javax.naming.NameNotFoundException:[LDAP:错误代码32 - 没有这样的对象];剩余名称&dc; dc = server,dc = lan,cn = admin'

时间:2016-03-11 09:59:28

标签: java ldap

是LDAP新手,我正在尝试将其用于身份验证。但我继续得到这个错误: 连接成功。

[LDAP: error code 32 - No Such Object]
javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'dc=server,dc=lan,cn=admin'
    at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3112)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3033)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2840)
    at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1849)
    at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1772)
    at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:386)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:356)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:339)
    at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267)
    at ldap.Fedora.one(Fedora.java:104)
    at ldap.Fedora.main(Fedora.java:67)

这是我到目前为止所处的位置:

    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://localhost:389/dc=server,dc=lan");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "cn=admin,dc=server,dc=world");
    env.put(Context.SECURITY_CREDENTIALS, "william");

    DirContext context = null;

    NamingEnumeration namingEnumeration = null;
    try {
        context = new InitialDirContext(env);
        System.out.println("Connection Successful.");

        SearchControls controls = new SearchControls();
        controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        namingEnumeration = context.search("dc=server,dc=lan,cn=admin", "objectClass=posixGroup", controls);
        while (namingEnumeration.hasMore()) {
            SearchResult searchResult = (SearchResult) namingEnumeration.next();
            Attributes attributes = searchResult.getAttributes();
            Attribute attr = attributes.get("cn");
            String cn = (String) attr.get();
            System.out.println(" Person Common Name = " + cn);
        }

    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();

    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        if (namingEnumeration != null) {
            try {
                namingEnumeration.close();
            } catch (Exception e) {
            }
        }
        if (context != null) {
            try {
                context.close();
            } catch (Exception e) {
            }
        }


}

2 个答案:

答案 0 :(得分:2)

错误消息表示对象&#34; dc = server,dc = lan,cn = admin&#34;无法找到。

您的搜索群应该是&#34; cn = admin,dc = server,dc = lan&#34;

答案 1 :(得分:0)

例如 使用https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

如果LDAP用户名无效,则还会显示32错误。

下面是供参考的属性

  • ldap.urls = ldap://ldap.forumsys.com:389 /
  • ldap.base.dn = cn =只读管理员,dc =示例,dc = com
  • ldap.password =密码
  • ldap.username = dc = example,dc = com
  • ldap.user.dn.pattern = uid = {用户名},ou =科学家,dc =示例,dc = com
  • ldap.aut.domain = ashokParmar