- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从 Java 枚举我们 Active Directory 中的所有组。有很多,所以我在 1000 个结果后得到一个 SizeLimitExceededException
。我正在尝试使用 PagedResultsControl
,我的代码非常接近网络上所有示例的模型,并且它可以正常工作,因为它不再抛出 SizeLimitExceededException
,并返回匹配指定页面大小的结果数(前提是不大于 1000)。
但是,下一步是从响应中获取 cookie 并使用它来获取下一页,我的问题是在调用 搜索()
。事实上 getResponseControls()
返回 null
。
我进行了广泛的搜索,似乎找不到任何其他人报告此问题,我几乎被困在这里。那我做错了什么?为什么我没有得到 PagedResultsResponseControl
?
我们的域在 Windows Server 2016 上运行,我已将我的代码缩减为以下测试用例:
public class PagingTest {
public static void main(String[] args) throws Exception {
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_PRINCIPAL, "username");
env.put(Context.SECURITY_CREDENTIALS, "password");
env.put(Context.PROVIDER_URL, "ldap://campus.uni.ac.uk/DC=campus,DC=uni,DC=ac,DC=uk");
LdapContext adContext = new InitialLdapContext(env, null);
// Set up search controls.
SearchControls searchControl = new SearchControls();
searchControl.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attributesToFetch = {"cn"};
searchControl.setReturningAttributes(attributesToFetch);
// Set up a paged search.
final int pageSize = 500;
byte[] cookie = null;
adContext.setRequestControls(new Control[]{
new PagedResultsControl(pageSize, Control.CRITICAL)
});
// Do the search.
int count = 0;
boolean finished = false;
while (!finished) {
NamingEnumeration<SearchResult> records
= adContext.search("OU=Groups", "objectClass=group", searchControl);
// Examine the page's results control response and act accordingly.
Control[] controls = adContext.getResponseControls();
if (controls != null) {
for (int i = 0; i < controls.length; ++i) {
if (controls[i] instanceof PagedResultsResponseControl) {
PagedResultsResponseControl prrc =
(PagedResultsResponseControl) controls[i];
cookie = prrc.getCookie();
if (cookie == null) {
finished = true;
}
}
}
} else {
cookie = null;
finished = true;
}
// Process the page of results.
while (records != null && records.hasMore()) {
SearchResult sr = records.next();
Attributes attribs = sr.getAttributes();
BasicAttribute ba = (BasicAttribute) attribs.get("cn");
String cn = (String) ba.get();
System.out.println(cn);
++count;
}
// Re-activate paged results with the new cookie.
adContext.setRequestControls(new Control[]{
new PagedResultsControl(pageSize, cookie, Control.CRITICAL)
});
}
System.out.println("Found " + count + " groups");
}
}
最佳答案
可能你的ldap服务器不支持分页查询,你可以像这样使用ldapsearch命令:
ldapsearch -H ldap://xxxx:389 -x -D "uid=zhangsan,ou=employee,dc=test,dc=com" -W -b "" -s base -a always "(objectClass=*)" "supportedControl"
如果返回值中包含1.2.840.113556.1.4.319
,说明您的ldap服务器支持分页查询。
关于java - 为什么 Active Directory 不返回 PagedResultsResponseControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51878159/
我正在尝试从 Java 枚举我们 Active Directory 中的所有组。有很多,所以我在 1000 个结果后得到一个 SizeLimitExceededException。我正在尝试使用 Pa
我是一名优秀的程序员,十分优秀!