gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:43:06 29 4
gpt4 key购买 nike

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


}

最佳答案

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

您的搜索库可能应该是“cn=admin,dc=server,dc=lan”

关于javax.naming.NameNotFoundException : [LDAP: error code 32 - No Such Object]; remaining name 'dc=server,dc=lan,cn=admin' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35937105/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com