使用Spring安全 基本身份验证设置适用于某些硬编码的用户名密码,如下所示:
http://thoughtfulsoftware.wordpress.com/2013/12/08/adding-security-to-spring-guides-rest-service/
因此尝试扩展它以使用 LDAP。
已完成使用我们的 LDAP 服务器进行 LDAP 身份验证的设置
现在,当我尝试通过 REST 控制台插件调用我的休息服务时,会不断弹出用户名密码的授权窗口。如果我取消授权失败,不知道哪里出了问题
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.csrf().disable()
.httpBasic();
@Override
protected void configure(AuthenticationManagerBuilder authManagerBuilder) throws Exception {
authManagerBuilder
.ldapAuthentication()
.userSearchFilter("(uid={0})").userSearchBase("ou=people,dc=zzz,dc=xxxx,dc=yyy")
.groupRoleAttribute("cn").groupSearchFilter("(member={0})")
//.userDnPatterns("uid={0},ou=people")
//.groupSearchBase("ou=groups")
.contextSource().url("ldaps://ldap.xxxx.yyy:636/cn=cw-grpreader,ou=people,dc=xxx,dc=xxxx,dc=xxx")
.managerDn("cn=xx-xxr,ou=people,dc=med,dc=xxxx,dc=xxx")
.managerPassword("#$%^^");
}
这是我尝试的一种方法,它提供了重复的身份验证弹出窗口 如果我取消弹出窗口,我会得到 HTTP 状态 401 - [LDAP:错误代码 49 - NDS 错误:身份验证失败 (-669)];即使凭据正确也会出错 一些教程的链接将非常有帮助
最佳答案
这是由于您设置的 httpbasic 身份验证所致。 Spring Boot 会生成一个随 secret 码,该密码显示在控制台上,您可以使用该密码。
要禁用该弹出窗口,只需将其添加到您的 application.properties 文件中即可。
security.basic.enabled: false
关于spring-security - 在 spring security(spring-boot 项目)中使用 ldap 凭据进行 Http 基本身份验证以保护其余服务调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24378826/