首页 > 解决方案 > SpringBoot:只允许特定网站上我的应用的某些页面在Iframe中

问题描述

我正在使用带有 spring security 和 thymleaf 的 jdk8、springboot(v2.0.3)。我想在 iframe 中的特定网站上允许我的一些应用程序页面。

 http
            .headers()
            .frameOptions().disable()
            .and()
            .csrf().disable()/*disbaling csrf here*/
            .authorizeRequests()
            .antMatchers("/","/login","/css/**", "/js/**", "/fonts/**","/img/**").permitAll()/*do not use spring security on this path*/
            .and()
            .formLogin()
            .successHandler(successHandler) /*after success login on web we are handling the success event*/
            .permitAll()
            .and()
            .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login/?logout") /*defining logout and login url here*/
            .permitAll()

以上是我正在使用的示例代码。现在它已禁用 iframe。我希望它为特定网站启用,例如 https://abc.yxv.com、https://bac.xyz.com 等。

我在某些地方读到 x-frame-options 现在已弃用或不是一个好方法,因为它不支持现代浏览器。请帮助我。什么是这样做的好方法和代码示例

谢谢

标签: javaspring-bootspring-security

解决方案


推荐阅读