我知道“52e”代码是当用户名有效但密码无效时。我在apache studio中使用相同的用户名和密码,因此能够成功建立到LDAP的连接。
这是我的Java代码
String userName = "*******";
String password = "********";
String base ="DC=PSLTESTDOMAIN,DC=LOCAL";
String dn = "cn=" + userName + "," + base;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://******");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
LDAPAuthenticationService ldap = new LDAPAuthenticationService();
// LdapContext ctx;
DirContext ctx = null;
try {
ctx = new InitialDirContext(env);
我的错误在这行上:
ctx = new InitialDirContext(env);
我不知道是什么导致了此错误。
最佳答案
数据52e-Returns when username is valid but password/credential is invalid.
您可能需要类似
String dn = "cn=" + userName + "," + "CN=Users," + base;