【问题标题】:@ManagementContextConfiguration usage with WebSecurityConfigurerAdapter doesn't work@ManagementContextConfiguration 与 WebSecurityConfigurerAdapter 一起使用不起作用
【发布时间】:2019-08-04 11:39:34
【问题描述】:

我有一个工作的 Spring Boot 1.x 应用程序,配置了不同的管理端口和安全性(基本身份验证)。 迁移到 Spring 2.1 后,它不再工作了。

查看代码:

@ManagementContextConfiguration 公共类 ManagementConfig {

@EnableWebSecurity
@Order(SecurityProperties.BASIC_AUTH_ORDER)
static class SecurityConfig extends WebSecurityConfigurerAdapter {

  public SecurityConfig() {
    super(true);  // disable defaults
  }

  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
        auth.inMemoryAuthentication()
          .withUser("admin")
          .password(encoder.encode("admin"))
          .roles(Collections.emptyList().toArray(new String[]{}));
  }

  @Override
  protected void configure(HttpSecurity http) throws Exception {
      RequestMatcher matcher = new AntPathRequestMatcher("/**");

      http
        .authorizeRequests()
          .requestMatchers(matcher).authenticated();
    }
  }
}

我的 spring.factories 包含

org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=\
  com.test.config.ManagementConfig

在乞求期间,我可以看到创建了 SecurityConfig 实例,但没有调用 configure() 方法(如我所见,在创建 ManagementConfig 之后,Spring Boot 1.x 中有一个后处理器调用......)。

我的 application.yml 包含:

management.server:
  address: localhost
  port: 18543
  security: 
    enabled: true

问题在于,我现在可以通过简单的方式访问任何管理端点

curl http://localhost:18543/info

【问题讨论】:

    标签: spring-security spring-boot-actuator


    【解决方案1】:

    我已经通过分离解决了这个问题 @ManagementContextConfiguration 和 @EnableWebSecurity 到 2 个不同的文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多