use of org.springframework.boot.actuate.endpoint.EnvironmentEndpoint in project cas by apereo.
the class ConfigurationStateController method getConfiguration.
/**
* Gets configuration.
*
* @param request the request
* @param response the response
* @return the configuration
*/
@GetMapping("/getConfiguration")
@ResponseBody
public Map getConfiguration(final HttpServletRequest request, final HttpServletResponse response) {
final Map results = new TreeMap();
ensureEndpointAccessIsAuthorized(request, response);
if (environmentEndpoint == null || !environmentEndpoint.isEnabled()) {
LOGGER.warn("Environment endpoint is either undefined or disabled");
return results;
}
final Pattern pattern = RegexUtils.createPattern("(configService:|applicationConfig:).+(application|cas).+");
final Map<String, Object> environmentSettings = environmentEndpoint.invoke();
environmentSettings.entrySet().stream().filter(entry -> pattern.matcher(entry.getKey()).matches()).forEach(entry -> {
final Map<String, Object> keys = (Map<String, Object>) entry.getValue();
keys.keySet().forEach(key -> {
if (!results.containsKey(key)) {
final String propHolder = String.format("${%s}", key);
final String value = this.environment.resolvePlaceholders(propHolder);
results.put(key, environmentEndpoint.sanitize(key, value));
}
});
});
return results;
}
Aggregations