ldapunboundid-ldap-sdk

Get all user's names from ldap servers


I'm a college student and i am doing an aplication in springboot to authenticate a user with ldap. I was able to do that with ldap.unboundid but now i want to display the name of all users on the ldap servers, is that possible and if so, could you give some examples?

Here his my code that authenticates the user in ldap:

public class LDAPAuthentication implements Authentication {

LdapConfigurations ldapConfig;

LDAPConnection ldapConnection;

SearchResult searchResult;

public LDAPAuthentication(LdapConfigurations ldapConfig) {
    this.ldapConfig = ldapConfig;
}

@Override
public UserEntity authenticate(String username, String password) {

    try {
        LDAPURL ldapUrl = new LDAPURL(ldapConfig.getUrl());
        LDAPConnectionOptions ldapConnectionOptions = new LDAPConnectionOptions();

        ldapConnectionOptions.setConnectTimeoutMillis(50);
        ldapConnection = new LDAPConnection(ldapConnectionOptions, ldapUrl.getHost(), ldapUrl.getPort(),
                username + ldapConfig.getLdapDomain(), password);

        ldapConnection.bind(username + ldapConfig.getLdapDomain(), password);

        String lookup = String.format("(%s=%s)", "sAMAccountName", username);
        SearchRequest searchRequest = new SearchRequest(ldapConfig.getBaseDn(), SearchScope.SUB, lookup);

        searchResult = ldapConnection.search(searchRequest);

        ldapConnection.close();

    } catch (LDAPException e) {
        e.printStackTrace();

        return null;

    }

Solution

  • If you're querying AD, you'll need to make changes to AD, or, you'll need paged results. search for "The Simple Paged Results Control" at https://docs.ldap.com/ldap-sdk/docs/getting-started/controls.html