我正在将Spring应用程序迁移到Spring Boot。
我有一个广泛的security.xml文件,它将我的所有控制器代码映射到不同的身份验证提供程序。
我知道我可以创建一个WebSecurityConfigurerAdapter
并将它们转换为代码,但是,它在短期内是不可能的。
我可以使用security.xml
与ImportResource
工作但我的所有控制器返回一个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
类?
您可以尝试添加标记
[sec:csrf disabled="true"][/sec:csrf]
在你的xml配置中