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

alt*_*hor 5 spring-security

我的安全配置如下:

http.authorizeRequests().antMatchers("/authenticate").fullyAuthenticated().anyRequest().permitAll().and().httpBasic();
Run Code Online (Sandbox Code Playgroud)

它适用于所有端点,但/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"}
Run Code Online (Sandbox Code Playgroud)

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

提前致谢

小智 2

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

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