简体   繁体   English

InitialDirContext.search()错误的结果

[英]Wrong result with InitialDirContext.search()

I have now tried to make this work for two days with two different libraries, but it just don't want to do what I want. 我现在已经尝试使用两个不同的库将其工作两天,但是它只是不想做我想做的事情。 So here's the problem: 所以这是问题所在:

I'm trying to load ldap entries with java, I'm using the "org.ietf.ldap"-Library. 我正在尝试使用Java加载ldap条目,而我正在使用“ org.ietf.ldap” -Library。 Without problems, I can get single entries out of ldap, works perfectly, but with a special query, I only get one entry back from ldap, but there should be 15 entries. 没问题,我可以从ldap中获得单个条目,并且运行良好,但是通过特殊查询,我只能从ldap中获得一个条目,但是应该有15个条目。

Here's my code: 这是我的代码:


public void getEntries (String searchDN, int scope, InitialDirContext conn, String attributeName, String attributeValue) {
        List ansp = new ArrayList();
        final String QUERY = "cpMemDN=cn=usuid,ou=EMP,ou=COMPANY,o=META";
                    searchDN = "ou=SUPPORT, ou=ROLES, ou=SERVICES, ou=COMPANY, o=META";
        SearchControls ctrl = new SearchControls();
        ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
        NamingEnumeration enumeration = null;

    try {
        enumeration = context.search(searchDN, QUERY, ctrl);
    } catch (NamingException e) {
        e.printStackTrace();
    }
    Set<String> cns = new HashSet<String>();
    try {
              while (enumeration.hasMore()) {
            SearchResult result = (SearchResult) enumeration.next();

        }
    } catch (NamingException e) {
        e.printStackTrace();
    }

}

So how I said, the enumeration only contains one entry instead of 15 entries (checked with LDAPBrowser). 所以我怎么说,该枚举只包含一个条目,而不是15个条目(已通过LDAPBrowser检查)。 I also tried getting multiple entries with another query (cn=*) and it worked, I got multiple entries but the query can't be the problem because it works with LDAPBrowser. 我还尝试通过另一个查询(cn = *)获取多个条目,并且它起作用了,我得到了多个条目,但是由于它与LDAPBrowser一起使用,查询不是问题。

Any ideas? 有任何想法吗?

Okey it works now with the same code, just tried for 50 times haha. Okey现在可以使用相同的代码工作,仅尝试了50次哈哈。 Strange thing, but solved. 奇怪的事情,但是解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM