如何使用Spring Boot 2在不完全禁用执行器安全的情况下禁用它 [英] How to disable actuator security without disabling it totally with Spring Boot 2

查看:32
本文介绍了如何使用Spring Boot 2在不完全禁用执行器安全的情况下禁用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OAuth2中使用了Spring Boot Security。我不想禁用健康终结点的安全性。

我可以完全禁用安全性,也可以编写我自己的WebSecurityConfigurerAdapter实现并禁用自动配置的实现。

但如何修改WebSecurityConfigurerAdapter(OAuth2SsoDefaultConfiguration)的现有实现?

我尝试在不禁用自动配置的情况下创建自己的配置,但由于Order冲突而无法创建。

以下是错误消息:

Caused by: java.lang.IllegalStateException: @Order on WebSecurityConfigurers must be unique. 
Order of 100 was already used on SecurityConfiguration$$EnhancerBySpringCGLIB$$9505fc58@13f182b9,
 so it cannot be used on 
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2SsoDefaultConfiguration$$EnhancerBySpringCGLIB$$dc290e2b@5ee0cf64 too.

此外,我还尝试为我自己的安全配置显式设置更高的顺序,但看起来自动配置的安全配置覆盖了我的。

那么如何在不重新实现整个配置的情况下覆盖特定的安全规则?

推荐答案

您需要在您的

@SpringBootApplication

 @SpringBootApplication
 @EnableResourceServer
 @EnableGlobalMethodSecurity(prePostEnabled = true)
 @Configuration
 public class BusinessLogicServiceApplication extends ResourceServerConfigurerAdapter {

 public static void main(String[] args) throws IOException {
    ConfigurableApplicationContext context =  
    SpringApplication.run(BusinessLogicServiceApplication.class, args);
    }

  @Override
  public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .antMatchers("/health").permitAll().anyRequest().authenticated();

    }
}

这篇关于如何使用Spring Boot 2在不完全禁用执行器安全的情况下禁用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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