【问题标题】:Spring web security: is @EnableWebSecurity obsolete?Spring web security:@EnableWebSecurity 过时了吗?
【发布时间】:2016-07-20 02:13:33
【问题描述】:

在使用 spring-boot-starter-security:1.3.3:RELEASE 使用简单的 Web 应用程序测试 Spring Boot (1.3.3) 时,我观察到以下行为:

为了覆盖默认的 Spring web 安全配置,我提供了一个自定义的 Java 配置类,如下所示:

@Configuration
// @EnableWebSecurity apparently obsolete ?
public class SecurityConfig extends WebSecurityConfigurerAdapter {


  @Override
  protected void configure(HttpSecurity http) throws Exception {
      // http security checking left out for brevity ...
  }


  @Override
  protected void configure(
              AuthenticationManagerBuilder auth) throws Exception {
      // user authentication left out for brevity ...
  }

}

启动后,应用程序重定向到登录页面并正确检查用户名/密码是否提供了@EnableWebSecurity 注释(如上例所示)。因此,此上下文中的此注释是否已过时?如果是这样,为什么?

【问题讨论】:

    标签: spring-security spring-boot


    【解决方案1】:

    Spring Boot 的自动配置会自动启用 web 安全性,并在满足某些条件时检索所有 WebSecurityConfigurerAdapter 类型的 bean 以自定义配置(类路径上的spring-boot-starter-security 等)。在 org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration 类中启用了网络安全的自动配置(Spring Boot 1.2.7,新版本中类名可能已更改)。

    【讨论】:

      猜你喜欢
      • 2017-10-28
      • 2020-07-20
      • 1970-01-01
      • 2018-02-19
      • 2023-03-19
      • 2013-10-12
      • 1970-01-01
      • 2017-11-24
      • 2016-09-10
      相关资源
      最近更新 更多