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

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

我有一个用户名是 [email protected] java - 使用 JAAS LdapLoginModule 与 Active Directory 进行身份验证时遇到 FailedLoginException-LMLPHP

根据这个答案 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 命令:java - 使用 JAAS LdapLoginModule 与 Active Directory 进行身份验证时遇到 FailedLoginException-LMLPHP

但是,我无法进行身份验证工作。我已经按照 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: [email protected]
        [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: [email protected]
        [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: [email protected]
        [LdapLoginModule] authentication failed
        [LdapLoginModule] aborted authentication
javax.security.auth.login.FailedLoginException: Cannot bind to LDAP server

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

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: [email protected]
        [LdapLoginModule] cannot create LdapPrincipal: bad DN
        [LdapLoginModule] authentication failed
        [LdapLoginModule] aborted authentication
javax.security.auth.login.FailedLoginException: Cannot create LdapPrincipal

注意:我的第四次试验似乎略有进展,因为至少 LDAP 绑定(bind)似乎有效,但现在问题似乎是 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 API ,如果检测到语法违规,则会抛出 InvalidNameException ,但我不知道语法违规在哪里。

我也不知道如何调试它。

任何帮助都感激不尽!谢谢!

最佳答案

我在网上浏览了更多文章,终于从 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

关于java - 使用 JAAS LdapLoginModule 与 Active Directory 进行身份验证时遇到 FailedLoginException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36548510/

10-11 01:07