Skip to content

Commit 3eee1f1

Browse files
committed
Add convenience methods to SanitizingFunction
Add a `sanitizeValue()` factory method and `if...` methods that can be used to quickly build a `SanitizingFunction`. Closes gh-39243
1 parent 60adee3 commit 3eee1f1

File tree

5 files changed

+764
-1
lines changed

5 files changed

+764
-1
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/SanitizableData.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.actuate.endpoint;
1818

19+
import java.util.Locale;
20+
1921
import org.springframework.core.env.PropertySource;
2022

2123
/**
@@ -36,6 +38,8 @@ public final class SanitizableData {
3638

3739
private final String key;
3840

41+
private String lowerCaseKey;
42+
3943
private final Object value;
4044

4145
/**
@@ -67,6 +71,20 @@ public String getKey() {
6771
return this.key;
6872
}
6973

74+
/**
75+
* Return the key as a lowercase value.
76+
* @return the key as a lowercase value
77+
* @since 3.5.0
78+
*/
79+
public String getLowerCaseKey() {
80+
String result = this.lowerCaseKey;
81+
if (result == null && this.key != null) {
82+
result = this.key.toLowerCase(Locale.getDefault());
83+
this.lowerCaseKey = result;
84+
}
85+
return result;
86+
}
87+
7088
/**
7189
* Return the value of the data.
7290
* @return the data value

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/Sanitizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Object sanitize(SanitizableData data, boolean showUnsanitized) {
7272
return SanitizableData.SANITIZED_VALUE;
7373
}
7474
for (SanitizingFunction sanitizingFunction : this.sanitizingFunctions) {
75-
data = sanitizingFunction.apply(data);
75+
data = sanitizingFunction.applyUnlessFiltered(data);
7676
Object sanitizedValue = data.getValue();
7777
if (!value.equals(sanitizedValue)) {
7878
return sanitizedValue;

0 commit comments

Comments
 (0)