在spring boot项目中出现不能加载iframe
页面报一个"Refused to display ‘http://......‘ in a frame because it set ‘X-Frame-Options‘ to ‘DENY‘. "错误
解决方式:
因spring Boot采取的java config,在配置spring security的位置添加:
#解决frame 不能使用
http.headers().frameOptions().disable();
http.authorizeRequests()
// 不进行权限验证的请求或资源(从配置文件中读取)
.antMatchers(this.antMatchers.split(",")).permitAll()
// .antMatchers("/*").permitAll()
// .antMatchers("/login/**").permitAll()
/**
*Filter拦截请求两次的问题
跨域的post的请求会验证两次,get不会。网上的解释是,post请求第一次是预检请求,Request Method: OPTIONS。
解决方法:
在webSecurityConfig里添加
*/
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
// 其他的需要登陆后才能访问
.anyRequest().authenticated()
.and()
// 配置未登录自定义处理类
.httpBasic().authenticationEntryPoint(userAuthenticationEntryPointHandler)
.and()