C#如何覆盖LDAP服务器限制,而不是Java
本文关键字:Java 服务器 LDAP 何覆盖 覆盖 | 更新日期: 2023-09-27 18:34:07
我正在将我的 C# 程序重写为 Java,并且对 C# 应用程序可以使用此技巧提取数以万计的用户这一事实感到非常好奇:
DirectorySearcher search = new DirectorySearcher(entry);
search.SizeLimit = 99000;
search.PageSize = 98000;
但我的 Java 程序坚定地说
LDAPSearchException(resultCode=4 (超出大小限制), numEntries=1000, numReferences=0, errorMessage='超出大小限制')
我尝试了无绑定库和标准库。发现了关于这个问题的数百万讨论,到处都在说 - 限制在服务器上,你什么也做不了。
但是我的 C# 应用程序确实有效!怎么会这样?来自Microsoft的秘密技术,其他供应商无法复制?
以防万一,我的代码是:
SearchRequest searchRequest = new SearchRequest(path, SearchScope.SUB, filter, "SamAccountName");
searchRequest.setSizeLimit(99000);
searchRequest.setTimeLimitSeconds(999);
SearchResult result = connection.search(searchRequest);
for (SearchResultEntry sre : result.getSearchEntries()) {
System.out.println(count++ + ": " + sre.toString());
}
对于无界
附言我不想使用解决方法来搜索 a*、b*、c*等等。特别是,考虑到用户名可能不仅仅是英文。
进一步的阅读表明,unboundid 确实支持分页模式,因此问题得到了解决。
public static void main(String[] args) {
try {
int count = 0;
LDAPConnection connection = new LDAPConnection("hostname", 389, "user@domain", "password");
final String path = "OU=Users,DC=org,DC=com";
String[] attributes = {"SamAccountName","name"};
SearchRequest searchRequest = new SearchRequest(path, SearchScope.SUB, Filter.createEqualityFilter("objectClass", "person"), attributes);
ASN1OctetString resumeCookie = null;
while (true)
{
searchRequest.setControls(
new SimplePagedResultsControl(100, resumeCookie));
SearchResult searchResult = connection.search(searchRequest);
for (SearchResultEntry e : searchResult.getSearchEntries())
{
if (e.hasAttribute("SamAccountName"))
System.out.print(count++ + ": " + e.getAttributeValue("SamAccountName"));
if (e.hasAttribute("name"))
System.out.println("->" + e.getAttributeValue("name"));
}
LDAPTestUtils.assertHasControl(searchResult,
SimplePagedResultsControl.PAGED_RESULTS_OID);
SimplePagedResultsControl responseControl =
SimplePagedResultsControl.get(searchResult);
if (responseControl.moreResultsToReturn())
{
resumeCookie = responseControl.getCookie();
}
else
{
break;
}
}
}
catch (Exception e)
{
System.out.println(e.toString());
}
}