#出現這個問題的原因是因爲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();
}