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.