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

标签 spring-security ldap basic-authentication spring-boot

使用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/

相关文章:

spring-boot - EmbeddedServletContainerCustomizer(spring 2和spring boot 2)更改为WebServerFactoryCustomizer(spring 5和spring boot 2)

java - 无法将 String 类型的值转换为 MethodSecurityMetadataSource (Spring 3.1)

active-directory - 如何在两个 FreeIPA 服务器之间配置信任?

javascript - Restify 静态网络服务器在启用 HTTP 基本身份验证后停止工作

security - 使用类似密码的单个 htpasswd 保护开发 Grails 应用程序

spring - Maven : Spring 4 + Spring Security

java - security.oauth2.resource.jwt.key-value 的编码

active-directory - 尝试使用 userPrincipalName 连接时出现 LDAPException

security - 如何在 Jenkins 中创建用户并将其添加到组中进行身份验证?

java - 如果使用基本身份验证,Applet 会显示登录对话框