@Test public void testValuesWithPrefixOverride() { String prefix = "prefix."; Properties props = new Properties(); props.put("sasl.mechanism", "PLAIN"); props.put("prefix.sasl.mechanism", "GSSAPI"); props.put("prefix.sasl.kerberos.kinit.cmd", "/usr/bin/kinit2"); props.put("prefix.ssl.truststore.location", "my location"); props.put("sasl.kerberos.service.name", "service name"); props.put("ssl.keymanager.algorithm", "algorithm"); TestSecurityConfig config = new TestSecurityConfig(props); Map<String, Object> valuesWithPrefixOverride = config.valuesWithPrefixOverride(prefix); assertTrue(config.unused().contains("prefix.sasl.mechanism")); assertTrue(config.unused().contains("sasl.mechanism")); assertEquals("GSSAPI", valuesWithPrefixOverride.get("sasl.mechanism")); assertFalse(config.unused().contains("sasl.mechanism")); assertFalse(config.unused().contains("prefix.sasl.mechanism")); assertTrue(config.unused().contains("prefix.sasl.kerberos.kinit.cmd")); assertFalse(config.unused().contains("sasl.kerberos.kinit.cmd")); assertEquals("/usr/bin/kinit2", valuesWithPrefixOverride.get("sasl.kerberos.kinit.cmd")); assertFalse(config.unused().contains("sasl.kerberos.kinit.cmd")); assertFalse(config.unused().contains("prefix.sasl.kerberos.kinit.cmd")); assertTrue(config.unused().contains("prefix.ssl.truststore.location")); assertFalse(config.unused().contains("ssl.truststore.location")); assertEquals("my location", valuesWithPrefixOverride.get("ssl.truststore.location")); assertFalse(config.unused().contains("ssl.truststore.location")); assertFalse(config.unused().contains("prefix.ssl.truststore.location")); assertTrue(config.unused().contains("ssl.keymanager.algorithm")); assertEquals("algorithm", valuesWithPrefixOverride.get("ssl.keymanager.algorithm")); assertFalse(config.unused().contains("ssl.keymanager.algorithm")); assertTrue(config.unused().contains("sasl.kerberos.service.name")); assertEquals("service name", valuesWithPrefixOverride.get("sasl.kerberos.service.name")); assertFalse(config.unused().contains("sasl.kerberos.service.name")); assertFalse(config.unused().contains("sasl.kerberos.min.time.before.relogin")); assertEquals(SaslConfigs.DEFAULT_KERBEROS_MIN_TIME_BEFORE_RELOGIN, valuesWithPrefixOverride.get("sasl.kerberos.min.time.before.relogin")); assertFalse(config.unused().contains("sasl.kerberos.min.time.before.relogin")); assertFalse(config.unused().contains("ssl.key.password")); assertNull(valuesWithPrefixOverride.get("ssl.key.password")); assertFalse(config.unused().contains("ssl.key.password")); }
public Map<String, Object> valuesWithPrefixOverride(String prefix) { Map<String, Object> result = new RecordingMap<>(values(), prefix, true); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) { String keyWithNoPrefix = entry.getKey().substring(prefix.length()); ConfigDef.ConfigKey configKey = definition.configKeys().get(keyWithNoPrefix); if (configKey != null) result.put(keyWithNoPrefix, definition.parseValue(configKey, entry.getValue(), true)); } } return result; }
AbstractConfig { public Map<String, Object> valuesWithPrefixOverride(String prefix) { Map<String, Object> result = new RecordingMap<>(values(), prefix, true); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) { String keyWithNoPrefix = entry.getKey().substring(prefix.length()); ConfigDef.ConfigKey configKey = definition.configKeys().get(keyWithNoPrefix); if (configKey != null) result.put(keyWithNoPrefix, definition.parseValue(configKey, entry.getValue(), true)); } } return result; } }
AbstractConfig { public Map<String, Object> valuesWithPrefixOverride(String prefix) { Map<String, Object> result = new RecordingMap<>(values(), prefix, true); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) { String keyWithNoPrefix = entry.getKey().substring(prefix.length()); ConfigDef.ConfigKey configKey = definition.configKeys().get(keyWithNoPrefix); if (configKey != null) result.put(keyWithNoPrefix, definition.parseValue(configKey, entry.getValue(), true)); } } return result; } @SuppressWarnings("unchecked")  AbstractConfig(ConfigDef definition, Map<?, ?> originals, boolean doLog);  AbstractConfig(ConfigDef definition, Map<?, ?> originals); }
AbstractConfig { public Map<String, Object> valuesWithPrefixOverride(String prefix) { Map<String, Object> result = new RecordingMap<>(values(), prefix, true); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) { String keyWithNoPrefix = entry.getKey().substring(prefix.length()); ConfigDef.ConfigKey configKey = definition.configKeys().get(keyWithNoPrefix); if (configKey != null) result.put(keyWithNoPrefix, definition.parseValue(configKey, entry.getValue(), true)); } } return result; } @SuppressWarnings("unchecked")  AbstractConfig(ConfigDef definition, Map<?, ?> originals, boolean doLog);  AbstractConfig(ConfigDef definition, Map<?, ?> originals); void ignore(String key); Short getShort(String key); Integer getInt(String key); Long getLong(String key); Double getDouble(String key); @SuppressWarnings("unchecked") List<String> getList(String key); Boolean getBoolean(String key); String getString(String key); ConfigDef.Type typeOf(String key); Password getPassword(String key); Class<?> getClass(String key); Set<String> unused(); Map<String, Object> originals(); Map<String, String> originalsStrings(); Map<String, Object> originalsWithPrefix(String prefix); Map<String, Object> valuesWithPrefixOverride(String prefix); Map<String, ?> values(); void logUnused(); T getConfiguredInstance(String key, Class<T> t); List<T> getConfiguredInstances(String key, Class<T> t); List<T> getConfiguredInstances(String key, Class<T> t, Map<String, Object> configOverrides); @Override boolean equals(Object o); @Override int hashCode(); }
AbstractConfig { public Map<String, Object> valuesWithPrefixOverride(String prefix) { Map<String, Object> result = new RecordingMap<>(values(), prefix, true); for (Map.Entry<String, ?> entry : originals.entrySet()) { if (entry.getKey().startsWith(prefix) && entry.getKey().length() > prefix.length()) { String keyWithNoPrefix = entry.getKey().substring(prefix.length()); ConfigDef.ConfigKey configKey = definition.configKeys().get(keyWithNoPrefix); if (configKey != null) result.put(keyWithNoPrefix, definition.parseValue(configKey, entry.getValue(), true)); } } return result; } @SuppressWarnings("unchecked")  AbstractConfig(ConfigDef definition, Map<?, ?> originals, boolean doLog);  AbstractConfig(ConfigDef definition, Map<?, ?> originals); void ignore(String key); Short getShort(String key); Integer getInt(String key); Long getLong(String key); Double getDouble(String key); @SuppressWarnings("unchecked") List<String> getList(String key); Boolean getBoolean(String key); String getString(String key); ConfigDef.Type typeOf(String key); Password getPassword(String key); Class<?> getClass(String key); Set<String> unused(); Map<String, Object> originals(); Map<String, String> originalsStrings(); Map<String, Object> originalsWithPrefix(String prefix); Map<String, Object> valuesWithPrefixOverride(String prefix); Map<String, ?> values(); void logUnused(); T getConfiguredInstance(String key, Class<T> t); List<T> getConfiguredInstances(String key, Class<T> t); List<T> getConfiguredInstances(String key, Class<T> t, Map<String, Object> configOverrides); @Override boolean equals(Object o); @Override int hashCode();  }