Java 为什么使用spring security和angular获取_CSRFNULL错误
我得到一个类似这样的错误:Java 为什么使用spring security和angular获取_CSRFNULL错误,java,angular,spring-boot,csrf,x-xsrf-token,Java,Angular,Spring Boot,Csrf,X Xsrf Token,我得到一个类似这样的错误: {timestamp: 1536511109166, status: 403, error: "Forbidden",…} error : "Forbidden" message : "Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'." path : "/vendors/1" status : 403 timestamp : 15
{timestamp: 1536511109166, status: 403, error: "Forbidden",…}
error
:
"Forbidden"
message
:
"Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'."
path
:
"/vendors/1"
status
:
403
timestamp
:
1536511109166
spring安全项目使用zuul代理
zuul:
routes:
resource:
path: /resource/**
url: http://localhost:9000
sensitive-headers:
spring security为spring security设置了以下配置,以便可以使用csrf令牌repo
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.httpBasic().and()
.logout().and()
.authorizeRequests()
.antMatchers("/index.html", "/", "/home", "/login", "/vendors", "/table").permitAll()
.anyRequest().authenticated()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
// @formatter:on
}
我在get请求上没有收到任何错误,但只有post和delete请求因此错误而失败。我还在代理和资源上使用spring会话服务器作为redis
项目位置示例:
https://github.com/nishantlakhara/proxy
在尝试了各种方法之后,当我添加http.csrf().csrfTokenRepository(CookiesRftokenRepository.WithTpOnlyFalse())时,它起到了作用;也可以连接到资源服务器。