我正在使用 spring security 和 java config
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api/*").hasRole("ADMIN")
.and()
.addFilterAfter(new CsrfTokenResponseHeaderBindingFilter(), CsrfFilter.class)
.exceptionHandling()
.authenticationEntryPoint(restAuthenticationEntryPoint)
.and()
.formLogin()
.successHandler(authenticationSuccessHandler)
.failureHandler(new SimpleUrlAuthenticationFailureHandler());
我正在使用 PostMan 来测试我的 REST 服务。我成功获得“csrf 令牌”,并且能够在请求标头中使用 X-CSRF-TOKEN
登录。但是在我点击发布请求时登录后(我在用于登录发布请求的请求标头中包含相同的令牌)我收到以下错误消息:
HTTP 状态 403 - 无法验证提供的 CSRF 令牌,因为未找到您的会话。
谁能指导我做错了什么。
原文由 Haseeb Wali 发布,翻译遵循 CC BY-SA 4.0 许可协议
根据 spring.io:
所以要禁用它:
注意: Java 配置默认启用 CSRF 保护