【发布时间】:2016-10-26 12:29:46
【问题描述】:
我正在使用 Spring Security 和 java 配置
@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 token”,并且可以在请求标头中使用X-CSRF-TOKEN 登录。但是登录后,当我点击发布请求时(我在请求标头中包含了用于登录发布请求的相同令牌)我收到以下错误消息:
HTTP 状态 403 - 无法验证提供的 CSRF 令牌,因为找不到您的会话。
谁能指导我做错了什么。
【问题讨论】:
标签: java spring-security csrf spring-restcontroller