解决在项目里引入Spring Security后iframe或者frame所引用的页无法显示的问题

#出现这个问题的原因是因为Spring Security默认将header response里的X-Frame-Options属性设置为DENY。

如果页面里有需要通过iframe/frame引用的页面,需要配置Spring Security允许iframe frame加载同源的资源,方法为在Spring Security的配置类里将header response的X-Frame-Options属性设置为SAMEORIGIN,具体可以参考如下代码:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
	.authorizeRequests()
	.antMatchers("/res/**", "/admin", "/thirdparty/**", "/auth/login").permitAll()
	.antMatchers("/admin/**").hasAuthority("admin:index")
	.anyRequest().authenticated()
	.and()
	.formLogin().loginPage("/admin").permitAll()
	.and()
	.logout().logoutUrl("/admin/logout").logoutSuccessUrl("/admin").invalidateHttpSession(true)
	.and()
	.csrf().disable()
	.headers().frameOptions().sameOrigin();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章