Skip to content

Commit e19c624

Browse files
committed
Consider endpoints.sensitive when endpoints.health.sensitive is not set
Closes gh-7476
1 parent 1f82819 commit e19c624

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
5959

6060
private Map<String, HttpStatus> statusMapping = new HashMap<String, HttpStatus>();
6161

62-
private RelaxedPropertyResolver propertyResolver;
62+
private RelaxedPropertyResolver healthPropertyResolver;
63+
64+
private RelaxedPropertyResolver endpointPropertyResolver;
6365

6466
private RelaxedPropertyResolver roleResolver;
6567

@@ -84,8 +86,10 @@ private void setupDefaultStatusMapping() {
8486

8587
@Override
8688
public void setEnvironment(Environment environment) {
87-
this.propertyResolver = new RelaxedPropertyResolver(environment,
89+
this.healthPropertyResolver = new RelaxedPropertyResolver(environment,
8890
"endpoints.health.");
91+
this.endpointPropertyResolver = new RelaxedPropertyResolver(environment,
92+
"endpoints.");
8993
this.roleResolver = new RelaxedPropertyResolver(environment,
9094
"management.security.");
9195
}
@@ -209,7 +213,12 @@ private boolean isSpringSecurityAuthentication(Principal principal) {
209213
}
210214

211215
private boolean isUnrestricted() {
212-
Boolean sensitive = this.propertyResolver.getProperty("sensitive", Boolean.class);
216+
Boolean sensitive = this.healthPropertyResolver.getProperty("sensitive",
217+
Boolean.class);
218+
if (sensitive == null) {
219+
sensitive = this.endpointPropertyResolver.getProperty("sensitive",
220+
Boolean.class);
221+
}
213222
return !this.secure && !Boolean.TRUE.equals(sensitive);
214223
}
215224

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.boot.actuate.endpoint.HealthEndpoint;
2525
import org.springframework.boot.actuate.health.Health;
2626
import org.springframework.boot.actuate.health.Status;
27+
import org.springframework.boot.test.util.EnvironmentTestUtils;
2728
import org.springframework.core.env.MapPropertySource;
2829
import org.springframework.core.env.PropertySource;
2930
import org.springframework.http.HttpStatus;
@@ -264,4 +265,45 @@ public void newValueIsReturnedOnceTtlExpires() throws InterruptedException {
264265
assertThat(health.getStatus() == Status.DOWN).isTrue();
265266
}
266267

268+
@Test
269+
public void detailIsHiddenWhenAllEndpointsAreSensitive() {
270+
EnvironmentTestUtils.addEnvironment(this.environment, "endpoints.sensitive:true");
271+
this.mvc = new HealthMvcEndpoint(this.endpoint, false);
272+
this.mvc.setEnvironment(this.environment);
273+
given(this.endpoint.invoke())
274+
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
275+
Object result = this.mvc.invoke(null);
276+
assertThat(result instanceof Health).isTrue();
277+
assertThat(((Health) result).getStatus() == Status.UP).isTrue();
278+
assertThat(((Health) result).getDetails().get("foo")).isNull();
279+
}
280+
281+
@Test
282+
public void detailIsHiddenWhenHealthEndpointIsSensitive() {
283+
EnvironmentTestUtils.addEnvironment(this.environment,
284+
"endpoints.health.sensitive:true");
285+
this.mvc = new HealthMvcEndpoint(this.endpoint, false);
286+
this.mvc.setEnvironment(this.environment);
287+
given(this.endpoint.invoke())
288+
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
289+
Object result = this.mvc.invoke(null);
290+
assertThat(result instanceof Health).isTrue();
291+
assertThat(((Health) result).getStatus() == Status.UP).isTrue();
292+
assertThat(((Health) result).getDetails().get("foo")).isNull();
293+
}
294+
295+
@Test
296+
public void detailIsHiddenWhenOnlyHealthEndpointIsSensitive() {
297+
EnvironmentTestUtils.addEnvironment(this.environment,
298+
"endpoints.health.sensitive:true", "endpoints.sensitive:false");
299+
this.mvc = new HealthMvcEndpoint(this.endpoint, false);
300+
this.mvc.setEnvironment(this.environment);
301+
given(this.endpoint.invoke())
302+
.willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
303+
Object result = this.mvc.invoke(null);
304+
assertThat(result instanceof Health).isTrue();
305+
assertThat(((Health) result).getStatus() == Status.UP).isTrue();
306+
assertThat(((Health) result).getDetails().get("foo")).isNull();
307+
}
308+
267309
}

0 commit comments

Comments
 (0)