相关疑难解决方法(0)

scpting 安全 requireCsrfProtectionMatcher 与 csrfTokenRepository

我正在尝试禁用特定 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。有什么我想念的吗?

cas csrf spring-security

1
推荐指数
1
解决办法
2942
查看次数

标签 统计

cas ×1

csrf ×1

spring-security ×1