我在將Spring Boot從1.1.12升級到1.2.5時遇到問題,但在1.2.x的所有版本中都有相同的問題。 Actuator提供的端點/health
現在將401未授權返回到曾經工作的集成測試。升級依賴關係時沒有代碼發生變化。升級到引導1.2後無法訪問Spring Boot執行器運行狀況端點
這裏的測試用例:
@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"
狀態,但沒有進一步的細節,因爲用戶是匿名的,未經過身份驗證。
在application.properties中設置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,UNKNOWN
添加到application.properties
沒有區別。
使用所有這三個屬性導致401(不工作):
endpoints.health.enabled=true
endpoints.health.sensitive=false
management.health.status.order=UP,DOWN,OUT_OF_SERVICE,UNKNOWN
主要類只是一個剝離下來的春天啓動的應用程序啓動:
@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
屬性。我在文檔中沒有發現這一點。
類似[這個問題](http://stackoverflow.com/questions/32121635/how-to-re-enable-anonymous-access-to-spring -boot-health-endpoint),但安全細節不同。 – IanGilham