C#如何覆盖LDAP服务器限制,而不是Java [英] How can C# override LDAP server limit, but not Java
问题描述
我正在将我的C#程序重写为Java,并对有关C#应用程序可以使用此技巧提取成千上万用户的事实感到非常好奇:
I'm rewriting my C# program to Java and became very curios about the fact that C# application can extract tens of thousands of users with this trick:
DirectorySearcher search = new DirectorySearcher(entry);
search.SizeLimit = 99000;
search.PageSize = 98000;
但是我的Java程序坚定地说
but my Java programs firmly say
LDAPSearchException(resultCode = 4(超出大小限制),numEntries = 1000,numReferences = 0,errorMessage =超出大小限制")
我尝试了unboundid和标准库.已找到有关该问题的数百万次讨论,到处都有报道-限制在服务器上,您无能为力.
I tried both unboundid and standard libraries. Found million discussions about this problem and everywhere is said - the limitation is on server, you can do nothing.
但是我的C#应用程序确实可以工作!怎么会这样微软的秘密技术,其他供应商无法重复?
But my C# application does work! How can this happen? Secret techniques from Microsoft, that cannot be repeated by other vendors?
以防万一,我的代码是:
Just in case, my code is:
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());
}
对于无限制
p.s.我不想在搜索a *,b *,c *时使用变通办法 等等.特别是考虑到用户名可能不仅是英文的.
p.s. I do not want to use workaround with searching for a*, b*, c* et c. Especially, considering that usernames might be not only in English.
推荐答案
进一步的阅读显示,unboundid确实支持分页模式,因此问题得以解决.
Further reading showed, that unboundid does support paged mode, so problem is solved.
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());
}
}
这篇关于C#如何覆盖LDAP服务器限制,而不是Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!