Active directory Spring LDAP AD分页支持不工作-LDAP:错误代码12-00000057:LDAPPER:DSID-0C09079A

Active directory Spring LDAP AD分页支持不工作-LDAP:错误代码12-00000057:LDAPPER:DSID-0C09079A,active-directory,paging,spring-ldap,Active Directory,Paging,Spring Ldap,当尝试运行上面的代码时,我得到了javax.naming.OperationNotSupportedException,并显示以下消息: [LDAP:错误代码12-00000057:LDAPPER:DSID-0C09079A,注释:错误处理控制,数据0,v2580] 成功检索第一个页面,并且仅在第二次循环迭代时引发异常 public void pagedResults() { PagedResultsCookie cookie = null; SearchControls sea

当尝试运行上面的代码时,我得到了
javax.naming.OperationNotSupportedException
,并显示以下消息:
[LDAP:错误代码12-00000057:LDAPPER:DSID-0C09079A,注释:错误处理控制,数据0,v2580]

成功检索第一个页面,并且仅在第二次循环迭代时引发异常

public void pagedResults() {
    PagedResultsCookie cookie = null;
    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    int page = 1;
    do {
        logger.info("Starting Page: " + page);
        PagedResultsDirContextProcessor processor = new PagedResultsDirContextProcessor(20, cookie);

        List<String> lastNames = ldapTemplate.search("", initialFilter.encode(), searchControls, UserMapper.USER_MAPPER_VNT, processor);
        for (String l : lastNames) {
            logger.info(l);
        }
        cookie = processor.getCookie();
        page = page + 1;
    } while (null != cookie.getCookie());
}
public void pagedResults(){
PagedResultsCookie cookie=null;
SearchControls SearchControls=新的SearchControls();
searchControls.setSearchScope(searchControls.SUBTREE_范围);
int page=1;
做{
logger.info(“起始页:”+页);
PagedResultsDirContextProcessor=新的PagedResultsDirContextProcessor(20,cookie);
List lastNames=ldapTemplate.search(“”,initialFilter.encode(),searchControls,UserMapper.USER\u MAPPER\u VNT,processor);
for(字符串l:lastNames){
日志信息(l);
}
cookie=处理器。getCookie();
页码=页码+1;
}while(null!=cookie.getCookie());
}
然而,当我使用上面的纯实现删除SpringLDAP时,它就可以工作了

try {
        LdapContext ctx = new InitialLdapContext(env, null);

        // Activate paged results
        int pageSize = 5;
        byte[] cookie = null;
        ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, Control.CRITICAL) });
        int total;

        do {
            /* perform the search */
            NamingEnumeration results = ctx .search("",
                            "(&(objectCategory=person)(objectClass=user)(SAMAccountName=vnt*))",
                            searchCtls);

            /* for each entry print out name + all attrs and values */
            while (results != null && results.hasMore()) {
                SearchResult entry = (SearchResult) results.next();
                System.out.println(entry.getName());
            }

            // Examine the paged results control response
            Control[] controls = ctx.getResponseControls();
            if (controls != null) {
                for (int i = 0; i < controls.length; i++) {
                    if (controls[i] instanceof PagedResultsResponseControl) {
                        PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i];
                        total = prrc.getResultSize();
                        if (total != 0) {
                            System.out.println("***************** END-OF-PAGE "
                                    + "(total : " + total
                                    + ") *****************\n");
                        } else {
                            System.out.println("***************** END-OF-PAGE "
                                    + "(total: unknown) ***************\n");
                        }
                        cookie = prrc.getCookie();
                    }
                }
            } else {
                System.out.println("No controls were sent from the server");
            }
            // Re-activate paged results
            ctx.setRequestControls(new Control[] { new PagedResultsControl(
                    pageSize, cookie, Control.CRITICAL) });

        } while (cookie != null);

        ctx.close();

    } catch (NamingException e) {
        System.err.println("PagedSearch failed.");
        e.printStackTrace();
    } catch (IOException ie) {
        System.err.println("PagedSearch failed.");
        ie.printStackTrace();
    }
试试看{
LdapContext ctx=新的初始LdapContext(env,null);
//激活分页结果
int pageSize=5;
字节[]cookie=null;
setRequestControls(新控件[]{new PagedResultsControl(pageSize,Control.CRITICAL)});
整数合计;
做{
/*执行搜索*/
NamingEnumeration results=ctx.search(“”,
“(&(objectCategory=person)(objectClass=user)(SAMAccountName=vnt*)”,
搜索(CTL);
/*对于每个条目,打印出名称+所有属性和值*/
while(results!=null&&results.hasMore(){
SearchResult条目=(SearchResult)results.next();
System.out.println(entry.getName());
}
//检查分页结果控件响应
Control[]controls=ctx.getResponseControl();
if(控件!=null){
for(int i=0;i

有什么提示吗?

LDAP分页结果的缺点是,只有在所有请求都使用相同的底层连接时,它们才起作用。SpringLDAP的内部为每个LdapTemplate操作获得一个新的连接,除非您使用事务支持


确保相同连接将用于一系列LDapTemplate操作的最简单方法是使用事务支持,例如,为SpringLDAP配置事务,并用事务注释包装目标方法。

我使用SingleContextSource.doWithSingleContext方法成功地实现了上述示例

但是我的情况不同,我的应用程序是面向服务的,分页结果以及cookie应该发送给外部客户端,以便他决定是否请求下一页

据我所知,SpringLDAP不支持这种情况。我必须使用纯实现,以便在请求期间跟踪底层连接。事务支持和SingleContextSource一样有帮助,但在不同的请求之间没有帮助

@马图森
在spring ldap中,将来是否有任何计划支持这种支持?

我发现我可以使用您的第一个示例(spring)只要我在我的ldapTemplate配置中将ignorePartialResultException属性设置为true,并按照建议将@Transactional放在我的方法上。

您可以像这样替换
ldapTemplate

ldapTemplate.setContextSource(new SingleContextSource(ldapContextSource().getReadWriteContext()));

非常感谢你的回复。我按照你的建议做了,将@Transactional放在上面提到的pagedResults方法中,并根据配置了事务:但我还是得到了相同的结果。交易是否需要特殊?是的,它解决了问题。你是试过还是只是在闲逛?