use of com.sequenceiq.cloudbreak.dto.LdapView in project cloudbreak by hortonworks.
the class StackToTemplatePreparationObjectConverterTest method testConvertWhenClusterFromClusterServiceHasLdapConfigThenItShouldBeStored.
@Test
public void testConvertWhenClusterFromClusterServiceHasLdapConfigThenItShouldBeStored() {
LdapView ldapView = LdapView.LdapViewBuilder.aLdapView().withProtocol("").withBindDn("admin<>").build();
when(ldapConfigService.get(anyString(), anyString())).thenReturn(Optional.of(ldapView));
when(blueprintViewProvider.getBlueprintView(any())).thenReturn(getBlueprintView());
TemplatePreparationObject result = underTest.convert(stackMock);
assertThat(result.getLdapConfig().isPresent()).isTrue();
}
use of com.sequenceiq.cloudbreak.dto.LdapView in project cloudbreak by hortonworks.
the class ClouderaManagerLdapServiceTest method testSetupLdapWithFullAdminGroupMapping.
@Test
public void testSetupLdapWithFullAdminGroupMapping() throws ApiException, ClouderaManagerClientInitException {
// GIVEN
ReflectionTestUtils.setField(underTest, "adminRole", "ROLE_ADMIN");
ReflectionTestUtils.setField(underTest, "limitedAdminRole", "NO_ROLE_LIMITED_CLUSTER_ADMIN");
ReflectionTestUtils.setField(underTest, "userRole", "ROLE_USER");
ReflectionTestUtils.setField(underTest, "dashboardUserRole", "ROLE_DASHBOARD_USER");
LdapView ldapConfig = getLdapConfig();
VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(TestConstants.CRN, "");
ApiAuthRoleMetadataList apiAuthRoleMetadataList = new ApiAuthRoleMetadataList().addItemsItem(new ApiAuthRoleMetadata().displayName("ROLE_LIMITED_CLUSTER_ADMIN").uuid("uuid").role("ROLE_LIMITED_CLUSTER_ADMIN"));
apiAuthRoleMetadataList.addItemsItem(new ApiAuthRoleMetadata().displayName("ROLE_ADMIN").uuid("uuid").role("ROLE_ADMIN"));
apiAuthRoleMetadataList.addItemsItem(new ApiAuthRoleMetadata().displayName("ROLE_DASHBOARD_USER").uuid("uuid").role("ROLE_DASHBOARD_USER"));
when(authRolesResourceApi.readAuthRolesMetadata(null)).thenReturn(apiAuthRoleMetadataList);
when(virtualGroupService.createOrGetVirtualGroup(virtualGroupRequest, UmsVirtualGroupRight.CLOUDER_MANAGER_ADMIN)).thenReturn("virtualGroup");
// WHEN
underTest.setupLdap(stack, cluster, httpClientConfig, ldapConfig, virtualGroupRequest);
// THEN
ArgumentCaptor<ApiExternalUserMappingList> apiExternalUserMappingListArgumentCaptor = ArgumentCaptor.forClass(ApiExternalUserMappingList.class);
verify(externalUserMappingsResourceApi).createExternalUserMappings(apiExternalUserMappingListArgumentCaptor.capture());
ApiExternalUserMapping apiExternalUserMapping = apiExternalUserMappingListArgumentCaptor.getValue().getItems().get(0);
ApiAuthRoleRef authRole = apiExternalUserMapping.getAuthRoles().get(0);
assertEquals("ROLE_ADMIN", authRole.getDisplayName());
assertEquals("uuid", authRole.getUuid());
assertEquals("virtualGroup", apiExternalUserMapping.getName());
}
use of com.sequenceiq.cloudbreak.dto.LdapView in project cloudbreak by hortonworks.
the class ClouderaManagerLdapServiceTest method testSetupLdapWithLimitedAdminGroupMapping.
@Test
public void testSetupLdapWithLimitedAdminGroupMapping() throws ApiException, ClouderaManagerClientInitException {
// GIVEN
ReflectionTestUtils.setField(underTest, "adminRole", "ROLE_ADMIN");
ReflectionTestUtils.setField(underTest, "limitedAdminRole", "ROLE_LIMITED_CLUSTER_ADMIN");
ReflectionTestUtils.setField(underTest, "userRole", "ROLE_USER");
ReflectionTestUtils.setField(underTest, "dashboardUserRole", "ROLE_DASHBOARD_USER");
LdapView ldapConfig = getLdapConfig();
VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(TestConstants.CRN, "");
ApiAuthRoleMetadataList apiAuthRoleMetadataList = new ApiAuthRoleMetadataList().addItemsItem(new ApiAuthRoleMetadata().displayName("ROLE_LIMITED_CLUSTER_ADMIN").uuid("uuid").role("ROLE_LIMITED_CLUSTER_ADMIN"));
apiAuthRoleMetadataList.addItemsItem(new ApiAuthRoleMetadata().displayName("ROLE_ADMIN").uuid("uuid").role("ROLE_ADMIN"));
when(authRolesResourceApi.readAuthRolesMetadata(null)).thenReturn(apiAuthRoleMetadataList);
when(virtualGroupService.createOrGetVirtualGroup(virtualGroupRequest, UmsVirtualGroupRight.CLOUDER_MANAGER_ADMIN)).thenReturn("virtualGroup");
// WHEN
underTest.setupLdap(stack, cluster, httpClientConfig, ldapConfig, virtualGroupRequest);
// THEN
ArgumentCaptor<ApiExternalUserMappingList> apiExternalUserMappingListArgumentCaptor = ArgumentCaptor.forClass(ApiExternalUserMappingList.class);
verify(externalUserMappingsResourceApi).createExternalUserMappings(apiExternalUserMappingListArgumentCaptor.capture());
ApiExternalUserMapping apiExternalUserMapping = apiExternalUserMappingListArgumentCaptor.getValue().getItems().get(0);
ApiAuthRoleRef authRole = apiExternalUserMapping.getAuthRoles().get(0);
assertEquals("ROLE_LIMITED_CLUSTER_ADMIN", authRole.getDisplayName());
assertEquals("uuid", authRole.getUuid());
assertEquals("virtualGroup", apiExternalUserMapping.getName());
}
use of com.sequenceiq.cloudbreak.dto.LdapView in project cloudbreak by hortonworks.
the class StackV4RequestToTemplatePreparationObjectConverter method convert.
public TemplatePreparationObject convert(StackV4Request source) {
try {
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
User user = userService.getOrCreate(cloudbreakUser);
Workspace workspace = workspaceService.get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
DetailedEnvironmentResponse environment = environmentClientService.getByCrn(source.getEnvironmentCrn());
Credential credential = getCredential(source, environment);
LdapView ldapConfig = getLdapConfig(source, environment);
BaseFileSystemConfigurationsView fileSystemConfigurationView = getFileSystemConfigurationView(source, credential.getAttributes());
Set<RDSConfig> rdsConfigs = getRdsConfigs(source, workspace);
Blueprint blueprint = getBlueprint(source, workspace);
Set<HostgroupView> hostgroupViews = getHostgroupViews(source);
Gateway gateway = source.getCluster().getGateway() == null ? null : stackV4RequestToGatewayConverter.convert(source);
BlueprintView blueprintView = blueprintViewProvider.getBlueprintView(blueprint);
Optional<String> version = Optional.ofNullable(blueprintView.getVersion());
GeneralClusterConfigs generalClusterConfigs = generalClusterConfigsProvider.generalClusterConfigs(source, cloudbreakUser.getEmail(), blueprintService.getBlueprintVariant(blueprint));
String gatewaySignKey = null;
if (gateway != null) {
gatewaySignKey = gateway.getSignKey();
}
String envCrnForVirtualGroups = getEnvironmentCrnForVirtualGroups(environment);
VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(envCrnForVirtualGroups, ldapConfig != null ? ldapConfig.getAdminGroup() : "");
Builder builder = Builder.builder().withCloudPlatform(source.getCloudPlatform()).withRdsConfigs(rdsConfigs).withHostgroupViews(hostgroupViews).withGateway(gateway, gatewaySignKey, exposedServiceCollector.getAllKnoxExposed(version)).withBlueprintView(blueprintView).withFileSystemConfigurationView(fileSystemConfigurationView).withGeneralClusterConfigs(generalClusterConfigs).withLdapConfig(ldapConfig).withCustomInputs(source.getInputs()).withKerberosConfig(getKerberosConfig(source, environment)).withStackType(source.getType()).withVirtualGroupView(virtualGroupRequest);
decorateBuilderWithPlacement(source, builder);
decorateBuilderWithAccountMapping(source, environment, credential, builder);
decorateBuilderWithProductDetails(source, builder);
decorateDatalakeView(source, builder);
return builder.build();
} catch (BlueprintProcessingException | IOException e) {
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.dto.LdapView in project cloudbreak by hortonworks.
the class KnoxGatewayConfigProviderTest method roleConfigsWithGatewayWithLdapConfigWhenOdbcEntitlementFalse.
@Test
public void roleConfigsWithGatewayWithLdapConfigWhenOdbcEntitlementFalse() {
Gateway gateway = new Gateway();
gateway.setKnoxMasterSecret("admin");
gateway.setPath("/a/b/c");
IdBroker idBroker = new IdBroker();
idBroker.setMasterSecret("supersecret");
BlueprintTextProcessor blueprintTextProcessor = mock(BlueprintTextProcessor.class);
LdapView ldapConfig = LdapViewBuilder.aLdapView().build();
BlueprintView blueprintView = new BlueprintView("text", "7.2.11", "CDH", blueprintTextProcessor);
GeneralClusterConfigs generalClusterConfigs = new GeneralClusterConfigs();
generalClusterConfigs.setAccountId(Optional.of("1234"));
TemplatePreparationObject source = Builder.builder().withGateway(gateway, "key", new HashSet<>()).withLdapConfig(ldapConfig).withGeneralClusterConfigs(generalClusterConfigs).withBlueprintView(blueprintView).withVirtualGroupView(new VirtualGroupRequest(TestConstants.CRN, "")).withProductDetails(new ClouderaManagerRepo().withVersion("7.4.2"), List.of(new ClouderaManagerProduct().withVersion("7.2.10").withName("CDH"))).withIdBroker(idBroker).build();
when(virtualGroupService.createOrGetVirtualGroup(source.getVirtualGroupRequest(), UmsVirtualGroupRight.KNOX_ADMIN)).thenReturn("knox_admins");
when(entitlementService.isOjdbcTokenDhOneHour(anyString())).thenReturn(false);
assertEquals(List.of(config("idbroker_master_secret", "supersecret"), config("idbroker_gateway_knox_admin_groups", "knox_admins"), 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", gateway.getKnoxMasterSecret()), config("gateway_default_topology_name", "cdp-proxy"), config("gateway_knox_admin_groups", "knox_admins"), config("gateway_auto_discovery_enabled", "false"), config("gateway_path", gateway.getPath()), config("gateway_signing_keystore_name", "signing.jks"), config("gateway_signing_keystore_type", "JKS"), config("gateway_signing_key_alias", "signing-identity"), config("gateway_dispatch_whitelist", "^*.*$"), config("gateway_token_generation_enable_lifespan_input", "true"), config("gateway_token_generation_knox_token_ttl", "86400000"), config("gateway_service_tokenstate_impl", "org.apache.knox.gateway.services.token.impl.JDBCTokenStateService")), ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.getRoleConfigs(KnoxRoles.KNOX_GATEWAY, source)));
assertEquals(List.of(), underTest.getRoleConfigs("NAMENODE", source));
}
Aggregations