【问题标题】:Spring Boot 2 not ignoring authorization header on permitAllSpring Boot 2 不忽略 permitAll 上的授权标头
【发布时间】:2019-03-09 18:34:59
【问题描述】:

我的弹簧安全配置如下:

@EnableWebSecurity
@Order(1)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable().authorizeRequests()
      .antMatchers("/rest/app/health").permitAll()
      .antMatchers("/*/app/**").authenticated()
      .antMatchers("/**").permitAll().and().httpBasic();
  }

  @Override
  public final void configure(final WebSecurity web) throws Exception {
    super.configure(web);
    web.httpFirewall(new DefaultHttpFirewall());
  }

}

我只包含了 spring security 而不是 oauth2。由于某种原因,如果有人正在访问任何允许的 url,例如。 /rest/app/health 带有 Authorization 标头,他得到 401 Unauthorized。没有标题它工作正常。

如何忽略 Authorization 标头,因为我需要此标头作为请求参数来将我的请求委托给第三方服务。

【问题讨论】:

标签: spring spring-boot spring-security


【解决方案1】:

将对通过 HttpSecurity 配置的所有端点执行过滤器。如果您不希望将过滤器应用于某些端点,请将它们包含在配置 WebSecurity 的方法中。

你需要改变这个方法

 @Override
  public final void configure(final WebSecurity web) throws Exception {
    super.configure(web);
    web.httpFirewall(new DefaultHttpFirewall());
  }

到:

@Override
    public void configure(WebSecurity web) {
        web.ignoring()
            .antMatchers(HttpMethod.POST, "/rest/app/health");
    }

【讨论】:

    猜你喜欢
    • 2021-04-13
    • 2017-06-21
    • 2018-01-28
    • 1970-01-01
    • 2018-08-12
    • 2021-06-20
    • 1970-01-01
    • 2012-08-18
    • 2023-01-11
    相关资源
    最近更新 更多