JNDI-LDAP 分页

2023-12-20

我设法让分页像描述的那样工作here http://docs.oracle.com/javase/tutorial/jndi/newstuff/paged-results.html。问题是我需要公开一个如下所示的 API:getUsers(pageSize, pageNumber),这与 JNDI/LDAP 进行分页的方式并不太相配(每次都将 cookie 传递给搜索方法)。代码如下所示:

private NamingEnumeration ldapPagedSearch(String filter, int pageSize, int pageNumber){
    InitialLdapContext ctx = getInitialContext();

    //TODO: get the id also, need to spec it in UI
    // Create the search controls
    SearchControls searchCtls = new SearchControls();
    searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    //keep a session
    byte[] cookie = null;

    //Request the paged results control
    Control[] ctls = new Control[]{new PagedResultsControl(pageSize, true)};
    ctx.setRequestControls(ctls);

    //Specify the search scope
    NamingEnumeration results = null;
    int currentPage = 1;
    do {
        results = ctx.search(getConfiguration().get(BASEDN_KEY), filter, searchCtls);

        //we got to the right page, return this page
        if(currentPage == pageNumber) {
            return results;
        }

        // loop through this page, because we cannot get a proper cookie otherwise
        // WARN: this could be a problem of performance
        while (results.hasMore()) results.next();

        // examine the paged results control response
        Control[] controls = ctx.getResponseControls();
        if (controls != null) {
            for (Control control : controls) {
                if (control instanceof PagedResultsResponseControl) {
                    cookie = ((PagedResultsResponseControl) control).getCookie();
                } 
            }
        }

        // pass the cookie back to the server for the next page
        ctx.setRequestControls(new Control[]{new PagedResultsControl(pageSize, cookie, Control.CRITICAL) });

        //increment page
        currentPage++;
    } while (cookie != null);


    ctx.close();

    //if we get here, means it is an empty set(consumed by the inner loop)
    return results;
}

看来我需要遍历所有页面才能获得所需的页面。此外,我需要遍历页面上的所有条目,以便能够获取下一页。

有没有更好的办法?我担心性能问题。


有一种叫做“虚拟列表视图”的控件。它由几个 LDAP 服务器支持。不确定该实现是否仍在 JNDI 中。如果没有,您可以考虑自己实现。您必须将它与服务器端排序一起使用。

也可以看看https://datatracker.ietf.org/doc/html/draft-ietf-ldapext-ldapv3-vlv-04 https://datatracker.ietf.org/doc/html/draft-ietf-ldapext-ldapv3-vlv-04 and http://www.cs.rit.edu/usr/local/pub/jeh/rit/java/lib/doc/ldapcontrols/com/sun/jndi/ldap/ctl/VirtualListViewControl.html http://www.cs.rit.edu/usr/local/pub/jeh/rit/java/lib/doc/ldapcontrols/com/sun/jndi/ldap/ctl/VirtualListViewControl.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JNDI-LDAP 分页 的相关文章

  • 如何检索LDAP数据库的所有属性

    我在用LDAP模块 of python连接到LDAP服务器 我可以查询数据库 但我不知道如何查询检索数据库中存在的字段 这样我就可以提前通知用户查询数据库 告诉他他试图访问的字段不在数据库中 例如 如果存在的字段只是 cn memberOf
  • Offset Fetch Next 获取所有行

    我在 SQL Server 2012 中有一个查询 它应该根据我指定的页面大小及其所在的页面返回许多记录 它看起来像这样 SELECT LocID LocName FROM Locations ORDER BY LocName OFFSET
  • 配置 JBoss 使用 JNDI 的问题(2)

    继续上周的问题 配置 JBoss 使用 JNDI 时出现问题 https stackoverflow com questions 2828237 problem configure jboss to work with jndi 我正在尝试
  • 在一次搜索中搜索 LDAP 上的用户和关联组

    LDAP 新手 我们的 LDAP 的排列方式是 人员 和 组 人们拥有姓名 uid 和邮件等用户信息 这些组具有组名称和多个成员字段 其值如 cn First Last cn people dc comic dc com 列出了该组成员的人
  • Java 中的搜索结果

    我使用以下代码列出 LDAP 中的用户 Hashtable
  • php ldap-bind 密码过期

    我正在使用 adldap 插件连接到 Windows Server AD 但据我所知 我的问题是 php ldap bind 当用户输入不正确的密码时 ldap error 由 adldap 使用 返回的错误是 Invalid Creden
  • 上下文是只读的

    Helo大师 我必须动态创建一个JNDI数据源 我尝试使用名为SetupApplicationListener的侦听器来完成它 这是开始WEB LIB web xml
  • 如何从 LDAP 目录中提取 TNSNames

    我一直在尝试查询 LDAP 目录服务器以检索 tnsnames 条目 我可以使用以下代码 但味道不对 是因为它是错误的 还是因为查询 ldap 涉及几个间接级别 let identifier LdapDirectoryIdentifier
  • EJB3 Glassfish JNDI 查找

    我正在使用 Glassfish 捆绑的 Eclipse IDE 我编写了一个简单的 EJB 应用程序 但它不起作用 Stateless Remote CalculatorRemote class Local CalculatorLocal
  • UICollectionView ClipsToBounds 无法与分页正常工作

    我正在使用启用水平分页的 UICollectionView 我的 collectionView 框架小于屏幕尺寸 我使用了以下代码 myCollectionView clipsToBounds FALSE 我仍然无法看到 Collectio
  • 独立应用程序中的 JNDI 对象创建

    可以创建 JNDI llookup 并在独立应用程序中引用它 无需任何应用程序服务器 java comp env jdbc Regards Chaitu JNDI是Java平台提供的一项服务 参考下面的链接 http www javawor
  • 如何在非交互模式下配置 pam-auth-update?

    I wanted to enable PAM module packages in non interactive mode Running pam auth update will prompt a wizard to enable th
  • python - Flask_simpleldap 不会绑定

    我在用着烧瓶 simpledap https github com admiralobvious flask simpleldap并且正在努力获得绑定连接来执行任何有用的操作 我的 LDAP 服务器是活动目录 精简后的代码如下所示 几乎与这
  • 无法验证 SSL 证书

    我想做的事 与以下人员保持干净的联系openssl connect到远程站点 网站似乎是自签名的 What I m getting CONNECTED 00000003 depth 0 CN DC01 home pri verify err
  • 分页助手 asp.net mvc

    我已经实现了一个分页 html 帮助器 改编自史蒂文 桑德森的书 这是当前的代码 公共静态字符串PageLinks 此HtmlHelper html int currentPage int TotalPages Func pageUrl S
  • 如何使用 unboundid-ldap-sdp 导入 ldif 文件?

    我从 LDAP 服务器导出了以下 ldif 文件 现在尝试导入它 以便可以复制从中导出它的目录 dn cn MYCOMPANY Users dc mycompany dc com changetype add objectClass pos
  • 为什么x86分页没有特权环的概念?

    早在 1982 年 当 Intel 发布 80286 时 他们在分段方案中添加了 4 个特权级别 环 0 3 由全局描述符表 GDT 和局部描述符表 LDT 中的 2 位指定 在 80386 处理器中 Intel 添加了分页功能 但令人惊讶
  • Adobe AIR 应用程序能否实现针对 Active Directory 的 SSO 身份验证?

    我对 AIR 应用程序了解不多 但我喜欢目前所看到的内容 所以现在 我想知道这种类型的应用程序在工作中的内联网中是否有意义 在投入时间和精力加强 AIR 开发之前 我想知道 Windows 上的 AIR 应用程序是否可以针对 Active
  • 克服 Active Directory 1000 条记录的限制

    PowerShell 能够提取 1492 条记录的列表 当我使用带有 ldap3 模块的 Python 时 我遇到了 1000 条记录的限制 请帮我更改Python代码以超出限制 PowerShell 输入 get aduser filte
  • maven tomcat7:运行配置数据源

    我有一个多模块 Maven 项目 我想将它与tomcat7 maven插件并开始 mvn tomcat7 run 但我不知道如何配置 jndi 数据源 我试着把我的pom xml

随机推荐