【问题标题】:LDAP pagination with Server sizelimit使用服务器 sizelimit 的 LDAP 分页
【发布时间】:2019-11-05 10:55:09
【问题描述】:

我想用 Spring-Ldap (2.3.2.RELEASE) 实现 ldap 分页。我的 LDAP 服务器的大小限制为 500。 如果我在一个查询中获取所有结果(没有分页),我会得到 500 个条目(而不是更多的原因)。 如果我尝试获取页面大小为 100 的所有结果,则会出现无限循环。这是执行分页的方法:

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() 总是返回 true 但我不明白为什么。 ContextSource 是org.springframework.ldap.core.support.LdapContextSource

如果我禁用 LDAP 服务器上的大小限制以便服务器返回所有结果,则该代码有效。所以我假设我错过了一些东西,但我不知道是什么。

【问题讨论】:

    标签: java spring ldap spring-ldap


    【解决方案1】:

    我猜你有一个无限循环,因为processor.hasMore()每次都会返回第一组操作 1000。

    另见Paginate on LDAP server which does not support PagedResultsControl

    【讨论】:

    • 但是我的代码永远不会工作(或者我错了吗?)。当我在 LDAP 服务器中禁用 sizelimit 时,上面的代码有效。如果我调试我的代码,我会看到我得到了所有结果,但是在代码永远循环之后,一遍又一遍地获取最后一页。
    猜你喜欢
    • 1970-01-01
    • 2018-11-12
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多