Java 具有服务器大小限制的LDAP分页
我想用SpringLDAP(2.3.2.RELEASE)实现ldap分页。我的LDAP服务器的大小限制为500。 如果我在一个查询中获取所有结果(不分页),我将获得500个条目(而不是更多的原因)。 如果我试图获取页面大小为100的所有结果,我会有一个无止境的循环。下面是执行分页的方法:Java 具有服务器大小限制的LDAP分页,java,spring,ldap,spring-ldap,Java,Spring,Ldap,Spring Ldap,我想用SpringLDAP(2.3.2.RELEASE)实现ldap分页。我的LDAP服务器的大小限制为500。 如果我在一个查询中获取所有结果(不分页),我将获得500个条目(而不是更多的原因)。 如果我试图获取页面大小为100的所有结果,我会有一个无止境的循环。下面是执行分页的方法: private static final ContextMapper<String> ctxMapper = ctx -> ((DirContextAdapter) ctx).getNameI
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;
});
}
private static final ContextMapper ctxMapper=ctx->((DirContextAdapter)ctx).getNameInNamespace();
// ...
公共集合列表组(int pageSize){
最终SearchControls SearchControls=新的SearchControls();
searchControls.setSearchScope(searchControls.SUBTREE_范围);
PagedResultsDirContextProcessor=新的PagedResultsDirContextProcessor(pageSize);
//为了使分页结果cookie继续有效,必须使用相同的基础cookie
//连接用于每个分页结果调用。这可以使用SingleContextSource完成。
返回SingleContextSource.doWithSingleContext(contextSource,
(LdapOperations操作)->{
设置结果=新建LinkedHashSet();
做{
最终列表FoundGroupName=operations.search(
"",
“(objectClass=groupOfUniqueNames)”,
搜索控制,
ctxMapper,
处理器);
info(“导入找到{}个外部组。”,foundGroupNames.size());
results.addAll(foundGroupNames);
}while(processor.hasMore());
info(“导入找到{}个外部组。”,results.size());
返回结果;
});
}
processor.hasMore()
总是返回true
,但我不明白为什么。ContextSource是一个org.springframework.ldap.core.support.LdapContextSource
如果我禁用LDAP服务器上的大小限制,以便服务器返回所有结果,则代码可以工作。因此,我假设我遗漏了一些东西,但我不知道是什么。我猜您的you有一个无休止的循环,因为
处理器。hasMore()
每次都返回第一组op 1000
另请参见我猜您的you有一个无止境的循环,因为处理器。hasMore()每次都返回第一组op 1000
另请参见,但是我的代码永远不会工作(或者我错了吗?)。当我在LDAP服务器中禁用sizelimit时,上面的代码可以工作。如果我调试我的代码,我会看到我得到了所有的结果,但是在代码永远循环之后,一次又一次地得到最后一页。但是我的代码永远不会工作(或者我错了吗?)。当我在LDAP服务器中禁用sizelimit时,上面的代码可以工作。如果我调试我的代码,我会看到我得到了所有的结果,但是在代码永远循环之后,一次又一次地得到最后一页。