x-frame-options
出现的问题
夸子系统访问其他子系统的界面(用iframe嵌套,子系统间有一键登录),用iframe嵌套访问springboot项目的中的某个界面时报Refused to display ‘’ in a frame because it set ‘X-Frame-Options’ to ‘sameorigin’.。
出现问题的原因
这是因不支持iframe嵌入, 这个主要是因为spring boot默认为了安全, 默认不让网页支持嵌入, 帮助用户对抗点击劫持。
解决办法
X-Frame-Options 有三个值:
DENY
表示该页面不允许在 frame 中展示,即便是在相同域名的页面中嵌套也不允许。
SAMEORIGIN
表示该页面可以在相同域名页面的 frame 中展示。
ALLOW-FROM uri
表示该页面可以在指定来源的 frame 中展示。
spring boot支持EnableWebSecurity 这个anotation来设置不全的安全策略。 具体如下:
import com.alibaba.spring.websecurity.DefaultWebSecurityConfigurer;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.