在 java 应用程序中使用 jndi 的身份验证错误 49 52e - 无效令牌

Authentication error 49 52e with jndi in a java application- invalid token

我想询问 LDAP 服务器在 Java 应用程序中提供的用户名和密码是否正确。

我最终将 jndi 与此功能一起使用(这是我用来探索 LDAP 的测试功能,returns 异常消息):

public static String checkCredentials(String securityPrincipal,
                               String password,
                               String ldapUrl,
                               String securityAuthentication) 
{
    String userVerify = "";
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, ldapUrl);
    env.put(Context.SECURITY_AUTHENTICATION, securityAuthentication);
    env.put(Context.SECURITY_PRINCIPAL, securityPrincipal);
    env.put(Context.SECURITY_CREDENTIALS, password);

    try {
        DirContext authContext = new InitialDirContext(env);
        userVerify = testDescription + " - Success";
        authContext.close();
    } catch (AuthenticationException authEx) {
        userVerify = "AuthenticationException: " + authEx.getMessage();//"Authentication failed!";
    } catch (NamingException namEx) {
        userVerify = "NamingException: " + namEx.getMessage();//"Something went wrong!";
    } 
    return userVerify;
}

当我通过传递正确的 ldapUrl 调用 checkCredentials 时(在我的例子中是 ldap://192.168.48.60:389),我总是得到结果(函数 returns a String):

AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903A8, comment: AcceptSecurityContext error, data 52e, v1db1]

这个page说是认证错误(49)和"username is valid but password/credential is invalid"(52e)。

我为 securityPrincipal 尝试了所有这些:

john

john@mycompany

CN=john,conn

CN=john,OU=internal users,DC=mycompany

passwordsecuirityAuthentication 似乎被忽略了。

我尝试从 http://www.ldapadmin.org/ 安装 LDAP admin,我也从中得到:

LDAP error! Invalid credentials: 80090308: LdapErr: DSID-0C0903A8, comment: AcceptSecurityContext error, data 52e, v1db1.

传递给函数的令牌无效。

不知何故,这告诉了我更多信息 "invalid token"。

有什么指点吗?我卡住了。

在 securityAuthentication 中传递 "none" 而不是 "simple" 成功了。

至少没有异常,即使UserVerifyT returns成功即使密码错误,如果邮件被退回,我会像过去一样通过检索用户的邮件来处理密码没问题