首页 文章

在spring security(spring-boot项目)中使用ldap凭证进行Http基本身份验证,以保护休息服务调用

提问于
浏览
2

使用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 回答

  • 2

    这是由于您已设置的httpbasic身份验证 . Spring启动会生成一个随机密码,显示在您可以使用的控制台上 .

    要禁用该弹出窗口,只需将其添加到application.properties文件即可 .

    security.basic.enabled: false
    

相关问题