无法禁用csrf Spring启动

时间:2016-03-11 16:15:03

标签: java spring spring-security spring-boot

我正在开发一个Android应用程序,并且我使用Spring作为REST后端。

每次我尝试向服务器发出post请求时,都会收到403响应,并显示此消息"未找到预期的CSRF令牌。您的会话是否已过期?"。

我尝试在application.properties中使用自己的WebSecurityConfigurerAdapter实现禁用csrf,但无效。

我错过了什么吗?

2 个答案:

答案 0 :(得分:0)

试试这个:

.invalidateHttpSession(true)
.and()
.exceptionHandling()
.authenticationEntryPoint(new Http403ForbiddenEntryPoint())
.and()
.csrf()//Disabled CSRF protection
.disable();

logoutSuccessHandler(...)

上添加此内容

答案 1 :(得分:0)

有多种方法可以在Spring Boot中禁用CSRF,默认情况下在spring boot中启用

1。通过Java配置

@Override
protected void configure(HttpSecurity http) throws Exception {
   http.csrf().disable();
}

2。通过Application.yml

 security.enable-csrf: false