我有一个正在工作的Spring Boot应用程序,其中启用了csrf,但现在我想仅针对本地主机禁用它。任何来自其他域的请求都必须绕过csrf安全性,但是对于本地主机,我想禁用它。怎样才能实现呢?
我知道如何通过更改以下内容来禁用它:
@Configuration
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf.disable();
}
}
上面的代码禁用了csrf,但我只想禁用localhost的csrf。
你能帮我吗?
编辑:我知道如何通过两个配置文件来实现。感谢@daren提供的详细答案。