试读部分
问题场景 在使用 SpringSecurity 时对一些访问权限进行了设置, 在用户请求资源时出现了403错误 , 通过检查代码发现请求权限是开放的, 并且切换成 GET 请求也是可以通过, 换成POST 请求就无法通过。 解决方法 在 SpringSecurity 中关闭 CSRF 因为 前端向后台发送 post 请求时,必须验证 csrf,否则会报错 403 Forbidden。 @Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
// CSRF禁用,因为不使用session
.csrf().disable()
.antMatchers(
HttpMethod.GET,
"/",
"/*.html",
"/**/*.html",
"/**/*.css",
"/**/*.js",
"/profile/**"
).permitAll()
// activiti modeler 放行
.antMatchers("/modeler/**").anonymous()
……
本文为 VIP 文章,已展示部分内容,
开通 VIP 后查看全文
觉得这篇文章有帮助?
点个赞,或赞赏支持作者持续创作