如何禁用执行器安全性而不使用 Spring Boot 2 完全禁用它

sol*_*nmv 4 spring spring-security spring-boot spring-security-oauth2 spring-boot-actuator

我正在使用带有 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.
Run Code Online (Sandbox Code Playgroud)

此外,我试图为我自己的安全配置明确设置更高的顺序,但看起来自动配置的一个覆盖了我的。

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

And*_*lko 8

@Configuration
@EnableOAuth2Sso
class MyConfiguration extends WebSecurityConfigurerAdapter {

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

}
Run Code Online (Sandbox Code Playgroud)

确保您在课堂@EnableOAuth2Sso上使用WebSecurityConfigurerAdapter。这很重要,因为它将包括OAuth2SsoCustomConfiguration基本上复制OAuth2SsoDefaultConfiguration#configure.

您可能还想显示完整的健康详细信息:

management:
  endpoint:
    health:
      show-details: always
Run Code Online (Sandbox Code Playgroud)


Ale*_*rov 7

您需要在您的

@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();

    }
}
Run Code Online (Sandbox Code Playgroud)