diff --git a/core/src/main/java/org/apache/accumulo/core/conf/ClientProperty.java b/core/src/main/java/org/apache/accumulo/core/conf/ClientProperty.java index 1f76c998a7e..eb1a5b6da81 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/ClientProperty.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/ClientProperty.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.nio.file.Path; +import java.util.Arrays; import java.util.Base64; import java.util.HashMap; import java.util.Map; @@ -132,9 +133,23 @@ public enum ClientProperty { // RPC RPC_TRANSPORT_IDLE_TIMEOUT("rpc.transport.idle.timeout", "3s", PropertyType.TIMEDURATION, "The maximum duration to leave idle transports open in the client's transport pool", "2.1.0", - false), + false); - ; + private static final HashMap propertiesByKey = new HashMap<>(); + + static { + Arrays.stream(ClientProperty.values()).forEach(p -> propertiesByKey.put(p.getKey(), p)); + } + + /** + * Gets a {@link Property} instance with the given key. + * + * @param key property key + * @return property, or null if not found + */ + public static ClientProperty getPropertyByKey(String key) { + return propertiesByKey.get(key); + } private final String key; private final String defaultValue; diff --git a/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java b/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java index 2c3abca0f10..61ed56cfa20 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/DefaultConfiguration.java @@ -21,11 +21,16 @@ import static com.google.common.base.Suppliers.memoize; import java.util.Arrays; +import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * An {@link AccumuloConfiguration} that contains only default values for properties. This class is * a singleton. @@ -33,12 +38,36 @@ public class DefaultConfiguration extends AccumuloConfiguration { private static final Supplier instance = memoize(DefaultConfiguration::new); + private static final Logger LOG = LoggerFactory.getLogger(DefaultConfiguration.class); + + private final Map resolvedProps; + private boolean keyDuplication = false; + + private DefaultConfiguration() { + Map tmp = new HashMap<>(); + + tmp.putAll(Arrays.stream(Property.values()).filter(p -> p.getType() != PropertyType.PREFIX) + .collect(Collectors.toMap(Property::getKey, Property::getDefaultValue))); - private final Map resolvedProps = - Arrays.stream(Property.values()).filter(p -> p.getType() != PropertyType.PREFIX) - .collect(Collectors.toMap(Property::getKey, Property::getDefaultValue)); + Map clientDefaults = (Arrays.stream(ClientProperty.values()) + .filter(p -> p.getType() != PropertyType.PREFIX) + .collect(Collectors.toMap(ClientProperty::getKey, ClientProperty::getDefaultValue))); - private DefaultConfiguration() {} + for (Entry e : clientDefaults.entrySet()) { + if (tmp.containsKey(e.getKey())) { + keyDuplication = true; + if (keyDuplication) { + LOG.warn("Name collision between client and server properties: {}", e.getKey()); + } + + } else { + tmp.put(e.getKey(), e.getValue()); + } + } + + resolvedProps = Map.copyOf(tmp); + } /** * Gets a default configuration. @@ -51,11 +80,19 @@ public static DefaultConfiguration getInstance() { @Override public String get(Property property) { + if (keyDuplication) { + throw new IllegalStateException( + "Name collision between client and server properties, check the log"); + } return resolvedProps.get(property.getKey()); } @Override public void getProperties(Map props, Predicate filter) { + if (keyDuplication) { + throw new IllegalStateException( + "Name collision between client and server properties, check the log"); + } resolvedProps.entrySet().stream().filter(p -> filter.test(p.getKey())) .forEach(e -> props.put(e.getKey(), e.getValue())); } diff --git a/core/src/test/java/org/apache/accumulo/core/conf/PropertyTest.java b/core/src/test/java/org/apache/accumulo/core/conf/PropertyTest.java index be100685e85..a29963ab2ce 100644 --- a/core/src/test/java/org/apache/accumulo/core/conf/PropertyTest.java +++ b/core/src/test/java/org/apache/accumulo/core/conf/PropertyTest.java @@ -248,7 +248,8 @@ public void testSensitiveKeys() { || e.getKey().toLowerCase().endsWith("secret") || e.getKey().startsWith(Property.INSTANCE_CRYPTO_SENSITIVE_PREFIX.getKey()); - Predicate> isMarkedSensitive = e -> Property.isSensitive(e.getKey()); + Predicate> isMarkedSensitive = e -> Property.isSensitive(e.getKey()) + || (ClientProperty.getPropertyByKey(e.getKey()) != null && e.getKey().contains("password")); TreeMap expected = StreamSupport.stream(conf.spliterator(), false) .filter(sensitiveNames).collect(treeMapCollector);