Enable actuator discovery

This commit is contained in:
David Turanski
2021-10-05 14:20:55 -04:00
committed by Soby Chacko
parent dfeedf4338
commit 451d962eee
4 changed files with 18 additions and 1 deletions

View File

@@ -61,7 +61,7 @@ public class AppStarterWebFluxSecurityAutoConfiguration {
.permitAll();
}
else {
http.authorizeExchange().pathMatchers("/actuator/health", "/actuator/info", "/actuator/bindings")
http.authorizeExchange().pathMatchers("/actuator", "/actuator/health", "/actuator/info", "/actuator/bindings")
.permitAll().anyExchange().authenticated();
http.httpBasic();
http.formLogin();

View File

@@ -60,6 +60,7 @@ public class AppStarterWebSecurityAutoConfiguration {
}
if (securityProperties.isEnabled()) {
http.authorizeRequests()
.requestMatchers(EndpointRequest.toLinks()).permitAll()
.requestMatchers(EndpointRequest.to("health", "info", "bindings")).permitAll()
.requestMatchers(EndpointRequest.toAnyEndpoint()).authenticated()
.and().formLogin().and().httpBasic();

View File

@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@TestPropertySource(properties = {
"spring.main.web-application-type=reactive",
"management.endpoints.web.discovery.enabled=true",
"management.endpoints.web.exposure.include=health,info,env,bindings",
"info.name=MY TEST APP"})
public class ReactiveSecurityEnabledManagementSecurityEnabledTests extends AbstractSecurityCommonTests {
@@ -57,6 +58,13 @@ public class ReactiveSecurityEnabledManagementSecurityEnabledTests extends Abstr
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@Test
@SuppressWarnings("rawtypes")
public void testDiscoveryEndpoint() {
ResponseEntity<Map> response = this.restTemplate.getForEntity("/actuator", Map.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@Test
@SuppressWarnings("rawtypes")
public void testBindingsEndpoint() {

View File

@@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@TestPropertySource(properties = {
"spring.main.web-application-type=servlet",
"management.endpoints.web.discovery.enabled=true",
"management.endpoints.web.exposure.include=health,info,env",
"info.name=MY TEST APP"})
public class SecurityEnabledManagementSecurityEnabledTests extends AbstractSecurityCommonTests {
@@ -54,6 +55,13 @@ public class SecurityEnabledManagementSecurityEnabledTests extends AbstractSecur
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@Test
@SuppressWarnings("rawtypes")
public void testDiscoveryEndpoint() {
ResponseEntity<Map> response = this.restTemplate.getForEntity("/actuator", Map.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
// The ManagementWebSecurityAutoConfiguration exposes only Info and Health endpoint not Env!
@Test
@SuppressWarnings("rawtypes")