【发布时间】:2018-05-14 07:32:13
【问题描述】:
我正在尝试在 Sprint Boot 应用程序中实现 LDAP 身份验证。在测试环境中,我安装了一个用于进行身份验证的 Active Directory LDP 服务。我在 AD 实例中创建了一个用户,启用了该帐户并设置了密码。然后,我尝试使用 Spring 登录表单中的此帐户进行身份验证。
当我尝试使用 AD 登录时,我收到一条错误消息:
您的登录尝试不成功,请重试。
原因:凭据错误
由于我是 AD 和 Spring 的新手,很可能我配置错误(或两者都配置错误!)。
您对我如何进一步诊断此问题有什么建议吗?或者有什么我可能遗漏的明显内容?
我的 Spring Boot 代码(我尝试了许多不同的变体,这是一个例子):
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.formLogin();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
}
@Bean
public AuthenticationManager authenticationManager() {
return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
}
@Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider provider =
new ActiveDirectoryLdapAuthenticationProvider("foo.bar", "ldap://servername:389");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
}
【问题讨论】:
标签: spring authentication spring-boot active-directory ldap