@Test public void testGetLdapUserByMemberAttrNoPagination() throws Exception { Configuration configuration = createNiceMock(Configuration.class); Users users = createNiceMock(Users.class); LdapTemplate ldapTemplate = createNiceMock(LdapTemplate.class); LdapServerProperties ldapServerProperties = createNiceMock(LdapServerProperties.class); Capture<ContextMapper> contextMapperCapture = EasyMock.newCapture(); Capture<SearchControls> searchControlsCapture = EasyMock.newCapture(); PagedResultsDirContextProcessor processor = createNiceMock(PagedResultsDirContextProcessor.class); PagedResultsCookie cookie = createNiceMock(PagedResultsCookie.class); LdapUserDto dto = new LdapUserDto(); List<LdapUserDto> list = new LinkedList<LdapUserDto>(); list.add(dto); expect(configuration.getLdapServerProperties()).andReturn(ldapServerProperties).anyTimes(); expect(ldapServerProperties.isPaginationEnabled()).andReturn(false).anyTimes(); expect(ldapServerProperties.getUserObjectClass()).andReturn("objectClass").anyTimes(); expect(ldapServerProperties.getUsernameAttribute()).andReturn("uid").anyTimes(); expect(ldapServerProperties.getDnAttribute()).andReturn("dn").anyTimes(); expect(ldapServerProperties.getBaseDN()).andReturn("cn=testUser,ou=Ambari,dc=SME,dc=support,dc=com").anyTimes(); expect(ldapTemplate.search(eq(LdapUtils.newLdapName("cn=testUser,ou=Ambari,dc=SME,dc=support,dc=com") ), eq("(&(objectClass=objectClass)(uid=foo))"), anyObject(SearchControls.class), capture(contextMapperCapture))).andReturn(list); replay(ldapTemplate, ldapServerProperties, users, configuration, processor, cookie); AmbariLdapDataPopulatorTestInstance populator = new AmbariLdapDataPopulatorTestInstance(configuration, users); populator.setLdapTemplate(ldapTemplate); populator.setProcessor(processor); assertEquals(dto, populator.getLdapUserByMemberAttr("foo")); verify(ldapTemplate, ldapServerProperties, users, configuration, processor, cookie); }
protected LdapUserDto getLdapUserByMemberAttr(String memberAttributeValue) { Set<LdapUserDto> filteredLdapUsers; memberAttributeValue = getUniqueIdByMemberPattern(memberAttributeValue, ldapServerProperties.getSyncUserMemberReplacePattern()); Filter syncMemberFilter = createCustomMemberFilter(memberAttributeValue, ldapServerProperties.getSyncUserMemberFilter()); if (memberAttributeValue != null && syncMemberFilter != null) { LOG.trace("Use custom filter '{}' for getting member user with default baseDN ('{}')", syncMemberFilter.encode(), ldapServerProperties.getBaseDN()); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), syncMemberFilter); } else if (memberAttributeValue != null && isMemberAttributeBaseDn(memberAttributeValue)) { LOG.trace("Member can be used as baseDn: {}", memberAttributeValue); Filter filter = new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass()); filteredLdapUsers = getFilteredLdapUsers(memberAttributeValue, filter); } else { LOG.trace("Member cannot be used as baseDn: {}", memberAttributeValue); Filter filter = new AndFilter() .and(new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass())) .and(new EqualsFilter(ldapServerProperties.getUsernameAttribute(), memberAttributeValue)); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), filter); } return (filteredLdapUsers.isEmpty()) ? null : filteredLdapUsers.iterator().next(); }
AmbariLdapDataPopulator { protected LdapUserDto getLdapUserByMemberAttr(String memberAttributeValue) { Set<LdapUserDto> filteredLdapUsers; memberAttributeValue = getUniqueIdByMemberPattern(memberAttributeValue, ldapServerProperties.getSyncUserMemberReplacePattern()); Filter syncMemberFilter = createCustomMemberFilter(memberAttributeValue, ldapServerProperties.getSyncUserMemberFilter()); if (memberAttributeValue != null && syncMemberFilter != null) { LOG.trace("Use custom filter '{}' for getting member user with default baseDN ('{}')", syncMemberFilter.encode(), ldapServerProperties.getBaseDN()); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), syncMemberFilter); } else if (memberAttributeValue != null && isMemberAttributeBaseDn(memberAttributeValue)) { LOG.trace("Member can be used as baseDn: {}", memberAttributeValue); Filter filter = new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass()); filteredLdapUsers = getFilteredLdapUsers(memberAttributeValue, filter); } else { LOG.trace("Member cannot be used as baseDn: {}", memberAttributeValue); Filter filter = new AndFilter() .and(new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass())) .and(new EqualsFilter(ldapServerProperties.getUsernameAttribute(), memberAttributeValue)); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), filter); } return (filteredLdapUsers.isEmpty()) ? null : filteredLdapUsers.iterator().next(); } }
AmbariLdapDataPopulator { protected LdapUserDto getLdapUserByMemberAttr(String memberAttributeValue) { Set<LdapUserDto> filteredLdapUsers; memberAttributeValue = getUniqueIdByMemberPattern(memberAttributeValue, ldapServerProperties.getSyncUserMemberReplacePattern()); Filter syncMemberFilter = createCustomMemberFilter(memberAttributeValue, ldapServerProperties.getSyncUserMemberFilter()); if (memberAttributeValue != null && syncMemberFilter != null) { LOG.trace("Use custom filter '{}' for getting member user with default baseDN ('{}')", syncMemberFilter.encode(), ldapServerProperties.getBaseDN()); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), syncMemberFilter); } else if (memberAttributeValue != null && isMemberAttributeBaseDn(memberAttributeValue)) { LOG.trace("Member can be used as baseDn: {}", memberAttributeValue); Filter filter = new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass()); filteredLdapUsers = getFilteredLdapUsers(memberAttributeValue, filter); } else { LOG.trace("Member cannot be used as baseDn: {}", memberAttributeValue); Filter filter = new AndFilter() .and(new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass())) .and(new EqualsFilter(ldapServerProperties.getUsernameAttribute(), memberAttributeValue)); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), filter); } return (filteredLdapUsers.isEmpty()) ? null : filteredLdapUsers.iterator().next(); } @Inject  AmbariLdapDataPopulator(Configuration configuration, Users users); }
AmbariLdapDataPopulator { protected LdapUserDto getLdapUserByMemberAttr(String memberAttributeValue) { Set<LdapUserDto> filteredLdapUsers; memberAttributeValue = getUniqueIdByMemberPattern(memberAttributeValue, ldapServerProperties.getSyncUserMemberReplacePattern()); Filter syncMemberFilter = createCustomMemberFilter(memberAttributeValue, ldapServerProperties.getSyncUserMemberFilter()); if (memberAttributeValue != null && syncMemberFilter != null) { LOG.trace("Use custom filter '{}' for getting member user with default baseDN ('{}')", syncMemberFilter.encode(), ldapServerProperties.getBaseDN()); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), syncMemberFilter); } else if (memberAttributeValue != null && isMemberAttributeBaseDn(memberAttributeValue)) { LOG.trace("Member can be used as baseDn: {}", memberAttributeValue); Filter filter = new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass()); filteredLdapUsers = getFilteredLdapUsers(memberAttributeValue, filter); } else { LOG.trace("Member cannot be used as baseDn: {}", memberAttributeValue); Filter filter = new AndFilter() .and(new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass())) .and(new EqualsFilter(ldapServerProperties.getUsernameAttribute(), memberAttributeValue)); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), filter); } return (filteredLdapUsers.isEmpty()) ? null : filteredLdapUsers.iterator().next(); } @Inject  AmbariLdapDataPopulator(Configuration configuration, Users users); boolean isLdapEnabled(); LdapSyncDto getLdapSyncInfo(); LdapBatchDto synchronizeAllLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeAllLdapUsers(LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapGroups(Set<String> groups, LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapUsers(Set<String> users, LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo); }
AmbariLdapDataPopulator { protected LdapUserDto getLdapUserByMemberAttr(String memberAttributeValue) { Set<LdapUserDto> filteredLdapUsers; memberAttributeValue = getUniqueIdByMemberPattern(memberAttributeValue, ldapServerProperties.getSyncUserMemberReplacePattern()); Filter syncMemberFilter = createCustomMemberFilter(memberAttributeValue, ldapServerProperties.getSyncUserMemberFilter()); if (memberAttributeValue != null && syncMemberFilter != null) { LOG.trace("Use custom filter '{}' for getting member user with default baseDN ('{}')", syncMemberFilter.encode(), ldapServerProperties.getBaseDN()); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), syncMemberFilter); } else if (memberAttributeValue != null && isMemberAttributeBaseDn(memberAttributeValue)) { LOG.trace("Member can be used as baseDn: {}", memberAttributeValue); Filter filter = new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass()); filteredLdapUsers = getFilteredLdapUsers(memberAttributeValue, filter); } else { LOG.trace("Member cannot be used as baseDn: {}", memberAttributeValue); Filter filter = new AndFilter() .and(new EqualsFilter(OBJECT_CLASS_ATTRIBUTE, ldapServerProperties.getUserObjectClass())) .and(new EqualsFilter(ldapServerProperties.getUsernameAttribute(), memberAttributeValue)); filteredLdapUsers = getFilteredLdapUsers(ldapServerProperties.getBaseDN(), filter); } return (filteredLdapUsers.isEmpty()) ? null : filteredLdapUsers.iterator().next(); } @Inject  AmbariLdapDataPopulator(Configuration configuration, Users users); boolean isLdapEnabled(); LdapSyncDto getLdapSyncInfo(); LdapBatchDto synchronizeAllLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeAllLdapUsers(LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapGroups(Set<String> groups, LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapUsers(Set<String> users, LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo);  }