@Test public void roleConfigsWithoutGateway() { GeneralClusterConfigs gcc = new GeneralClusterConfigs(); gcc.setPassword("secret"); IdBroker idBroker = new IdBroker(); idBroker.setMasterSecret("supersecret"); TemplatePreparationObject source = Builder.builder() .withGeneralClusterConfigs(gcc) .withVirtualGroupView(new VirtualGroupRequest(TestConstants.CRN, "")) .withIdBroker(idBroker) .build(); Mockito.when(virtualGroupService.getVirtualGroup(source.getVirtualGroupRequest(), UmsRight.KNOX_ADMIN.getRight())).thenReturn(""); assertEquals( List.of( config("idbroker_master_secret", "supersecret"), config("idbroker_gateway_knox_admin_groups", ""), config("idbroker_gateway_signing_keystore_name", "signing.jks"), config("idbroker_gateway_signing_keystore_type", "JKS"), config("idbroker_gateway_signing_key_alias", "signing-identity") ), underTest.getRoleConfigs(KnoxRoles.IDBROKER, source) ); assertEquals( List.of( config("gateway_master_secret", gcc.getPassword()), config("gateway_default_topology_name", "cdp-proxy"), config("gateway_knox_admin_groups", ""), config("gateway_auto_discovery_enabled", "false") ), underTest.getRoleConfigs(KnoxRoles.KNOX_GATEWAY, source) ); assertEquals(List.of(), underTest.getRoleConfigs("NAMENODE", source)); }
@Override protected List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { GatewayView gateway = source.getGatewayView(); GeneralClusterConfigs generalClusterConfigs = source.getGeneralClusterConfigs(); String masterSecret = gateway != null ? gateway.getMasterSecret() : generalClusterConfigs.getPassword(); String topologyName = gateway != null && gateway.getExposedServices() != null ? gateway.getTopologyName() : DEFAULT_TOPOLOGY; VirtualGroupRequest virtualGroupRequest = source.getVirtualGroupRequest(); String adminGroup = virtualGroupService.getVirtualGroup(virtualGroupRequest, UmsRight.KNOX_ADMIN.getRight()); switch (roleType) { case KnoxRoles.KNOX_GATEWAY: List<ApiClusterTemplateConfig> config = new ArrayList<>(); config.add(config(KNOX_MASTER_SECRET, masterSecret)); config.add(config(GATEWAY_DEFAULT_TOPOLOGY_NAME, topologyName)); config.add(config(GATEWAY_ADMIN_GROUPS, adminGroup)); config.add(config(GATEWAY_CM_AUTO_DISCOVERY_ENABLED, "false")); if (gateway != null) { config.add(config(GATEWAY_PATH, gateway.getPath())); config.add(config(GATEWAY_SIGNING_KEYSTORE_NAME, SIGNING_JKS)); config.add(config(GATEWAY_SIGNING_KEYSTORE_TYPE, JKS)); config.add(config(GATEWAY_SIGNING_KEY_ALIAS, SIGNING_IDENTITY)); config.add(getGatewayWhitelistConfig(source)); } return config; case KnoxRoles.IDBROKER: return List.of( config(IDBROKER_MASTER_SECRET, source.getIdBroker().getMasterSecret()), config(IDBROKER_GATEWAY_ADMIN_GROUPS, adminGroup), config(IDBROKER_SIGNING_KEYSTORE_NAME, SIGNING_JKS), config(IDBROKER_SIGNING_KEYSTORE_TYPE, JKS), config(IDBROKER_SIGNING_KEY_ALIAS, SIGNING_IDENTITY) ); default: return List.of(); } }
KnoxGatewayConfigProvider extends AbstractRoleConfigProvider { @Override protected List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { GatewayView gateway = source.getGatewayView(); GeneralClusterConfigs generalClusterConfigs = source.getGeneralClusterConfigs(); String masterSecret = gateway != null ? gateway.getMasterSecret() : generalClusterConfigs.getPassword(); String topologyName = gateway != null && gateway.getExposedServices() != null ? gateway.getTopologyName() : DEFAULT_TOPOLOGY; VirtualGroupRequest virtualGroupRequest = source.getVirtualGroupRequest(); String adminGroup = virtualGroupService.getVirtualGroup(virtualGroupRequest, UmsRight.KNOX_ADMIN.getRight()); switch (roleType) { case KnoxRoles.KNOX_GATEWAY: List<ApiClusterTemplateConfig> config = new ArrayList<>(); config.add(config(KNOX_MASTER_SECRET, masterSecret)); config.add(config(GATEWAY_DEFAULT_TOPOLOGY_NAME, topologyName)); config.add(config(GATEWAY_ADMIN_GROUPS, adminGroup)); config.add(config(GATEWAY_CM_AUTO_DISCOVERY_ENABLED, "false")); if (gateway != null) { config.add(config(GATEWAY_PATH, gateway.getPath())); config.add(config(GATEWAY_SIGNING_KEYSTORE_NAME, SIGNING_JKS)); config.add(config(GATEWAY_SIGNING_KEYSTORE_TYPE, JKS)); config.add(config(GATEWAY_SIGNING_KEY_ALIAS, SIGNING_IDENTITY)); config.add(getGatewayWhitelistConfig(source)); } return config; case KnoxRoles.IDBROKER: return List.of( config(IDBROKER_MASTER_SECRET, source.getIdBroker().getMasterSecret()), config(IDBROKER_GATEWAY_ADMIN_GROUPS, adminGroup), config(IDBROKER_SIGNING_KEYSTORE_NAME, SIGNING_JKS), config(IDBROKER_SIGNING_KEYSTORE_TYPE, JKS), config(IDBROKER_SIGNING_KEY_ALIAS, SIGNING_IDENTITY) ); default: return List.of(); } } }
KnoxGatewayConfigProvider extends AbstractRoleConfigProvider { @Override protected List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { GatewayView gateway = source.getGatewayView(); GeneralClusterConfigs generalClusterConfigs = source.getGeneralClusterConfigs(); String masterSecret = gateway != null ? gateway.getMasterSecret() : generalClusterConfigs.getPassword(); String topologyName = gateway != null && gateway.getExposedServices() != null ? gateway.getTopologyName() : DEFAULT_TOPOLOGY; VirtualGroupRequest virtualGroupRequest = source.getVirtualGroupRequest(); String adminGroup = virtualGroupService.getVirtualGroup(virtualGroupRequest, UmsRight.KNOX_ADMIN.getRight()); switch (roleType) { case KnoxRoles.KNOX_GATEWAY: List<ApiClusterTemplateConfig> config = new ArrayList<>(); config.add(config(KNOX_MASTER_SECRET, masterSecret)); config.add(config(GATEWAY_DEFAULT_TOPOLOGY_NAME, topologyName)); config.add(config(GATEWAY_ADMIN_GROUPS, adminGroup)); config.add(config(GATEWAY_CM_AUTO_DISCOVERY_ENABLED, "false")); if (gateway != null) { config.add(config(GATEWAY_PATH, gateway.getPath())); config.add(config(GATEWAY_SIGNING_KEYSTORE_NAME, SIGNING_JKS)); config.add(config(GATEWAY_SIGNING_KEYSTORE_TYPE, JKS)); config.add(config(GATEWAY_SIGNING_KEY_ALIAS, SIGNING_IDENTITY)); config.add(getGatewayWhitelistConfig(source)); } return config; case KnoxRoles.IDBROKER: return List.of( config(IDBROKER_MASTER_SECRET, source.getIdBroker().getMasterSecret()), config(IDBROKER_GATEWAY_ADMIN_GROUPS, adminGroup), config(IDBROKER_SIGNING_KEYSTORE_NAME, SIGNING_JKS), config(IDBROKER_SIGNING_KEYSTORE_TYPE, JKS), config(IDBROKER_SIGNING_KEY_ALIAS, SIGNING_IDENTITY) ); default: return List.of(); } }  }
KnoxGatewayConfigProvider extends AbstractRoleConfigProvider { @Override protected List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { GatewayView gateway = source.getGatewayView(); GeneralClusterConfigs generalClusterConfigs = source.getGeneralClusterConfigs(); String masterSecret = gateway != null ? gateway.getMasterSecret() : generalClusterConfigs.getPassword(); String topologyName = gateway != null && gateway.getExposedServices() != null ? gateway.getTopologyName() : DEFAULT_TOPOLOGY; VirtualGroupRequest virtualGroupRequest = source.getVirtualGroupRequest(); String adminGroup = virtualGroupService.getVirtualGroup(virtualGroupRequest, UmsRight.KNOX_ADMIN.getRight()); switch (roleType) { case KnoxRoles.KNOX_GATEWAY: List<ApiClusterTemplateConfig> config = new ArrayList<>(); config.add(config(KNOX_MASTER_SECRET, masterSecret)); config.add(config(GATEWAY_DEFAULT_TOPOLOGY_NAME, topologyName)); config.add(config(GATEWAY_ADMIN_GROUPS, adminGroup)); config.add(config(GATEWAY_CM_AUTO_DISCOVERY_ENABLED, "false")); if (gateway != null) { config.add(config(GATEWAY_PATH, gateway.getPath())); config.add(config(GATEWAY_SIGNING_KEYSTORE_NAME, SIGNING_JKS)); config.add(config(GATEWAY_SIGNING_KEYSTORE_TYPE, JKS)); config.add(config(GATEWAY_SIGNING_KEY_ALIAS, SIGNING_IDENTITY)); config.add(getGatewayWhitelistConfig(source)); } return config; case KnoxRoles.IDBROKER: return List.of( config(IDBROKER_MASTER_SECRET, source.getIdBroker().getMasterSecret()), config(IDBROKER_GATEWAY_ADMIN_GROUPS, adminGroup), config(IDBROKER_SIGNING_KEYSTORE_NAME, SIGNING_JKS), config(IDBROKER_SIGNING_KEYSTORE_TYPE, JKS), config(IDBROKER_SIGNING_KEY_ALIAS, SIGNING_IDENTITY) ); default: return List.of(); } }  @Override Map<String, ApiClusterTemplateService> getAdditionalServices(CmTemplateProcessor cmTemplateProcessor, TemplatePreparationObject source); @Override String getServiceType(); @Override List<String> getRoleTypes(); }
KnoxGatewayConfigProvider extends AbstractRoleConfigProvider { @Override protected List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { GatewayView gateway = source.getGatewayView(); GeneralClusterConfigs generalClusterConfigs = source.getGeneralClusterConfigs(); String masterSecret = gateway != null ? gateway.getMasterSecret() : generalClusterConfigs.getPassword(); String topologyName = gateway != null && gateway.getExposedServices() != null ? gateway.getTopologyName() : DEFAULT_TOPOLOGY; VirtualGroupRequest virtualGroupRequest = source.getVirtualGroupRequest(); String adminGroup = virtualGroupService.getVirtualGroup(virtualGroupRequest, UmsRight.KNOX_ADMIN.getRight()); switch (roleType) { case KnoxRoles.KNOX_GATEWAY: List<ApiClusterTemplateConfig> config = new ArrayList<>(); config.add(config(KNOX_MASTER_SECRET, masterSecret)); config.add(config(GATEWAY_DEFAULT_TOPOLOGY_NAME, topologyName)); config.add(config(GATEWAY_ADMIN_GROUPS, adminGroup)); config.add(config(GATEWAY_CM_AUTO_DISCOVERY_ENABLED, "false")); if (gateway != null) { config.add(config(GATEWAY_PATH, gateway.getPath())); config.add(config(GATEWAY_SIGNING_KEYSTORE_NAME, SIGNING_JKS)); config.add(config(GATEWAY_SIGNING_KEYSTORE_TYPE, JKS)); config.add(config(GATEWAY_SIGNING_KEY_ALIAS, SIGNING_IDENTITY)); config.add(getGatewayWhitelistConfig(source)); } return config; case KnoxRoles.IDBROKER: return List.of( config(IDBROKER_MASTER_SECRET, source.getIdBroker().getMasterSecret()), config(IDBROKER_GATEWAY_ADMIN_GROUPS, adminGroup), config(IDBROKER_SIGNING_KEYSTORE_NAME, SIGNING_JKS), config(IDBROKER_SIGNING_KEYSTORE_TYPE, JKS), config(IDBROKER_SIGNING_KEY_ALIAS, SIGNING_IDENTITY) ); default: return List.of(); } }  @Override Map<String, ApiClusterTemplateService> getAdditionalServices(CmTemplateProcessor cmTemplateProcessor, TemplatePreparationObject source); @Override String getServiceType(); @Override List<String> getRoleTypes();  }