これは、LDAP サーバーに AD 情報を照会する最初の試みです。LDAPサーバーにクエリを実行しようとしているときに、取得しようとしているのは次のとおりです。
表示名が「sav」で始まり、電子メール アドレスがあり、userAccountControl 属性が 512 である 500 レコードの countlimit を持つすべてのアクティブな従業員を取得しようとしています。私が遭遇している問題は、8 レコードしか取得できないことです。合計。文字通り、少なくとも 10 件のレコードを取得する必要があります。
検索で取得されなかった 2 つのレコードを個別に検索しましたが、それぞれにメール アドレスと userAccountControl の値が 512 ありました。したがって、これらの 2 つのレコードが欠落している理由がわかりません。
構文で何か間違ったことをしたと確信していますが、それが何であるかを見つけることができません。任意のヘルプ/指示をいただければ幸いです。ありがとうございました。
グーグルで検索した後、SEARCH FILTER を次のように定義しました。
String searchFilter = "(&(objectClass=user)(displayname="+displayname+"*"+")(mail=*)(userAccountControl=512))";
以下の完全な方法を参照してください。
public List<String> getAutocompleteEmpRecordsList(String displayname, LdapContext ctx) {
List<String> activeEmpAttributes = new ArrayList<String>();
Attributes attrs = null;
int count = 0;
int empEmailAddrLen = 0;
try {
SearchControls constraints = new SearchControls();
constraints.setCountLimit(500);
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs = {"displayname", "mail", "userAccountControl"};
constraints.setReturningAttributes(attrIDs);
String searchFilter = "(&(objectClass=user)(displayname="+displayname+"*"+")(mail=*)(userAccountControl=512))";
NamingEnumeration answer = ctx.search("OU=Standard,OU=Users,DC=xxx,DC=org", searchFilter, constraints);
if (answer != null) {
while (answer.hasMore()) {
attrs = ((SearchResult) answer.next()).getAttributes();
if (attrs.get("displayname") != null) {
int empNameLen = attrs.get("displayname").toString().length();
activeEmpAttributes.add(attrs.get("displayname").toString().substring(13, empNameLen));
}
count++;
ctx.close();
}
}
else {
throw new Exception("Invalid User");
}
System.out.println("activeEmpAttributes: " + activeEmpAttributes);
System.out.println("count: " + activeEmpAttributes.size());
} catch (Exception ex) {
ex.printStackTrace();
}
return activeEmpAttributes;
}