Spring Security permitall在发送授权头时拒绝访问

xwbd5t1u  于 2023-08-05  发布在  Spring
关注(0)|答案(1)|浏览(121)

我的安全配置如下:

http.authorizeRequests().antMatchers("/authenticate").fullyAuthenticated().anyRequest().permitAll().and().httpBasic();

字符串
它工作正常,但除/authenticate外的所有端点都不安全。但是当客户端将Authorization头发送到任何不安全的端点时,Spring Security将返回401

curl -s -u asdf:asdf http://127.0.0.1:22000/info
{"timestamp":1511348485989,"status":401,"error":"Unauthorized","message":"Bad credentials","path":"/info"}


我必须如何配置安全性,以忽略不安全端点上的Authorization标头**(如果发送**)?
先谢了

0md85ypi

0md85ypi1#

我通过创建WebSecurityCustomizer bean SecurityConfiguration解决了这个问题,它配置为忽略所需的模式:

@Bean
    public WebSecurityCustomizer webSecurityCustomizer() {
        return webSecurity -> webSecurity.ignoring().requestMatchers("/api/allowedPath/**");
    }

字符串

相关问题