private Set<LdapUserDto> getFilteredLdapUsers(String baseDn, Filter filter) {
    final Set<LdapUserDto> users = new HashSet<>();
    final LdapTemplate ldapTemplate = loadLdapTemplate();
    LdapServerProperties ldapServerProperties = getLdapProperties();
    PagedResultsDirContextProcessor processor = createPagingProcessor();
    SearchControls searchControls = new SearchControls();
    searchControls.setReturningObjFlag(true);
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    LdapUserContextMapper ldapUserContextMapper = new LdapUserContextMapper(ldapServerProperties);
    String encodedFilter = filter.encode();

    do {
      LOG.trace("LDAP User Query - Base DN: '{}' ; Filter: '{}'", baseDn, encodedFilter);
      List dtos = ldapServerProperties.isPaginationEnabled() ?
          ldapTemplate.search(LdapUtils.newLdapName(baseDn), encodedFilter, searchControls, ldapUserContextMapper, processor) :
          ldapTemplate.search(LdapUtils.newLdapName(baseDn), encodedFilter, searchControls, ldapUserContextMapper);
      for (Object dto : dtos) {
        if (dto != null) {
          users.add((LdapUserDto) dto);
        }
      }
    } while (ldapServerProperties.isPaginationEnabled()
        && (processor.getCookie() != null) && (processor.getCookie().getCookie() != null));
    return users;
  }
Retrieves users from external LDAP server.

@return set of info about LDAP users
ambari-server/src/main/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulator.java