gpt4 book ai didi

active-directory - Spring LDAP AD 分页支持不起作用 - LDAP : error code 12 - 00000057: LdapErr: DSID-0C09079A

转载 作者:行者123 更新时间:2023-12-04 07:23:13 27 4
gpt4 key购买 nike

尝试运行上面的代码时,我收到 javax.naming.OperationNotSupportedException消息:[LDAP: error code 12 - 00000057: LdapErr: DSID-0C09079A, comment: Error processing control, data 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());
}

但是,当我使用上述纯实现删除 Spring LDAP 时,它起作用了!
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();
}

任何提示?

最佳答案

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

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

关于active-directory - Spring LDAP AD 分页支持不起作用 - LDAP : error code 12 - 00000057: LdapErr: DSID-0C09079A,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33285975/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com