我正在尝试禁用特定 url 的 Csrf。这是我到目前为止所做的:
public HttpSessionCsrfTokenRepository csrfTokenRepository() {
final HttpSessionCsrfTokenRepository tokenRepository = new HttpSessionCsrfTokenRepository();
tokenRepository.setHeaderName("X-XSRF-TOKEN");
return tokenRepository;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
RequestMatcher matcher = request -> !("//j_spring_cas_security_check".equals(request.getRequestURI()));
http.csrf()
.requireCsrfProtectionMatcher(matcher)
.csrfTokenRepository(csrfTokenRepository());
Run Code Online (Sandbox Code Playgroud)
如果我requireCsrfProtectionMatcher
在所有匹配器中注释掉或简单地返回 false 将不会有错误,但是使用此配置它会给我:
HTTP Status 403 - Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-XSRF-TOKEN'.
Run Code Online (Sandbox Code Playgroud)
我需要禁用 csrf,j_spring_cas_security_check
以便单点注销工作并tokenRepository
使用 angularjs。有什么我想念的吗?