你好,我有使用LDAP创建简单的登录问题。我已经从spring.io网站下载了入门项目:link它与ldif文件完美结合,但我想用运行ldap服务器替换它。我已经尝试了好几天没有进展。我与这段代码(在WebSecurityConfig取代入门项目)春季启动LDAP安全
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
}
@Override
protected void configure(AuthenticationManagerBuilder authManagerBuilder) throws Exception {
authManagerBuilder.authenticationProvider(activeDirectoryLdapAuthenticationProvider()).userDetailsService(userDetailsService());
}
@Bean
public AuthenticationManager authenticationManager() {
return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
}
@Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(null, "ldap://ip:port/", "ou=GROUP,dc=domain,dc=com");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
}
如果我尝试用格式“用户名”,“密码”控制台输出良好的用户名和密码登录最好的结果:ActiveDirectoryLdapAuthenticationProvider:活动目录身份验证失败:提供的密码无效
如果我使用“[email protected]”和良好的密码,页面只是没有输出到控制台重新加载。
如果我使用随机用户名和密码控制台:Active Directory身份验证失败:提供的密码无效
有人能帮忙吗?
正如你在ActiveDirectoryLdapAuthenticationProvider的构造函数中使用“空”的域名,则必须使用“的UserPrincipalName”([email protected])来验证 您可以启用日志记录,以找出为什么这不工作或如果你不使用LDAPS或StartTLS扩展操作的网络跟踪会肯定地告诉如果LDAP BIND请求成功 –