【问题标题】:Exception in Spring Boot when changing configuration of X-Frame-Options to ALLOW-FROM将 X-Frame-Options 的配置更改为 ALLOW-FROM 时 Spring Boot 中的异常
【发布时间】:2018-05-13 16:43:07
【问题描述】:

我在一个使用 Spring Boot 的项目中工作了一段时间,现在,作为一项要求,我正在使用一些需要渲染的 html 文件,其中一个使用 iframe 来显示另一个网页(来自同一公司的另一个业务部门,但在不同的域中)。

到目前为止,我在 SpringConfiguration 中所做的如下:

@EnableWebSecurity
@Configuration
public class MyApplicationConfiguration extends WebSecurityConfigurerAdapter {

    @Value("${company.domain}")
    private String companyDomain;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.headers().frameOptions().disable().addHeaderWriter(new XFrameOptionsHeaderWriter(new StaticAllowFromStrategy(URI.create(this.companyDomain))));
    }
}

根据我在互联网和论坛上检查的内容,它应该可以正常工作,但没有提及以下内容:

Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: @Order on WebSecurityConfigurers must be unique. Order of 100 was already used on com.sampleapp.myapp.ecards.MyApplicationConfiguration$$EnhancerBySpringCGLIB$$24364a75@13ecedf6, so it cannot be used on com.sampleapp.dep.dsp.core.autoconfigure.DsfCoreAutoConfiguration$DSFServerWebSecurityConfig$$EnhancerBySpringCGLIB$$a540fd8@7ec416a0 too.

顺便提一下,我看到解决方案是在我的项目上下文中删除@Order 注释,但我的项目中没有任何@Order 注释。此外,这家公司的项目是使用一些预定义的 maven 原型创建的,这些原型将为所有软件组件创建自定义文件夹结构以及创建具有所有必需依赖项的 pom.xml(必须使用这些依赖项,所以我不能删除它们中的任何一个,只需添加)。此外,我无法编辑或删除用作项目依赖项的组件上的注释。

您会推荐什么其他解决方案?或者是否有任何解决方法可以解决此问题?

提前感谢您的时间和帮助。

【问题讨论】:

    标签: java spring-boot iframe spring-security x-frame-options


    【解决方案1】:

    WebSecurityConfigurer 适配器的默认顺序是 100,您的应用程序中似乎有两个:

    • com.sampleapp.myapp.ecards.MyApplicationConfiguration
    • com.sampleapp.dep.dsp.core.autoconfigure.DsfCoreAutoConfiguration$DSFServerWebSecurityConfig

    您应该更新其中一个以使用@Order 显式注释,指定一个非100 的值。鉴于您描述的限制,将@Order 添加到com.sampleapp.myapp.ecards.MyApplicationConfiguration 似乎更有可能是好的。它的顺序应该更高还是更低将取决于您的安全配置的不同部分之间的关​​系,如果该配置重叠,您希望哪个优先。

    【讨论】:

      猜你喜欢
      • 2019-03-25
      • 2012-04-29
      • 2016-12-09
      • 2015-08-24
      • 1970-01-01
      • 2019-03-07
      • 1970-01-01
      • 2017-08-02
      • 2012-05-26
      相关资源
      最近更新 更多