尝试从 LDAP AD 中的组中获取成员时,我遇到了一些问题。
1)我需要 1000 的页面大小,但它返回 1500 个成员(我这边有什么问题或需要询问管理员吗??)
2) Cookie 值始终为 null,我不确定缺少什么。Cookie 为空,resultpagesize 为空
如果您遇到此问题并解决了此问题,请帮助我
Hashtable<String, Object> env = new Hashtable<String, Object>();
LdapContext ctx;
byte[] cookie = null;
try {
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost");
env.put(Context.SECURITY_PRINCIPAL,"cn=testaccount");
env.put(Context.SECURITY_CREDENTIALS, "passwd");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
ctx = new InitialLdapContext(env, null);
SearchControls searchCtls = new SearchControls();
String returnedAtts[]={"member"};
searchCtls.setSearchScope(2);
searchCtls.setReturningAttributes(returnedAtts);
ctx.setRequestControls(new Control[] { new PagedResultsControl(1000, false) });
do {
NamingEnumeration answer = ctx.search("", "(&(objectClass=group)(cn=testgroup))", searchCtls);
while (answer.hasMore()) {
SearchResult entry = (SearchResult) answer.next();
String attrsValaues = entry.getAttributes().toString();
System.out.println(attrsValaues);
}
Control[] controls = ctx.getResponseControls();
if (controls != null) {
for (int i = 0; i < controls.length; i++) {
System.out.println(controls[i]);
if (controls[i] instanceof PagedResultsResponseControl) {
PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i];
cookie = prrc.getCookie();
}
}
}
ctx.setRequestControls(new Control[] { new PagedResultsControl(1000, cookie, false) });
} while(cookie!=null);
} catch (Exception e) {
e.printStackTrace();
}