0
我正试图在Spring Security项目的Spring Boot项目中为特定URL禁用或设置XFrameOptions标头为SAME_ORIGIN。我粘贴下面的代码,为URL禁用X-FrameOptions响应标题Spring Security JAVA配置
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
RequestMatcher matcher = new AntPathRequestMatcher("**/course/embed/**");
DelegatingRequestMatcherHeaderWriter headerWriter =
new DelegatingRequestMatcherHeaderWriter(matcher,new XFrameOptionsHeaderWriter());
http.headers()
.frameOptions().sameOrigin()
.addHeaderWriter(headerWriter);
}
}
我使用AntRequestMatcher但不起作用,它,而不是禁用XFrameOptions头所有响应。有一个更好的方法吗?请帮忙。
谢谢,我试了多个WebSecurityConfigurerAdapter。当“/ course/embed”被调用时,我得到这个错误“拒绝在一个框架中显示'https:// localhost/modern/course/embed/33510',因为它将'X-Frame-Options'设置为'DENY'” 。所以antMatcher仍然不符合模式。我错过了什么吗? – arjary
如果你的网址是/ course/embed,那么pattern应该设置为/ course/embed * – mhshimul
对不起,我错过了你的完整url路径。尝试用这个/ ** /当然/嵌入/ ** – mhshimul