31
31
import org .springframework .boot .actuate .endpoint .annotation .Selector ;
32
32
import org .springframework .boot .actuate .env .EnvironmentEndpoint .EnvironmentDescriptor .PropertySourceDescriptor ;
33
33
import org .springframework .boot .actuate .env .EnvironmentEndpoint .EnvironmentDescriptor .PropertySourceDescriptor .PropertyValueDescriptor ;
34
+ import org .springframework .boot .context .properties .bind .PlaceholdersResolver ;
35
+ import org .springframework .boot .context .properties .bind .PropertySourcesPlaceholdersResolver ;
34
36
import org .springframework .boot .origin .OriginLookup ;
35
37
import org .springframework .core .env .CompositePropertySource ;
36
38
import org .springframework .core .env .ConfigurableEnvironment ;
37
39
import org .springframework .core .env .EnumerablePropertySource ;
38
40
import org .springframework .core .env .Environment ;
39
41
import org .springframework .core .env .MutablePropertySources ;
40
- import org .springframework .core .env .PropertyResolver ;
41
42
import org .springframework .core .env .PropertySource ;
42
- import org .springframework .core .env .PropertySources ;
43
- import org .springframework .core .env .PropertySourcesPropertyResolver ;
44
43
import org .springframework .core .env .StandardEnvironment ;
45
44
import org .springframework .http .HttpStatus ;
45
+ import org .springframework .util .PropertyPlaceholderHelper ;
46
46
import org .springframework .util .StringUtils ;
47
+ import org .springframework .util .SystemPropertyUtils ;
47
48
import org .springframework .web .bind .annotation .ResponseStatus ;
48
49
49
50
/**
@@ -85,7 +86,7 @@ public EnvironmentDescriptor environmentEntry(@Selector String toMatch) {
85
86
86
87
private EnvironmentDescriptor getEnvironmentDescriptor (
87
88
Predicate <String > propertyNamePredicate ) {
88
- PropertyResolver resolver = getResolver ();
89
+ PlaceholdersResolver resolver = getResolver ();
89
90
List <PropertySourceDescriptor > propertySources = new ArrayList <>();
90
91
getPropertySourcesAsMap ().forEach ((sourceName , source ) -> {
91
92
if (source instanceof EnumerablePropertySource ) {
@@ -99,7 +100,7 @@ private EnvironmentDescriptor getEnvironmentDescriptor(
99
100
}
100
101
101
102
private PropertySourceDescriptor describeSource (String sourceName ,
102
- EnumerablePropertySource <?> source , PropertyResolver resolver ,
103
+ EnumerablePropertySource <?> source , PlaceholdersResolver resolver ,
103
104
Predicate <String > namePredicate ) {
104
105
Map <String , PropertyValueDescriptor > properties = new LinkedHashMap <>();
105
106
Stream .of (source .getPropertyNames ()).filter (namePredicate ).forEach (
@@ -108,19 +109,17 @@ private PropertySourceDescriptor describeSource(String sourceName,
108
109
}
109
110
110
111
private PropertyValueDescriptor describeValueOf (String name ,
111
- EnumerablePropertySource <?> source , PropertyResolver resolver ) {
112
- Object resolved = resolver .getProperty (name , Object . class );
112
+ EnumerablePropertySource <?> source , PlaceholdersResolver resolver ) {
113
+ Object resolved = resolver .resolvePlaceholders ( source . getProperty (name ) );
113
114
@ SuppressWarnings ("unchecked" )
114
115
String origin = (source instanceof OriginLookup )
115
116
? ((OriginLookup <Object >) source ).getOrigin (name ).toString () : null ;
116
117
return new PropertyValueDescriptor (sanitize (name , resolved ), origin );
117
118
}
118
119
119
- private PropertyResolver getResolver () {
120
- PlaceholderSanitizingPropertyResolver resolver = new PlaceholderSanitizingPropertyResolver (
120
+ private PlaceholdersResolver getResolver () {
121
+ return new PropertySourcesPlaceholdersSanitizingResolver (
121
122
getPropertySources (), this .sanitizer );
122
- resolver .setIgnoreUnresolvableNestedPlaceholders (true );
123
- return resolver ;
124
123
}
125
124
126
125
private Map <String , PropertySource <?>> getPropertySourcesAsMap () {
@@ -160,29 +159,28 @@ public Object sanitize(String name, Object object) {
160
159
}
161
160
162
161
/**
163
- * {@link PropertySourcesPropertyResolver } that sanitizes sensitive placeholders if
164
- * present.
162
+ * {@link PropertySourcesPlaceholdersResolver } that sanitizes sensitive placeholders
163
+ * if present.
165
164
*/
166
- private class PlaceholderSanitizingPropertyResolver
167
- extends PropertySourcesPropertyResolver {
165
+ private static class PropertySourcesPlaceholdersSanitizingResolver
166
+ extends PropertySourcesPlaceholdersResolver {
168
167
169
168
private final Sanitizer sanitizer ;
170
169
171
- /**
172
- * Create a new resolver against the given property sources.
173
- * @param propertySources the set of {@link PropertySource} objects to use
174
- * @param sanitizer the sanitizer used to sanitize sensitive values
175
- */
176
- PlaceholderSanitizingPropertyResolver (PropertySources propertySources ,
177
- Sanitizer sanitizer ) {
178
- super (propertySources );
170
+ public PropertySourcesPlaceholdersSanitizingResolver (
171
+ Iterable <PropertySource <?>> sources , Sanitizer sanitizer ) {
172
+ super (sources , new PropertyPlaceholderHelper (
173
+ SystemPropertyUtils .PLACEHOLDER_PREFIX ,
174
+ SystemPropertyUtils .PLACEHOLDER_SUFFIX ,
175
+ SystemPropertyUtils .VALUE_SEPARATOR , true ));
179
176
this .sanitizer = sanitizer ;
180
177
}
181
178
182
179
@ Override
183
- protected String getPropertyAsRawString (String key ) {
184
- String value = super .getPropertyAsRawString (key );
185
- return (String ) this .sanitizer .sanitize (key , value );
180
+ protected String resolvePlaceholder (String placeholder ) {
181
+ String value = super .resolvePlaceholder (placeholder );
182
+ return (value != null ?
183
+ (String ) this .sanitizer .sanitize (placeholder , value ) : null );
186
184
}
187
185
188
186
}
0 commit comments