diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java index 20aebd73602..db35991038a 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java @@ -92,8 +92,7 @@ public class EnvironmentMvcEndpoint extends EndpointMvcAdapter @Override protected Object getOptionalValue(Environment source, String name) { - Object result = ((EnvironmentEndpoint) getDelegate()).getResolver() - .getProperty(name, Object.class); + Object result = getValue(name); if (result != null) { result = ((EnvironmentEndpoint) getDelegate()).sanitize(name, result); } @@ -102,13 +101,18 @@ public class EnvironmentMvcEndpoint extends EndpointMvcAdapter @Override protected Object getValue(Environment source, String name) { - Object result = source.getProperty(name, Object.class); + Object result = getValue(name); if (result == null) { throw new NoSuchPropertyException("No such property: " + name); } return ((EnvironmentEndpoint) getDelegate()).sanitize(name, result); } + private Object getValue(String name) { + return ((EnvironmentEndpoint) getDelegate()).getResolver().getProperty(name, + Object.class); + } + } /** diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java index 12572e9f778..fce767f351a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java @@ -146,7 +146,7 @@ public class EnvironmentMvcEndpointTests { map.put("my.foo", "${my.bar}"); ((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources() .addFirst(new MapPropertySource("unresolved-placeholder", map)); - this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk()) + this.mvc.perform(get("/application/env/my.foo")).andExpect(status().isOk()) .andExpect(content().string(containsString("\"my.foo\":\"${my.bar}\""))); } @@ -155,6 +155,29 @@ public class EnvironmentMvcEndpointTests { Map map = new HashMap<>(); map.put("my.foo", "${my.password}"); map.put("my.password", "hello"); + ((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources() + .addFirst(new MapPropertySource("placeholder", map)); + this.mvc.perform(get("/application/env/my.foo")).andExpect(status().isOk()) + .andExpect(content().string(containsString("\"my.foo\":\"******\""))); + } + + @Test + public void nestedPathMatchedByRegexWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() + throws Exception { + Map map = new HashMap(); + map.put("my.foo", "${my.bar}"); + ((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources() + .addFirst(new MapPropertySource("unresolved-placeholder", map)); + this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk()) + .andExpect(content().string(containsString("\"my.foo\":\"${my.bar}\""))); + } + + @Test + public void nestedPathMatchedByRegexWithSensitivePlaceholderShouldSanitize() + throws Exception { + Map map = new HashMap(); + map.put("my.foo", "${my.password}"); + map.put("my.password", "hello"); ((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources() .addFirst(new MapPropertySource("placeholder", map)); this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk())