【问题标题】:Whitelisting '/' endpoint not working on Spring Security 6白名单 \'/\' 端点不适用于 Spring Security 6
【发布时间】:2022-12-05 20:10:58
【问题描述】:

我正在学习有关 Spring Security 的课程,并且我试图让它在最新的 Spring Security 6 上工作。我正在尝试使用基本身份验证将 localhost:8080/ 从身份验证中列入白名单。但是当我访问 url 时,它仍然要求我提供凭据。

目前我有这个豆:

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

    return http
            .authorizeHttpRequests(auth -> {
                        auth.requestMatchers("/").permitAll();
                        auth.requestMatchers("index").permitAll();
                        auth.requestMatchers("/css/*").permitAll();
                        auth.requestMatchers("js/*").permitAll();
                        auth.anyRequest().authenticated();
                    }
            )
            .httpBasic(withDefaults()).build();

}

但是默认的“/”端点仍然没有列入白名单。

【问题讨论】:

    标签: authentication spring-security spring-boot-3


    【解决方案1】:

    如果您在课堂上使用@EnableWebSecurity而不使用@Configuration,那么现在使用 Spring Security 6 时,你应该添加@Configuration一个因为@EnableWebSecurity不再包含@Configuration

    春季安全 6

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE)
    @Documented
    @Import({ WebSecurityConfiguration.class, SpringWebMvcImportSelector.class, OAuth2ImportSelector.class,
            HttpSecurityConfiguration.class })
    @EnableGlobalAuthentication
    public @interface EnableWebSecurity {
    

    【讨论】:

      猜你喜欢
      • 2019-03-08
      • 2020-07-26
      • 2022-11-17
      • 1970-01-01
      • 2020-04-13
      • 2021-03-25
      • 2017-06-29
      • 1970-01-01
      • 2015-11-03
      相关资源
      最近更新 更多