我的客户要求之一是根据他的公司 ActiveDirectory (LDAP) 对用户进行身份验证。所以我使用了标准的 ActiveDirectoryLdapAuthenticationProvider,它的工作方式就像一个魅力。
@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;
}
Run Code Online (Sandbox Code Playgroud)
问题是客户端 AC 隐藏在防火墙后面。它在部署后可以工作,但由于客户端安全策略,我在本地开发期间无法访问 AC。因此,我有一个想法,也许对于开发配置文件,我将使用嵌入式 LDAP 服务器(UnboundID LDAP SDK for Java)。我不是 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: …Run Code Online (Sandbox Code Playgroud)