使用Spring Security Basic身份验证设置可以对付一些硬编码的用户名密码,如下所示:
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)];即使凭据是正确的错误链接到一些教程将非常有帮助
1 回答
这是由于您已设置的httpbasic身份验证 . Spring启动会生成一个随机密码,显示在您可以使用的控制台上 .
要禁用该弹出窗口,只需将其添加到application.properties文件即可 .