2

I am using the next code to get all the users in the AD

Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://grupoasisa.local:636");
    env.put(Context.SECURITY_PROTOCOL, "ssl");
    env.put(Context.SECURITY_PRINCIPAL, "DOMASISA\\"+USER_SERVICE);
    env.put(Context.SECURITY_CREDENTIALS, PASSWORD_SERVICE);

    try {
        DirContext ctx = new InitialLdapContext(env, null);

        SearchControls searchCtls = new SearchControls();

        String returnedAtts[]={"sAMAccountName", "description", "mail"};

        searchCtls.setReturningAttributes(returnedAtts);

        //Specify the search scope
        searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        searchCtls.setTimeLimit(0);
        searchCtls.setCountLimit(0);

        //Specify the LDAP search filter
        String searchFilter="(&(objectCategory=person)(objectClass=user))";
        //Specify the Base for the search
        String searchBase = "DC=grupoasisa,DC=local";

        // Search for objects using the filter
        NamingEnumeration<SearchResult> answer = ctx.search(searchBase, searchFilter, searchCtls);

        //Loop through the search results
        while (answer.hasMoreElements()) {
            SearchResult searchResult = answer.next();
            Attributes attrs = searchResult.getAttributes();
            Attribute usuWin = attrs.get("sAMAccountName");
            Attribute racf = attrs.get("description");
            Attribute email = attrs.get("mail");    
        }
} catch (NamingException e) {
        System.err.println("Error: "+e.getMessage());
    } catch (Exception e) {
        System.err.println("Error: "+e.getMessage());
    }

And I am receiving only the 1000 first records although I was specifying that the search was unlimited. What is happening?

Thanks in advance.

Clara MG
  • 123
  • 1
  • 1
  • 8

1 Answers1

1

Not possible, you have to paginate (PaginationControl) through the results. Try this answer.

Community
  • 1
  • 1
Michael-O
  • 18,123
  • 6
  • 55
  • 121
  • Well, it does not work for me. I think I have to ask for changing the property MaxPageSize to a greater number. Thank you very much. – Clara MG Jun 01 '15 at 15:10
  • @ClaraMG, what is the exact exception you receive? – Michael-O Jun 01 '15 at 19:23
  • I am not receiving any exception but I only get the first 1000 records and I have to create an object with all records (that are over 1350). – Clara MG Jun 02 '15 at 14:43