Spring Web 安全配置 - 忽略 CSRF 验证

Spring Web Security Config - Ignore CSRF Validation for either or

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

或者

这是我现在的配置:

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

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

试试OrRequestMatcher.

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