用于CSRF的Spring Boot Security XML与WebSecurityConfigurerAdapter

问题描述 投票:1回答:1

我正在将Spring应用程序迁移到Spring Boot。

我有一个广泛的security.xml文件,它将我的所有控制器代码映射到不同的身份验证提供程序。

我知道我可以创建一个WebSecurityConfigurerAdapter并将它们转换为代码,但是,它在短期内是不可能的。

我可以使用security.xmlImportResource工作但我的所有控制器返回一个CSRF Error

我尝试创建一个类:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

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

和Spring Boot应用程序

@ImportResource(locations = {"classpath:security.xml"})
public class MyApplication extends SpringBootServletInitializer

现在,当我删除ImportResource时,WebSecurityConfig中的CSRF禁用工作,但如果我有它不起作用。

我尝试在我的xml文件中添加csrf disabled = true标签下的<http>标签,但它不起作用。

有什么方法可以使用XML在Spring Boot中禁用CSRF,或者以某种方式让它同时考虑XML和WebSecurityConfigurerAdapter类?

java spring spring-boot spring-security
1个回答
0
投票

您可以尝试添加标记

[sec:csrf disabled="true"][/sec:csrf]

在你的xml配置中

© www.soinside.com 2019 - 2024. All rights reserved.