解決在項目裏引入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();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章