升级到Boot 1.2后,无法访问Spring引导执行器运行状况端点



我在将Spring Boot从1.1.12升级到1.2.5时遇到麻烦,但在1.2.x的所有版本中都有相同的问题。驱动器提供的/health端点现在将401 Unauthorized返回到以前工作的集成测试。升级依赖时没有代码更改。

下面是测试用例:

@Test
public void testNoUserForStatusEndpoint() throws Exception {
    HttpEntity<String> entity = new HttpEntity<>(null, headers);
    ResponseEntity<String> response = template
            .exchange(base + "/health", HttpMethod.GET, entity, String.class);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals("{"status":"UP"}", response.getBody());
}

我希望看到基本的"UP"状态,但没有进一步的细节,因为用户是匿名的,没有经过身份验证。

设置management.security.enabled=false应用。属性使端点返回完整的运行状况信息。这是不可取的。

设置endpoints.health.sensitive=false无效。

安全配置未更改。它基于Apache终端和证书白名单,也没有改变。

@Override
public void configure(HttpSecurity http) throws Exception {
    http.csrf().disable();
    http.addFilterBefore(new CustomAuthenticationFilter(authenticationManager(), Environment.getUserWhitelist()), BasicAuthenticationFilter.class);
}

我怎样才能使考试通过?

更新:

最初application.properties中定义的唯一相关设置是endpoints.health.enabled=true

添加management.health.status.order=UP,DOWN,OUT_OF_SERVICE,UNKNOWNapplication.properties没有区别。

使用所有三个属性导致401(不工作):

endpoints.health.enabled=true
endpoints.health.sensitive=false
management.health.status.order=UP,DOWN,OUT_OF_SERVICE,UNKNOWN

主类只是一个简化的Spring Boot应用程序启动器:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

我已经尝试将http.authorizeRequests().antMatchers("/health**").permitAll();添加到上面详细介绍的安全配置方法的第一行。没有什么区别。

根据Spring Boot issue 2120, endpoints.health.sensitive属性在使用自定义安全性时被忽略。

或者添加management.security.enabled=false到application.properties

我找到一个解决办法了。

@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)添加到我的自定义身份验证过滤器(在问题中称为CustomAuthenticationFilter)更改了定义安全过滤器bean的语义。

如果没有注释,Spring Boot假设我想要覆盖所有的过滤器,并且只单独使用我的自定义过滤器。

通过注释,Spring Boot将我的过滤器添加到预定义过滤器列表中。这允许/health端点再次工作。

详细信息请参见GitHub上的Spring Boot issue 2120。

我得到404错误与/健康url。但是,它可以使用/actuator/health url而不是/health。

请在应用程序上尝试。属性或应用程序。yml: -

management.health.status.order=UP,DOWN,OUT_OF_SERVICE,UNKNOWN

最新更新