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

来源:互联网 发布:中信超市软件 编辑:程序博客网 时间:2024/05/20 20:43

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

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

@Overrideprotected 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();}


0 0
原创粉丝点击