出現這個問題的原因是因為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();}
新聞熱點
疑難解答