简体   繁体   English

LDAP不返回任何结果

[英]LDAP not returning any results

I have a piece of Java code that does a simple search of an Active Directory. 我有一段Java代码可以对Active Directory进行简单搜索。 The code functions as expected when using out production AD but when using the same code on out test AD no results are returned (no exception or error is thrown either). 在使用正式生产AD时,代码将按预期方式运行,但是在正式测试AD中使用相同的代码时,则不会返回任何结果(也不会引发异常或错误)。

When using an AD browser on my machine I am able to browse and search the test AD and find the results I am looking for. 在计算机上使用AD浏览器时,我可以浏览和搜索测试AD,并找到所需的结果。

The AD allows read access to everyone so it isn't a permissions problem. AD允许所有人读取权限,因此这不是权限问题。

Does anyone know what could be causing it not to return any results to my java client but does to my browser? 有谁知道是什么原因导致它不返回任何结果给我的Java客户端,而是返回给我的浏览器?

Java code: Java代码:

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, Constants.LDAPURL);
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.REFERRAL, "follow");
        DirContext dctx = new InitialDirContext(env);

        String base = Constants.LDAPQUERYLOCATION;

        SearchControls sc = new SearchControls();
        String[] attributeFilter = {"cn", "sAMAccountName", "sn", "distinguishedName"};
        sc.setReturningAttributes(attributeFilter);
        sc.setSearchScope(SearchControls.SUBTREE_SCOPE);

        String filter = "(&(objectClass=User)(sn=smith))";
        NamingEnumeration results = dctx.search(base, filter, sc);
        if(!results.hasMore()){
            log.debug("No results found");
        }
        while (results.hasMore()) {
            SearchResult sr = (SearchResult) results.next();
            Attributes attrs = sr.getAttributes();
            Attribute attr = attrs.get("cn");
            log.debug("cn: "+attr.get());
            attr = attrs.get("sn");
            log.debug("sn: "+attr.get());
            attr = attrs.get("distinguishedName");
            log.debug("dn: "+attr.get());
        }
        dctx.close();

I don't have control of the AD so I can't really provide much information about its setup. 我没有控制AD的功能,因此我无法提供有关其设置的太多信息。

Just tried your code on my network, which is using OpenLDAP - which I know is not the same as AD, but : 刚刚在使用OpenLDAP的网络上尝试了您的代码-我知道它与AD不同, 但是

I got no results either until I changed my filter string to this: 在将filter字符串更改为此之前,我也没有任何结果:

String filter = "(&(objectClass=inetOrgPerson)(sn=smith))";

I got that inetOrgPerson object class by snooping into the directory with an LDAP browser. 我通过使用LDAP浏览器窥探目录来获得了inetOrgPerson对象类。 It's a long-shot, but is it possible that your test AD isn't using the same object classes as your production server? 这是一个长期的尝试,但是您的测试广告是否可能没有使用与生产服务器相同的对象类?

A quick Google shows me that Microsoft's implementation of the LDAP standard was lacking at first, but should now be (more) compliant with the use of inetOrgPerson - maybe your test AD is running an older version with the problems, while your prod box is on the latest-and-greatest? 快速的Google告诉我, 起初缺乏 Microsoft 对LDAP标准实现,但现在应该(更多)inetOrgPerson的使用兼容 -也许您的测试广告正在运行有问题的旧版本,而您的产品框仍在最新最伟大的? Or perhaps vice-versa? 或者反之亦然?

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

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