|
19 | 19 | import java.lang.reflect.InvocationTargetException;
|
20 | 20 | import java.lang.reflect.Method;
|
21 | 21 | import java.util.Arrays;
|
| 22 | +import java.util.Collections; |
22 | 23 | import java.util.Enumeration;
|
| 24 | +import java.util.HashSet; |
23 | 25 | import java.util.List;
|
24 | 26 | import java.util.Map;
|
25 | 27 | import java.util.Properties;
|
| 28 | +import java.util.Set; |
26 | 29 | import java.util.logging.Logger;
|
27 | 30 | import org.checkerframework.checker.nullness.qual.NonNull;
|
28 | 31 | import software.amazon.jdbc.PropertyDefinition;
|
29 | 32 |
|
30 | 33 | public class PropertyUtils {
|
31 | 34 | private static final Logger LOGGER = Logger.getLogger(PropertyUtils.class.getName());
|
| 35 | + private static final Set<Object> SECRET_PROPERTIES = Collections.unmodifiableSet( |
| 36 | + new HashSet<>(Collections.singletonList(PropertyDefinition.PASSWORD.name)) |
| 37 | + ); |
32 | 38 |
|
33 | 39 | public static void applyProperties(final Object target, final Properties properties) {
|
34 | 40 | if (target == null || properties == null) {
|
@@ -96,7 +102,8 @@ public static void setPropertyOnTarget(
|
96 | 102 | } else {
|
97 | 103 | writeMethod.invoke(target, propValue);
|
98 | 104 | }
|
99 |
| - LOGGER.finest(() -> String.format("Set property '%s' with value: %s", propName, propValue)); |
| 105 | + Object cleanPropValue = isSecretProperty(propName) ? "***" : propValue; |
| 106 | + LOGGER.finest(() -> String.format("Set property '%s' with value: %s", propName, cleanPropValue)); |
100 | 107 |
|
101 | 108 | } catch (final InvocationTargetException ex) {
|
102 | 109 | LOGGER.warning(
|
@@ -127,6 +134,10 @@ public static void setPropertyOnTarget(
|
127 | 134 | return copy;
|
128 | 135 | }
|
129 | 136 |
|
| 137 | + private static boolean isSecretProperty(final Object propertyKey) { |
| 138 | + return SECRET_PROPERTIES.contains(propertyKey); |
| 139 | + } |
| 140 | + |
130 | 141 | public static @NonNull Properties maskProperties(final Properties props) {
|
131 | 142 | final Properties maskedProperties = copyProperties(props);
|
132 | 143 | if (maskedProperties.containsKey(PropertyDefinition.PASSWORD.name)) {
|
|
0 commit comments