如果用户名包含点(。),则Active Directory LDAP身份验证失败

时间:2013-11-24 13:43:25

标签: java authentication active-directory ldap username

我在Java中创建了一个Active Directory(winserver 2012)LDAP身份验证器,在这种情况下,当AD用户名包含dost(。)时,身份验证失败,但有以下异常:

javax.naming.AuthenticationException: [LDAP: error code 49 - 8009030C: LdapErr: DSID-0C0904F8, comment: AcceptSecurityContext error, data 52e, v23f0

如果用户名不包含dot,则为auth。工作正常。

有代码:

private DirContext getDirContext(String username, String password) {

    ...

    Hashtable<String, String> env = new Hashtable<>();

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.SECURITY_AUTHENTICATION, "DIGEST-MD5");
    env.put(Context.PROVIDER_URL, "LDAP://server.test.local:389");
    env.put(Context.SECURITY_PRINCIPAL, "test.user");
    env.put(Context.SECURITY_CREDENTIALS, "password");
    env.put(Context.REFERRAL, "follow");
    env.put("java.naming.ldap.attributes.binary", "objectGUID objectSid");

    DirContext ctx;

    try {
        ctx = new InitialLdapContext(env, null);
    } catch (NamingException ex) {
        getLogger().log(Level.WARNING,
                "ACTIVE DIRECTORY - AUTHENTICATION ERROR: " + ex);
    }

    return ctx;
}

我尝试将点替换为%2e,我尝试了完整的用户名(test.user@test.local),但这些并没有解决我的问题。

有人有什么想法吗?感谢。

1 个答案:

答案 0 :(得分:1)

Context.SECURITY_PRINCIPAL必须是您正在使用的上下文中的有效主体名称。 (在您的情况下为LDAP - AD。)

因此,完全限定的DN或userPrincipalName或domain \ samaccountname应该有效。 我们提出了一些JNDI samples