001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.actuate.autoconfigure.env; 018 019import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; 020import org.springframework.boot.actuate.env.EnvironmentEndpoint; 021import org.springframework.boot.actuate.env.EnvironmentEndpointWebExtension; 022import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 023import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 024import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 025import org.springframework.boot.context.properties.EnableConfigurationProperties; 026import org.springframework.context.annotation.Bean; 027import org.springframework.context.annotation.Configuration; 028import org.springframework.core.env.Environment; 029 030/** 031 * {@link EnableAutoConfiguration Auto-configuration} for the {@link EnvironmentEndpoint}. 032 * 033 * @author Phillip Webb 034 * @author Stephane Nicoll 035 * @since 2.0.0 036 */ 037@Configuration 038@EnableConfigurationProperties(EnvironmentEndpointProperties.class) 039public class EnvironmentEndpointAutoConfiguration { 040 041 private final EnvironmentEndpointProperties properties; 042 043 public EnvironmentEndpointAutoConfiguration( 044 EnvironmentEndpointProperties properties) { 045 this.properties = properties; 046 } 047 048 @Bean 049 @ConditionalOnMissingBean 050 @ConditionalOnEnabledEndpoint 051 public EnvironmentEndpoint environmentEndpoint(Environment environment) { 052 EnvironmentEndpoint endpoint = new EnvironmentEndpoint(environment); 053 String[] keysToSanitize = this.properties.getKeysToSanitize(); 054 if (keysToSanitize != null) { 055 endpoint.setKeysToSanitize(keysToSanitize); 056 } 057 return endpoint; 058 } 059 060 @Bean 061 @ConditionalOnMissingBean 062 @ConditionalOnEnabledEndpoint 063 @ConditionalOnBean(EnvironmentEndpoint.class) 064 public EnvironmentEndpointWebExtension environmentEndpointWebExtension( 065 EnvironmentEndpoint environmentEndpoint) { 066 return new EnvironmentEndpointWebExtension(environmentEndpoint); 067 } 068 069}