使用JAAS LdapLoginModule通过ActiveDirectory进行身份validation时遇到FailedLoginException

我正在拉我的头发试图让LDAP身份validation与Active Directory一起使用。

我们刚刚设置了一个SharePoint Server 2010,我们认为根据Active Directory对用户进行身份validation也是一个好主意,因为它已经存在于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命令: 在此处输入图像描述

但是,我只是无法获得身份validation工作。 我根据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.仅validation模式

注意:我没有指定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 

我还尝试了另一个配置,基于我在互联网上遇到的一些例子:

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 API ,抛出InvalidNameException 如果检测到语法违规 ,但我不知道语法违规在哪里。

我也不知道如何调试这个。

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

我在网上看了很多文章,最后找到了Bonitasoft 针对Active Directory LDAP的Q&A JAAS配置的解决方案

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