【问题标题】:Spring boot, how to disable autoconfiguration of springSecurityFitlerChainSpring Boot,如何禁用 springSecurityFitlerChain 的自动配置
【发布时间】:2017-05-12 13:16:32
【问题描述】:

我正在使用 Spring Boot 研究 Spring Security 框架,我不喜欢 boot 的一件事是它晦涩难懂。发生了很多神奇的事情,故障排除和定制是反复试验,猜测自动配置的内容和位置。这是安全领域的高风险,因为配置错误的系统可能会受到损害。

我想用我自己的实现替换springSecurityFilterChain。在 vanilla Spring 中,我会在 web.xml 中使用不同的名称注册 DelegatingFilterProxy,并实现相应的 bean。但是,如果 jars 存在,Spring boot 显然会自动注册springSecurityFilterChain,现在我不确定自动配置是否会通过以传统方式声明springSecurityFilterChain 来恢复,还是会导致系统配置错误?

一般来说,我想更好地了解 Spring boot,而不仅仅是猜测发生了什么、在哪里以及如何控制该区域。

【问题讨论】:

    标签: java spring spring-boot spring-security configuration


    【解决方案1】:

    有很多预配置的东西,但您可以覆盖每一步。 @EnableAutoConfiguration 的神奇之处在于方便。 --debug 开关应该会告诉您更多后台发生的事情。

    http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html

    【讨论】:

      【解决方案2】:

      如果您使用 Spring Boot 1.4.x(我不确定以前的版本),以下其中一项可以工作。

      @EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration.class})
      

      或

      @SpringBootApplication(exclude = { org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration.class})
      

      或

      在您的 application.properties 文件中,

      spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration

      有时您可能还需要排除 org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration 类。

      【讨论】:

      • 仍在自动配置。现在我担心,如果 EnableWebSecurity 注释的存在注册了安全过滤器。但是话又说回来,为什么我们需要在 vanilla spring 中使用 AbstractSecurityWebApplicationInitializer,因为 @EnableWebSecurity 已经存在。它与嵌入式 servlet 容器有关吗?
      【解决方案3】:

      您真的要禁用整个安全链吗?我没有看到用例,但如果你根本不需要@EnableWebSecurity。如果您只想调整链,请创建一个带有 @Configuration 和 @EnableWebSecurity 注释的类,它正在扩展 WebSecurityConfigurerAdapter。在那里,您可以通过覆盖 configure(HttpSecurity) 来判断谁可以做什么。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-12
        • 2015-04-29
        • 1970-01-01
        • 1970-01-01
        • 2022-01-21
        • 2017-01-16
        • 2016-01-21
        • 2019-10-21
        相关资源
        最近更新 更多