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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35937105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:16:25  来源:igfitidea点击:

javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'dc=server,dc=lan,cn=admin'

javaldap

提问by user3278647

Am new to LDAP and am trying to use it for authentication. But i keep on getting this error: Connection Successful.

我是 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)

This is where i have reached so far:

这是我到目前为止到达的地方:

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


}

回答by Thomas Kl?ger

The error message means that the object "dc=server,dc=lan,cn=admin" cannot be found.

错误信息表示找不到对象“dc=server,dc=lan,cn=admin”。

Your search base should probably be "cn=admin,dc=server,dc=lan"

您的搜索基础应该是“cn=admin,dc=server,dc=lan”

回答by Ashok Parmar

For example using https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

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

if LDAP username is not valid set then also shows 32 error.

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

below are the properties for reference

以下是可供参考的属性

  • ldap.urls=ldap://ldap.forumsys.com:389/
  • ldap.base.dn=cn=read-only-admin,dc=example,dc=com
  • ldap.password=password
  • ldap.username=dc=example,dc=com
  • ldap.user.dn.pattern =uid={username},ou=scientists,dc=example,dc=com
  • ldap.aut.domain=ashokParmar
  • ldap.urls=ldap://ldap.forumsys.com:389/
  • ldap.base.dn=cn=read-only-admin,dc=example,dc=com
  • ldap.password=密码
  • ldap.username= dc=example,dc=com
  • ldap.user.dn.pattern =uid={username},ou=scientists,dc=example,dc=com
  • ldap.aut.domain=ashokParmar