栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Spring中使用application.properties禁用CSRF?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Spring中使用application.properties禁用CSRF?

由于

WebSecurityConfigurerAdapter
使用强制命令方法,因此您可以注入
security.enable-csrf
变量的值,并在变量为false时禁用CSRF。没错,我认为这应该可以立即使用。

@Configurationpublic class AuthConfig extends WebSecurityConfigurerAdapter {    @Autowired    private UserDetailsService userDetailsService;    @Value("${security.enable-csrf}")    private boolean csrfEnabled;    @Override    protected void configure(AuthenticationManagerBuilder auth) throws Exception {        auth.userDetailsService(userDetailsService).passwordEnprer(new BCryptPasswordEnprer());    }    @Override    protected void configure(HttpSecurity http) throws Exception {       super.configure(http);       if(!csrfEnabled)       {         http.csrf().disable();       }    }}

我所做的是,在我激活了 dev spring概要文件时,在application.yml中将该变量设置为false ,尽管您也可以为此目的创建一个名为
nosecurity 的概要文件。它大大简化了此过程:

-– application.yml-

# Production configurationserver:  port: ${server.web.port}admin.email: ${admin.email}#etc---spring:  profiles: devsecurity.enable-csrf: false#other Development configurations

我希望它能满足您的需求

2017年12月17日更新

根据Spring Boot成员的评论,此问题已在Spring的新版本中解决:我在Spring的版本中拥有此问题,

1.5.2.RELEASE
但似乎在1.5.9.RELEASE版本(版本2之前的最新稳定版本)中已修复此问题。默认情况下 csrf
是禁用的,可以使用启用
security.enable_csrf: true
。因此,可能的解决方案可能只是升级到version
1.5.9.RELEASE
,然后再将主要版本升级到版本2,而该版本的体系结构可能会大不相同。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/623927.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号