为Spring Boot 2.0仿真器框架配置安全性 [英] Configure security for Spring Boot 2.0 acuator framework

查看:20
本文介绍了为Spring Boot 2.0仿真器框架配置安全性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Spring Boot 2.0应用程序中使用Spring Actuator框架。框架本身按照预期工作,因此我能够到达例如我的/actuator/health终结点。在那里,我呈现了一个登录对话框。我想摆脱它,并尝试了以下方法:

@Configuration
@EnableWebFluxSecurity
public class SecurityConfiguration {

  @Bean
  public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {

    return http
               .authorizeExchange()
                   .matchers(EndpointRequest.to("prometheus")).permitAll()
                   .matchers(EndpointRequest.toAnyEndpoint()).authenticated()
                   .anyExchange().permitAll()
                   .and()
               .formLogin()
                  .and()
               .httpBasic()
                  .and()
               .build();
  }

但是,在应用程序启动期间,我收到以下错误:

未能实例化[org.springframework.security.web.server.SecurityWebFilterChain]:工厂方法‘securityWebFilterChain’引发异常;嵌套异常为java.lang.IlLegalArgumentException:身份验证管理器不能为空

当然,我试图搜索它,但我总是只能得到描述使用Spring Boot 1.x框架的不同场景或安全配置的页面。有人能帮我一下吗?

推荐答案

最简单的方法应该是让SecurityConfiguration扩展WebSecurityConfigurerAdapter并覆盖configure(WebSecurity web),如下所示:

public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring()
                .antMatchers("/actuator/**");
    }

    // ...

}

另外,我不熟悉@EnableWebFluxSecurity,但要使上面的内容正常工作,您需要同时使用@Configuration@EnableWebSecurity注释。

至于设置配置的方式,它实际上并不是最优的。为了补充上述建议,您应该使用HttpSecurity配置安全性,而不是使用当前的SecurityWebFilterChain

这篇关于为Spring Boot 2.0仿真器框架配置安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆