spring-boot - 没有 WebSecurityConfigurerAdapter 和两个 AuthenticationProvider 的 Spring Security

标签 spring-boot spring-security

我有两个 AuthenticationProviders ,并且不知道如何将其转换为 Spring Security 的新方式。 这就是我所说的“新方式”https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter

目前我正在扩展 WebSecurityConfigurerAdapter 并具有以下配置:

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.authenticationProvider(inMemoryAuthenticationProvider);
    auth.authenticationProvider(ldapAuthenticationProvider);

    auth.userDetailsService(userDetailsService);
}

在不扩展 WebSecurityConfigurerAdapter 的情况下,配置必须是什么样子?

最佳答案

我通过使用@Elyobek建议的filterChain解决了这个问题,但使用了以下代码:

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http.authenticationProvider(inMemoryAuthenticationProvider);
    http.authenticationProvider(ldapAuthenticationProvider);
    http.userDetailsService(userDetailsService);
}

我没有意识到我可以在 HttpSecurity 上设置 AuthenticationProvidersUserDetailsS​​ervice

关于spring-boot - 没有 WebSecurityConfigurerAdapter 和两个 AuthenticationProvider 的 Spring Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74094096/

相关文章:

redis 的 spring-boot 安全共享 session

java - 使用 Spring Security 的条件权限实现会是什么样子?

grails - 在Grails中显示Spring Security类的属性

java - Spring Boot 和 Spring Batch 在 ItemProcessor 批处理的 DAO 中抛出 NullPointerException

java - 无法从 WAS Liberty 服务器中部署的 Spring boot 应用程序访问 JNDI Url 上下文

java - Spring Boot 白标 404

java - "org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation"生成 xml 响应

Grails Spring安全登录问题:/auth? login_error=1

kotlin - 为什么在Kotlin异步方法中SecurityContextHolder.getContext()。authentication等于null?

Spring 安全 : What is the right way to call method secured with @PreAuthorize in background task?