Merge branch '1.5.x'
This commit is contained in:
@@ -169,7 +169,8 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
/**
|
||||
* Comma-separated list of roles that can access the management endpoint.
|
||||
*/
|
||||
private List<String> roles = new ArrayList<String>(Collections.singletonList("ACTUATOR"));
|
||||
private List<String> roles = new ArrayList<String>(
|
||||
Collections.singletonList("ACTUATOR"));
|
||||
|
||||
/**
|
||||
* Session creating policy for security use (always, never, if_required,
|
||||
|
||||
@@ -61,7 +61,8 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("profiles", getEnvironment().getActiveProfiles());
|
||||
PropertyResolver resolver = getResolver();
|
||||
for (Entry<String, PropertySource<?>> entry : getPropertySourcesAsMap().entrySet()) {
|
||||
for (Entry<String, PropertySource<?>> entry : getPropertySourcesAsMap()
|
||||
.entrySet()) {
|
||||
PropertySource<?> source = entry.getValue();
|
||||
String sourceName = entry.getKey();
|
||||
if (source instanceof EnumerablePropertySource) {
|
||||
@@ -88,8 +89,7 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
|
||||
private Map<String, PropertySource<?>> getPropertySourcesAsMap() {
|
||||
Map<String, PropertySource<?>> map = new LinkedHashMap<String, PropertySource<?>>();
|
||||
MutablePropertySources sources = getPropertySources();
|
||||
for (PropertySource<?> source : sources) {
|
||||
for (PropertySource<?> source : getPropertySources()) {
|
||||
extract("", map, source);
|
||||
}
|
||||
return map;
|
||||
@@ -138,12 +138,11 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link PropertySourcesPropertyResolver} that sanitizes sensitive placeholders
|
||||
* if present.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* {@link PropertySourcesPropertyResolver} that sanitizes sensitive placeholders if
|
||||
* present.
|
||||
*/
|
||||
private class PlaceholderSanitizingPropertyResolver extends PropertySourcesPropertyResolver {
|
||||
private class PlaceholderSanitizingPropertyResolver
|
||||
extends PropertySourcesPropertyResolver {
|
||||
|
||||
private final Sanitizer sanitizer;
|
||||
|
||||
@@ -152,8 +151,8 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
* @param propertySources the set of {@link PropertySource} objects to use
|
||||
* @param sanitizer the sanitizer used to sanitize sensitive values
|
||||
*/
|
||||
PlaceholderSanitizingPropertyResolver(PropertySources
|
||||
propertySources, Sanitizer sanitizer) {
|
||||
PlaceholderSanitizingPropertyResolver(PropertySources propertySources,
|
||||
Sanitizer sanitizer) {
|
||||
super(propertySources);
|
||||
this.sanitizer = sanitizer;
|
||||
}
|
||||
@@ -163,6 +162,7 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
String value = super.getPropertyAsRawString(key);
|
||||
return (String) this.sanitizer.sanitize(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
@@ -97,13 +98,11 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request,
|
||||
HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
long startTime = System.currentTimeMillis();
|
||||
long startTime = System.nanoTime();
|
||||
Map<String, Object> trace = getTrace(request);
|
||||
logTrace(request, trace);
|
||||
int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
|
||||
@@ -112,8 +111,7 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
|
||||
status = response.getStatus();
|
||||
}
|
||||
finally {
|
||||
long endTime = System.currentTimeMillis();
|
||||
addTimeTaken(startTime, endTime, trace);
|
||||
addTimeTaken(trace, startTime);
|
||||
enhanceTrace(trace, status == response.getStatus() ? response
|
||||
: new CustomStatusResponseWrapper(response, status));
|
||||
this.repository.add(trace);
|
||||
@@ -200,9 +198,10 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
|
||||
protected void postProcessRequestHeaders(Map<String, Object> headers) {
|
||||
}
|
||||
|
||||
private void addTimeTaken(long startTime, long endTime, Map<String, Object> trace) {
|
||||
long timeTaken = endTime - startTime;
|
||||
add(trace, Include.TIME_TAKEN, "timeTaken", String.valueOf(timeTaken));
|
||||
private void addTimeTaken(Map<String, Object> trace, long startTime) {
|
||||
long timeTaken = System.nanoTime() - startTime;
|
||||
add(trace, Include.TIME_TAKEN, "timeTaken",
|
||||
"" + TimeUnit.NANOSECONDS.toMillis(timeTaken));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -138,7 +138,8 @@ public class EnvironmentMvcEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() throws Exception {
|
||||
public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty()
|
||||
throws Exception {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("my.foo", "${my.bar}");
|
||||
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
|
||||
|
||||
@@ -250,8 +250,8 @@ public class WebRequestTraceFilterTests {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
MockFilterChain chain = new MockFilterChain();
|
||||
this.filter.doFilter(request, response, chain);
|
||||
String timeTaken = (String) this.repository.findAll()
|
||||
.iterator().next().getInfo().get("timeTaken");
|
||||
String timeTaken = (String) this.repository.findAll().iterator().next().getInfo()
|
||||
.get("timeTaken");
|
||||
assertThat(timeTaken).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user