Java 使用ActiveDirectoryLdapAuthenticationProvider和嵌入式ldif的Spring身份验证
我的客户要求之一是根据他的公司ActiveDirectory(LDAP)对用户进行身份验证。所以我使用了标准的ActiveDirectoryLdapAuthenticationProvider,它就像一个符咒Java 使用ActiveDirectoryLdapAuthenticationProvider和嵌入式ldif的Spring身份验证,java,spring,authentication,active-directory,ldap,Java,Spring,Authentication,Active Directory,Ldap,我的客户要求之一是根据他的公司ActiveDirectory(LDAP)对用户进行身份验证。所以我使用了标准的ActiveDirectoryLdapAuthenticationProvider,它就像一个符咒 @Bean public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() { ActiveDirectoryLdapAuthenticationProvide
@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider adProvider = new ActiveDirectoryLdapAuthenticationProvider(
ldapConfig.getLdapDomain(), ldapConfig.getLdapUrl(), ldapConfig.getLdapRoot());
adProvider.setConvertSubErrorCodesToExceptions(true);
adProvider.setUseAuthenticationRequestCredentials(true);
adProvider.setSearchFilter(ldapConfig.getLdapSearchFilter());
return adProvider;
}
问题是客户端AC隐藏在防火墙后面。它在部署后工作,但由于cleints的安全策略,我无法在本地开发期间联系AC。所以,我有一个想法,也许对于dev概要文件,我将使用嵌入式LDAP服务器(unboundedldapsdkforjava)。我不是LDAP专家,但我以某种方式编写了简单的ldif文件,它看起来如下:
dn: dc=test,dc=local
objectclass: top
objectclass: domain
objectclass: extensibleObject
dc: test
# Organizational Units
dn: ou=groups,dc=test,dc=local
objectclass: top
objectclass: organizationalUnit
ou: groups
dn: ou=people,dc=test,dc=local
objectclass: top
objectclass: organizationalUnit
ou: people
# Users
dn: uid=john,ou=people,dc=test,dc=local
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: John Doe
sn: John
uid: john
password: johnspassword
# Create Groups
dn: cn=administrators,ou=groups,dc=test,dc=local
objectclass: top
objectclass: groupOfUniqueNames
cn: administrators
ou: administrator
uniqueMember: uid=john,ou=people,dc=test,dc=local
我还配置了嵌入式ldap属性:
spring.ldap.embedded.base-dn=dc=test,dc=local
spring.ldap.embedded.ldif=classpath:localldapactivedirectory.ldif
spring.ldap.embedded.port=12345
spring.ldap.embedded.url=ldap://localhost:12345/
spring.ldap.embedded.validation.enabled=false
Unbounded对此没有问题,但正如您猜的那样,我在身份验证过程中遇到了问题:
[LDAP: error code 34 - Unable to parse bind DN 'john@test.local': Unable to parse string 'john@test.local' as a DN because it does not have an equal sign after RDN attribute 'john@test.local'.]; nested exception is javax.naming.InvalidNameException: [LDAP: error code 34 - Unable to parse bind DN 'john@test.local': Unable to parse string 'user_cms@test.com' as a DN because it does not have an equal sign after RDN attribute 'john@test.local'.]
为了向您展示整个情况,我添加了在身份验证尝试期间发生的错误(在自定义身份验证服务中):
我认为这是由于我的ldif文件太简单造成的。它可以与普通Ldap身份验证提供程序一起使用,但不能与ActiveDirectoryLdapAuthenticationProvider一起使用
是否有人知道如何在ldif文件中“模拟”ActiveDirectory(LDAP),以便ActiveDirectoryLdapAuthenticationProvider可以在身份验证期间使用它 我也遇到了同样的问题,并找到了一个有效的解决方案,但我对此不太满意。 以下是它对我的作用:
.ldif
文件
将userPrincipalName
属性添加到.ldif
文件中,并使用与dn
相同的值填充该文件,在您的情况下:
dn: uid=john,ou=people,dc=test,dc=local
userPrincipalName: uid=john,ou=people,dc=test,dc=local
dn
而不是电子邮件地址进行身份验证
您使用john@test.local
在您的身份验证测试中。要使其工作,您必须使用dn
:uid=john,ou=people,dc=test,dc=local
欢迎提供更好的解决方案 我也遇到了同样的问题,并找到了一个有效的解决方案,但我对此不太满意。 以下是它对我的作用:
.ldif
文件
将userPrincipalName
属性添加到.ldif
文件中,并使用与dn
相同的值填充该文件,在您的情况下:
dn: uid=john,ou=people,dc=test,dc=local
userPrincipalName: uid=john,ou=people,dc=test,dc=local
dn
而不是电子邮件地址进行身份验证
您使用john@test.local
在您的身份验证测试中。要使其工作,您必须使用dn
:uid=john,ou=people,dc=test,dc=local
欢迎提供更好的解决方案 很长时间了,你找到解决办法了吗?很长时间了,你找到解决办法了吗?