博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot + SpringSecurity解决POST DELETE方式下的被拒绝访问 报错403的问题 (关闭CSRF)
阅读量:4048 次
发布时间:2019-05-25

本文共 798 字,大约阅读时间需要 2 分钟。

SpringBoot中配置了SSL之后,发现除了小程序访问后台的GET方法, 其余POST,DELETE都被拒绝,并且报错403.

找了好久原来是因为在Security的默认拦截器里,默认会开启CSRF处理,判断请求是否携带了token。

如果没有就拒绝访问。并且,在请求为(GET|HEAD|TRACE|OPTIONS)时,则不会开启。

解决

既然是因为默认开启了CSRF,那关掉即可。可以加入以下代码关闭~

import org.springframework.context.annotation.Configuration;import org.springframework.security.config.annotation.web.builders.HttpSecurity;import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;@Configuration@EnableWebSecuritypublic class SecurityConfigSEVEN extends WebSecurityConfigurerAdapter {    @Override    protected void configure(HttpSecurity http) throws Exception {        //super.configure(http);         http.csrf().disable();  //关闭CSRF    }}

 

转载地址:http://zizci.baihongyu.com/

你可能感兴趣的文章
javascript传参字符串 与引号的嵌套调用
查看>>
swiper插件的的使用
查看>>
layui插件的使用
查看>>
JS牛客网编译环境的使用
查看>>
9、VUE面经
查看>>
关于进制转换的具体实现代码
查看>>
Golang 数据可视化利器 go-echarts ,实际使用
查看>>
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>
dba 常用查询
查看>>
Oracle 异机恢复
查看>>
Oracle 12C DG 搭建(RAC-RAC/RAC-单机)
查看>>
Truncate 表之恢复
查看>>
Oracle DG failover 后恢复
查看>>
mysql 主从同步配置
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
mongdb安装使用
查看>>
mongdb在java中的应用
查看>>
区块链技术让Yotta企业云盘为行政事业服务助力
查看>>