2

I want to implement ldap paging with Spring-Ldap (2.3.2.RELEASE). My LDAP-Server has a size limit of 500. If I fetch all results in one query (without pagination) I get the 500 entries (and not more of cause). If I try to fetch all results with a page size of 100 I have an endless loop. Here's the method that does the paging:

private static final ContextMapper<String> ctxMapper = ctx -> ((DirContextAdapter) ctx).getNameInNamespace();

// ...

public Set<String> listGroups(int pageSize) {

    final SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    PagedResultsDirContextProcessor processor = new PagedResultsDirContextProcessor(pageSize);

    // In order for a paged results cookie to continue being valid, it is necessary that the same underlying
    // connection is used for each paged results call. This can be accomplished using the SingleContextSource.
    return SingleContextSource.doWithSingleContext(contextSource,
            (LdapOperations operations) -> {
                Set<String> results = new LinkedHashSet<>();
                do {
                    final List<String> foundGroupNames = operations.search(
                            "",
                            "(objectClass=groupOfUniqueNames)",
                            searchControls,
                            ctxMapper,
                            processor);
                    logger.info("Import found {} external groups.", foundGroupNames.size());
                    results.addAll(foundGroupNames);
                } while (processor.hasMore());

                logger.info("Import found {} external groups.", results.size());
                return results;
            });
}

processor.hasMore() returns always true but I don't understand why. The ContextSource is a org.springframework.ldap.core.support.LdapContextSource

The code works if I disable the size limit on the LDAP-Server so that the server returns all results. So I assume that there is something I missed but I don't know what.

Dirk Dittmar
  • 21
  • 1
  • 3

1 Answers1

0

I guess that your you have an endless loop becouse processor.hasMore()returns the first group op 1000 every time.

See also Paginate on LDAP server which does not support PagedResultsControl

FredvN
  • 504
  • 1
  • 3
  • 14
  • 1
    But then my code would never work (or am I wrong?). The code above works when I disable the sizelimit in the LDAP-Server. If I debug my code I see that I get all the results but after the code just loops forever an gets the last page over and over again. – Dirk Dittmar Nov 05 '19 at 12:07