use of com.sequenceiq.freeipa.ldap.LdapConfig in project cloudbreak by hortonworks.
the class LdapConfigRegisterServiceTest method testRegister.
@Test
void testRegister() {
Stack stack = new Stack();
stack.setEnvironmentCrn("env");
stack.setAccountId("acc");
stack.setName("name");
stack.setAppVersion("2.20.0");
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setInstanceGroupType(InstanceGroupType.MASTER);
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setDiscoveryFQDN("fqdn");
instanceMetaData.setPrivateIp("1.1.1.1");
instanceGroup.setInstanceMetaData(Collections.singleton(instanceMetaData));
stack.setInstanceGroups(Collections.singleton(instanceGroup));
when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain("testdomain.local");
freeIpa.setAdminPassword("asdf");
when(freeIpaService.findByStackId(anyLong())).thenReturn(freeIpa);
when(balancedDnsAvailabilityChecker.isBalancedDnsAvailable(stack)).thenReturn(true);
underTest.register(1L);
ArgumentCaptor<LdapConfig> ldapConfigArgumentCaptor = ArgumentCaptor.forClass(LdapConfig.class);
ArgumentCaptor<String> accountIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
verify(ldapConfigService).createLdapConfig(ldapConfigArgumentCaptor.capture(), accountIdArgumentCaptor.capture());
assertEquals(stack.getAccountId(), accountIdArgumentCaptor.getValue());
LdapConfig ldapConfig = ldapConfigArgumentCaptor.getValue();
assertEquals(ldapConfig.getName(), stack.getName());
assertEquals(ldapConfig.getEnvironmentCrn(), stack.getEnvironmentCrn());
String domainComponent = ",dc=testdomain,dc=local";
assertEquals(ldapConfig.getBindDn(), BIND_DN + domainComponent);
assertEquals(ldapConfig.getUserSearchBase(), USER_SEARCH_BASE + domainComponent);
assertEquals(ldapConfig.getGroupSearchBase(), GROUP_SEARCH_BASE + domainComponent);
assertEquals(ldapConfig.getUserDnPattern(), USER_DN_PATTERN + domainComponent);
assertEquals(ldapConfig.getServerHost(), "ldap.testdomain.local");
assertEquals(ldapConfig.getProtocol(), PROTOCOL);
assertEquals(ldapConfig.getServerPort(), SERVER_PORT);
assertEquals(ldapConfig.getDomain(), freeIpa.getDomain());
assertEquals(ldapConfig.getBindPassword(), freeIpa.getAdminPassword());
assertEquals(ldapConfig.getDirectoryType(), DirectoryType.LDAP);
assertEquals(ldapConfig.getUserNameAttribute(), USER_NAME_ATTRIBUTE);
assertEquals(ldapConfig.getUserObjectClass(), USER_OBJECT_CLASS);
assertEquals(ldapConfig.getGroupMemberAttribute(), GROUP_MEMBER_ATTRIBUTE);
assertEquals(ldapConfig.getGroupNameAttribute(), GROUP_NAME_ATTRIBUTE);
assertEquals(ldapConfig.getGroupObjectClass(), GROUP_OBJECT_CLASS);
}
use of com.sequenceiq.freeipa.ldap.LdapConfig in project cloudbreak by hortonworks.
the class LdapBindUserCreationHandlerTest method testEventSentIfConfigAlreadyExists.
@Test
public void testEventSentIfConfigAlreadyExists() {
CreateBindUserEvent createBindUserEvent = new CreateBindUserEvent("selector", 1L, "acc", "opid", "suffix", "envcrn");
CreateLdapBindUserEvent createLdapBindUserEvent = new CreateLdapBindUserEvent(createBindUserEvent);
HandlerEvent<CreateLdapBindUserEvent> handlerEvent = new HandlerEvent<>(new Event<>(createLdapBindUserEvent));
when(ldapConfigService.find(createBindUserEvent.getEnvironmentCrn(), createBindUserEvent.getAccountId(), createBindUserEvent.getSuffix())).thenReturn(Optional.of(new LdapConfig()));
Selectable selectable = underTest.doAccept(handlerEvent);
assertTrue(selectable instanceof CreateBindUserEvent);
CreateBindUserEvent event = (CreateBindUserEvent) selectable;
assertEquals(CreateBindUserFlowEvent.CREATE_LDAP_BIND_USER_FINISHED_EVENT.event(), event.selector());
assertEquals(createBindUserEvent.getOperationId(), event.getOperationId());
assertEquals(createBindUserEvent.getSuffix(), event.getSuffix());
assertEquals(createBindUserEvent.getAccountId(), event.getAccountId());
assertEquals(createBindUserEvent.getResourceId(), event.getResourceId());
verifyNoInteractions(stackService);
verifyNoInteractions(ldapConfigV1Service);
}
use of com.sequenceiq.freeipa.ldap.LdapConfig in project cloudbreak by hortonworks.
the class LdapConfigRegisterService method createLdapConfig.
public LdapConfig createLdapConfig(Long stackId, String bindDn, String bindPassword, String clusterName, String environmentCrn) {
Stack stack = getStackWithInstanceMetadata(stackId);
if (StringUtils.isEmpty(environmentCrn)) {
environmentCrn = stack.getEnvironmentCrn();
}
FreeIpa freeIpa = getFreeIpaService().findByStackId(stackId);
String adminGroupName = StringUtils.isNotEmpty(freeIpa.getAdminGroupName()) ? freeIpa.getAdminGroupName() : "";
LdapConfig ldapConfig = new LdapConfig();
ldapConfig.setName(stack.getName());
ldapConfig.setEnvironmentCrn(environmentCrn);
ldapConfig.setAdminGroup(adminGroupName);
ldapConfig.setUserGroup(USER_GROUP);
String domainComponent = generateDomainComponent(freeIpa);
ldapConfig.setBindDn(StringUtils.isBlank(bindDn) ? BIND_DN + domainComponent : bindDn);
ldapConfig.setUserSearchBase(USER_SEARCH_BASE + domainComponent);
ldapConfig.setGroupSearchBase(GROUP_SEARCH_BASE + domainComponent);
ldapConfig.setUserDnPattern(USER_DN_PATTERN + domainComponent);
addServerHost(stack, freeIpa, ldapConfig);
ldapConfig.setProtocol(PROTOCOL);
ldapConfig.setServerPort(SERVER_PORT);
ldapConfig.setDomain(freeIpa.getDomain());
ldapConfig.setBindPassword(StringUtils.isBlank(bindPassword) ? freeIpa.getAdminPassword() : bindPassword);
ldapConfig.setDirectoryType(DirectoryType.LDAP);
ldapConfig.setUserNameAttribute(USER_NAME_ATTRIBUTE);
ldapConfig.setUserObjectClass(USER_OBJECT_CLASS);
ldapConfig.setGroupMemberAttribute(GROUP_MEMBER_ATTRIBUTE);
ldapConfig.setGroupNameAttribute(GROUP_NAME_ATTRIBUTE);
ldapConfig.setGroupObjectClass(GROUP_OBJECT_CLASS);
ldapConfig.setClusterName(clusterName);
return ldapConfigService.createLdapConfig(ldapConfig, stack.getAccountId());
}
use of com.sequenceiq.freeipa.ldap.LdapConfig in project cloudbreak by hortonworks.
the class LdapConfigV1Service method convertCreateLdapConfigRequest.
private LdapConfig convertCreateLdapConfigRequest(CreateLdapConfigRequest createLdapConfigRequest) {
LdapConfig config = new LdapConfig();
if (Strings.isNullOrEmpty(createLdapConfigRequest.getName())) {
config.setName(missingResourceNameGenerator.generateName(APIResourceType.LDAP_CONFIG));
} else {
config.setName(createLdapConfigRequest.getName());
}
config.setDescription(createLdapConfigRequest.getDescription());
config.setEnvironmentCrn(createLdapConfigRequest.getEnvironmentCrn());
config.setBindDn(createLdapConfigRequest.getBindDn());
config.setBindPassword(createLdapConfigRequest.getBindPassword());
config.setServerHost(createLdapConfigRequest.getHost());
config.setServerPort(createLdapConfigRequest.getPort());
config.setProtocol(createLdapConfigRequest.getProtocol());
config.setGroupSearchBase(createLdapConfigRequest.getGroupSearchBase());
config.setUserSearchBase(createLdapConfigRequest.getUserSearchBase());
config.setUserDnPattern(createLdapConfigRequest.getUserDnPattern());
config.setUserNameAttribute(createLdapConfigRequest.getUserNameAttribute());
config.setDomain(createLdapConfigRequest.getDomain());
config.setDirectoryType(createLdapConfigRequest.getDirectoryType() != null ? createLdapConfigRequest.getDirectoryType() : DirectoryType.LDAP);
config.setUserObjectClass(createLdapConfigRequest.getUserObjectClass() != null ? createLdapConfigRequest.getUserObjectClass() : "person");
config.setGroupObjectClass(createLdapConfigRequest.getGroupObjectClass() != null ? createLdapConfigRequest.getGroupObjectClass() : "groupOfNames");
config.setGroupNameAttribute(createLdapConfigRequest.getGroupNameAttribute() != null ? createLdapConfigRequest.getGroupNameAttribute() : "cn");
config.setGroupMemberAttribute(createLdapConfigRequest.getGroupMemberAttribute() != null ? createLdapConfigRequest.getGroupMemberAttribute() : "member");
config.setAdminGroup(createLdapConfigRequest.getAdminGroup());
config.setCertificate(createLdapConfigRequest.getCertificate());
return config;
}
use of com.sequenceiq.freeipa.ldap.LdapConfig in project cloudbreak by hortonworks.
the class LdapConfigV1Service method getLdapConfigIfFreeIPAExists.
private DescribeLdapConfigResponse getLdapConfigIfFreeIPAExists(String environmentCrn, String accountId, String clusterName, Stack stack) throws FreeIpaClientException {
MDCBuilder.buildMdcContext(stack);
LOGGER.debug("FreeIPA exists for environment");
Optional<LdapConfig> existingLdapConfig = ldapConfigService.find(environmentCrn, accountId, clusterName);
LdapConfig ldapConfig;
if (existingLdapConfig.isPresent()) {
LOGGER.debug("LdapConfig already exists");
ldapConfig = existingLdapConfig.get();
} else {
ldapConfig = createNewLdapConfig(environmentCrn, clusterName, stack, false);
}
return convertLdapConfigToDescribeLdapConfigResponse(ldapConfig);
}
Aggregations