这是我曾经用来获取但没有填充任何东西的方法。
public void doSearch() throws NamingException {
String searchFilter = "(&(ou=Example,ou=Examples_ou)(objectClass=person))";
String domain = "DC=mydom,DC=com";
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> answer = ctx.search(domain, searchFilter, searchControls);
int ttl = 0;
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult) answer.next();
ttl++;
System.out.println(">>>" + sr.getName());
Attributes attrs = sr.getAttributes();
System.out.println(">>>>>>" + attrs.get("samAccountName"));
}
System.out.println("Total results: " + ttl);
}
答案 0 :(得分:1)
您的过滤器无效,因此不返回任何数据。在
ctx.search(domain, searchFilter, searchControls);
域被作为搜索的基本DN传递。如果要将搜索限制在ou = Example,ou = dc = example,dc = com的ou = Examples_ou之内,则搜索基准DN应该为“ ou = Example,ou = Examples_ou,dc = example,dc = com”和searchFilter只是“(&(objectClass = person))”