使用 JAAS LdapLoginModule 向 ActiveDirectory 进行身份验证时遇到 FailedLoginException

FailedLoginException encountered when using JAAS LdapLoginModule to authenticate with ActiveDirectory

我正在努力尝试让 LDAP 身份验证与 Active Directory 一起工作。

我们刚刚设置了 SharePoint Server 2010,我们认为最好还针对 Active Directory 对用户进行身份验证,因为它已经存在于 SharePoint 中。我们的环境是 Windows Server 2008 R2 Standard。

我有一个用户的用户名是 ahsieh@rdl.com.tw

根据这个答案 https://serverfault.com/a/130556 我的提供者 URL 应该是 ldap://192.168.0.81:389/CN=Users,DC=rdl,DC=com,DC=tw(请注意,我没有使用 vm-sps.rdl.com.tw 的主机名,而是选择了使用 IP 地址,因为我没有时间为所述服务器配置 DNS 条目)

为了确定,我已经 运行 服务器上的 dsquery 命令:

但是,我无法进行身份验证工作。我已经按照 LdapLoginModule API

尝试了所有三种类型的 JAAS 配置

以下是我遇到的错误:

1.搜索优先模式:

注意:我没有指定 authzIdentity,因为我在 AD

上没有那个设置

JAAS 配置:

AESLogin_AD1 {
    com.sun.security.auth.module.LdapLoginModule REQUIRED
    userProvider="ldap://192.168.0.81:389/CN=Users,DC=rdl,DC=com,DC=tw"
    userFilter="(&(uid={USERNAME})(objectClass=User))"
    useSSL=false
    debug=true;
};

结果:

        [LdapLoginModule] search-first mode; SSL disabled
        [LdapLoginModule] user provider: ldap://192.168.0.81:389/CN=Users,DC=rdl,DC=com,DC=tw
        [LdapLoginModule] searching for entry belonging to user: ahsieh@rdl.com.tw
        [LdapLoginModule] authentication failed
        [LdapLoginModule] aborted authentication
javax.security.auth.login.FailedLoginException: Cannot find user's LDAP entry

2。身份验证优先模式

JAAS 配置:

AESLogin_AD2 {
    com.sun.security.auth.module.LdapLoginModule REQUIRED
    userProvider="ldap:///CN=Users,DC=rdl,DC=com,DC=tw"
    authIdentity="{USERNAME}"
    userFilter="(&(|(samAccountName={USERNAME})(userPrincipalName={USERNAME})(cn={USERNAME}))(objectClass=user))"
    useSSL=false
    debug=true;
};

结果:

        [LdapLoginModule] authentication-first mode; SSL disabled
        [LdapLoginModule] user provider: ldap:///CN=Users,DC=rdl,DC=com,DC=tw
        [LdapLoginModule] attempting to authenticate user: ahsieh@rdl.com.tw
        [LdapLoginModule] authentication failed
        [LdapLoginModule] aborted authentication
javax.security.auth.login.FailedLoginException: Cannot bind to LDAP server

3。仅身份验证模式

注意:我没有指定 authzIdentity,因为我在 AD

上没有那个设置

JAAS 配置:

AESLogin_AD3 {
    com.sun.security.auth.module.LdapLoginModule REQUIRED
    userProvider="ldap://192.168.0.81:389"
    authIdentity="CN={USERNAME},CN=Users,DC=rdl,DC=com,DC=tw"
    useSSL=false
    debug=true;
};

结果:

        [LdapLoginModule] authentication-only mode; SSL disabled
        [LdapLoginModule] user provider: ldap://192.168.0.81:389
        [LdapLoginModule] attempting to authenticate user: ahsieh@rdl.com.tw
        [LdapLoginModule] authentication failed
        [LdapLoginModule] aborted authentication
javax.security.auth.login.FailedLoginException: Cannot bind to LDAP server

我还根据我在 Internet 上遇到的一些示例尝试了另一种配置:

4.来自其他示例的配置

JAAS 配置:

AESLogin_AD4 {
    com.sun.security.auth.module.LdapLoginModule REQUIRED
    userProvider="ldap://192.168.0.81:389/CN=Users,DC=rdl,DC=com,DC=tw"
    authIdentity="{USERNAME}"
    useSSL=false
    debug=true;
};

结果:

        [LdapLoginModule] authentication-only mode; SSL disabled
        [LdapLoginModule] user provider: ldap://192.168.0.81:389/CN=Users,DC=rdl,DC=com,DC=tw
        [LdapLoginModule] attempting to authenticate user: ahsieh@rdl.com.tw
        [LdapLoginModule] cannot create LdapPrincipal: bad DN
        [LdapLoginModule] authentication failed
        [LdapLoginModule] aborted authentication
javax.security.auth.login.FailedLoginException: Cannot create LdapPrincipal

注意:我的第四次试验似乎取得了微小的进展,因为至少 LDAP 绑定似乎有效,但现在问题似乎是 cannot create LdapPrincipal: bad DN

我已经进入 LdapLoginModule 的源代码并通过匹配调试消息,似乎这是由(从第 837 行开始)引起的:

try {

    ldapPrincipal = new LdapPrincipal(dn);

} catch (InvalidNameException e) {
    if (debug) {
        System.out.println("\t\t[LdapLoginModule] " +
                           "cannot create LdapPrincipal: bad DN");
    }
    throw (LoginException)
        new FailedLoginException("Cannot create LdapPrincipal")
            .initCause(e);
}

并且基于LdapPrincipal APIInvalidNameException被抛出如果检测到语法违规,但我不知道语法违规在哪里。

我也不知道如何调试它。

任何帮助将不胜感激!谢谢!

我在网上看了很多文章,最后从 Bonitasoft 的问答中找到了解决方案 JAAS config for Active Directory LDAP

JAAS 配置:

AESLogin_ADx {
    com.sun.security.auth.module.LdapLoginModule REQUIRED
    userProvider="ldap://192.168.0.81:389/CN=Users,DC=rdl,DC=com,DC=tw"
    authIdentity="{USERNAME}@rdl.com.tw"
    userFilter="(&(|(samAccountName={USERNAME})(userPrincipalName={USERNAME})(cn={USERNAME}))(objectClass=user))"
    useSSL=false
    debug=true;
};

结果:

[LdapLoginModule] authentication-first mode; SSL disabled
[LdapLoginModule] user provider: ldap://192.168.0.81:389/CN=Users,DC=rdl,DC=com,DC=tw
[LdapLoginModule] attempting to authenticate user: ahsieh
[LdapLoginModule] searching for entry belonging to user: ahsieh
[LdapLoginModule] found entry: CN=Arthur Hsieh,CN=Users,DC=rdl,DC=com,DC=tw
[LdapLoginModule] authentication succeeded
[LdapLoginModule] added LdapPrincipal "CN=Arthur Hsieh,CN=Users,DC=rdl,DC=com,DC=tw" to Subject
[LdapLoginModule] added UserPrincipal "ahsieh" to Subject