Search in sources :

Example 1 with EnvironmentEndpoint

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;
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) BaseCasMvcEndpoint(org.apereo.cas.web.BaseCasMvcEndpoint) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) RequestBody(org.springframework.web.bind.annotation.RequestBody) HttpServletRequest(javax.servlet.http.HttpServletRequest) Pair(org.apache.commons.lang3.tuple.Pair) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Map(java.util.Map) CasConfigurationPropertiesEnvironmentManager(org.apereo.cas.configuration.CasConfigurationPropertiesEnvironmentManager) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) GetMapping(org.springframework.web.bind.annotation.GetMapping) PostMapping(org.springframework.web.bind.annotation.PostMapping) HttpServletResponse(javax.servlet.http.HttpServletResponse) EnvironmentEndpoint(org.springframework.boot.actuate.endpoint.EnvironmentEndpoint) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RegexUtils(org.apereo.cas.util.RegexUtils) ControllerUtils(org.apereo.cas.web.report.util.ControllerUtils) ModelAndView(org.springframework.web.servlet.ModelAndView) Slf4j(lombok.extern.slf4j.Slf4j) TreeMap(java.util.TreeMap) Pattern(java.util.regex.Pattern) CasConfigurationModifiedEvent(org.apereo.cas.support.events.config.CasConfigurationModifiedEvent) RefreshEndpoint(org.springframework.cloud.endpoint.RefreshEndpoint) Pattern(java.util.regex.Pattern) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Pattern (java.util.regex.Pattern)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Pair (org.apache.commons.lang3.tuple.Pair)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 CasConfigurationPropertiesEnvironmentManager (org.apereo.cas.configuration.CasConfigurationPropertiesEnvironmentManager)1 CasConfigurationModifiedEvent (org.apereo.cas.support.events.config.CasConfigurationModifiedEvent)1 RegexUtils (org.apereo.cas.util.RegexUtils)1 BaseCasMvcEndpoint (org.apereo.cas.web.BaseCasMvcEndpoint)1 ControllerUtils (org.apereo.cas.web.report.util.ControllerUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 EnvironmentEndpoint (org.springframework.boot.actuate.endpoint.EnvironmentEndpoint)1 RefreshEndpoint (org.springframework.cloud.endpoint.RefreshEndpoint)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1