[英]Spring LDAP: error code 4 - Sizelimit Exceeded - when setting countLimit to 1
[英]How to fix Ldap connection error “javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]” in Java?
AD有7563名員工。 我需要使用 (employeeId=*) 來選擇它們
以下是我的 Java 代碼:
Hashtable<String, String> ldapEnv = new Hashtable<>();
ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
ldapEnv.put(Context.PROVIDER_URL, PROVIDER_URL);
ldapEnv.put("com.sun.jndi.Ldap.connect.timeout", CONNECTION_TIMEOUT); // specify timeout out to be 5 seconds
ldapEnv.put(Context.SECURITY_AUTHENTICATION, AUTHENTICATION_TYPE);
ldapEnv.put(Context.SECURITY_PRINCIPAL, AD_USER);
ldapEnv.put(Context.SECURITY_CREDENTIALS, AD_PASS);
DirContext context = new InitialDirContext(ldapEnv); // initial context created
System.out.println("(employeeID=" + aDemployeeID + ")");
String searchFilter = "(employeeID=*)";
SearchControls controls = new SearchControls();
String[] requiredAttribute = { "mail", "Targetaddress", "UserPrincipalName" };
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
controls.setReturningAttributes(requiredAttribute);
controls.setCountLimit(1200);
NamingEnumeration<SearchResult> users1 = context.search(SEARCH_DIRECTORY_1, searchFilter, controls);
adAttributesToEVRYIntegrator = new HashMap<>();
int count = 0;
while (users1.hasMore()) {
SearchResult sr = users1.next();
NamingEnumeration<? extends Attribute> aDattributes = sr.getAttributes().getAll();
count = count + 1;
while (aDattributes.hasMore()) {
Attribute requestedAttributesFromAD = aDattributes.next();
System.out.println(requestedAttributesFromAD.get().toString());
System.out.println(count);
}
Output:
After 1000 Records:
javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]; remaining name 'OU=Users,OU=Sweden,OU=CCD,OU=Customers,DC=corp,DC=corpcommon,DC=com'
我檢查了多個文件夾,發現:
誰能建議如何從 LDAP 獲取所有記錄
PS:我已經對相關帖子進行了所有更改,但無法解決問題。
您需要使用PagedResultsControl
。 您將不得不更改context
的聲明,使其成為LdapContext
,並且您可以在PagedResultsControl
的構造函數中InitialLdapContext
:
int pageSize = 1000;
LdapContext context = new InitialLdapContext(ldapEnv, new Control[] {
new PagedResultsControl(pageSize, Control.CRITICAL) });
pageSize
可以是 <= 1000 的任何值。
您似乎遇到了 Microsoft Active Directory MaxPageSize設置,該設置控制在單個搜索結果中返回的最大對象數。
您不能從客戶端更改 MaxPageSize。
Microsoft 的建議是使用簡單的分頁結果控件。
我確實注意到你有:
控制.setCountLimit(1200);
它設置了作為結果在客戶端上返回的最大條目數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.