这是我曾经用来获取但没有填充任何东西的方法。

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);
    }

最佳答案

您的过滤器无效,因此不返回任何数据。在

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))”

关于java - 如何使用Java从 Activity 目录中的特定ou获取所有用户?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53909217/

10-11 00:18