我正在开发一个Android应用程序,并且我使用Spring作为REST后端。
每次我尝试向服务器发出post请求时,都会收到403响应,并显示此消息"未找到预期的CSRF令牌。您的会话是否已过期?"。
我尝试在application.properties中使用自己的WebSecurityConfigurerAdapter
实现禁用csrf,但无效。
我错过了什么吗?
答案 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