【问题标题】:Spring Web Security Config - Ignore CSRF Validation for either orSpring Web Security Config - 忽略 CSRF 验证
【发布时间】:2020-07-15 08:31:48
【问题描述】:

我有某些条件可以忽略 csrf 验证,但我不确定如何将其放入配置中。以下是我忽略验证的条件:

  • 在授权中有一个Bearer 令牌。

或者

  • 特定网址

这是我现在的配置:

security.csrf().ignoringRequestMatchers(new RequestHeaderRequestMatcher("Authorization")).ignoringAntMatchers("/test").and();

但是有了这个配置,我猜它把它当作一个 AND 操作或其他东西。我该如何更改?

【问题讨论】:

    标签: spring csrf


    【解决方案1】:

    试试OrRequestMatcher.

    security.csrf()
           .ignoringRequestMatchers(new OrRequestMatcher(new RequestHeaderRequestMatcher("Authorization"), new AntPathRequestMatcher("/test"))); 
    

    【讨论】:

      猜你喜欢
      • 2014-03-11
      • 2014-03-18
      • 2018-06-22
      • 2017-09-16
      • 2016-09-10
      • 2015-12-18
      • 1970-01-01
      • 2015-07-09
      • 1970-01-01
      相关资源
      最近更新 更多