use of org.neo4j.graphdb.config.InvalidSettingException in project neo4j by neo4j.
the class HttpConnectorValidator method assertEncryption.
@Nonnull
private static Map<String, String> assertEncryption(@Nonnull String name, @Nonnull Setting<?> setting, @Nonnull Map<String, String> rawConfig) {
Map<String, String> result = setting.validate(rawConfig, nullConsumer);
Optional<?> encryption = Optional.ofNullable(setting.apply(rawConfig::get));
if ("https".equalsIgnoreCase(name)) {
if (encryption.isPresent() && !TLS.equals(encryption.get())) {
throw new InvalidSettingException(format("'%s' is only allowed to be '%s'; not '%s'", setting.name(), TLS.name(), encryption.get()));
}
} else if ("http".equalsIgnoreCase(name)) {
if (encryption.isPresent() && !NONE.equals(encryption.get())) {
throw new InvalidSettingException(format("'%s' is only allowed to be '%s'; not '%s'", setting.name(), NONE.name(), encryption.get()));
}
}
return result;
}
use of org.neo4j.graphdb.config.InvalidSettingException in project neo4j by neo4j.
the class ServerConfigurationValidator method validate.
/**
* Verifies that at least one http connector is specified and enabled.
*/
@Override
@Nonnull
public Map<String, String> validate(@Nonnull Collection<SettingValidator> settingValidators, @Nonnull Map<String, String> rawConfig, @Nonnull Log log, boolean parsingFile) throws InvalidSettingException {
Pattern pattern = Pattern.compile(Pattern.quote("dbms.connector.") + "([^\\.]+)\\.(.+)");
List<Connector> connectors = rawConfig.keySet().stream().map(pattern::matcher).filter(Matcher::matches).map(match -> match.group(1)).distinct().map(Connector::new).collect(Collectors.toList());
Map<String, String> validSettings = new HashMap<>(rawConfig);
// Add missing type info -- validation has succeeded so we can do this with confidence
connectors.stream().filter(connector -> connector.type.apply(rawConfig::get) == null).forEach(connector -> {
if ("http".equalsIgnoreCase(connector.group.groupKey) || "https".equalsIgnoreCase(connector.group.groupKey)) {
validSettings.put(connector.type.name(), HTTP.name());
} else {
validSettings.put(connector.type.name(), BOLT.name());
}
});
if (connectors.stream().filter(connector -> connector.type.apply(validSettings::get).equals(HTTP)).noneMatch(connector -> connector.enabled.apply(validSettings::get))) {
throw new InvalidSettingException(String.format("Missing mandatory enabled connector of type '%s'", HTTP));
}
return validSettings;
}
use of org.neo4j.graphdb.config.InvalidSettingException in project neo4j by neo4j.
the class LoadBalancingPluginLoaderTest method shouldNotAcceptInvalidSetting.
@Test
public void shouldNotAcceptInvalidSetting() {
// given
Config config = Config.empty().augment(stringMap(settingFor(DUMMY_PLUGIN_NAME, DummyLoadBalancingPlugin.DO_NOT_USE_THIS_CONFIG), "true"));
config.augment(stringMap(CausalClusteringSettings.load_balancing_plugin.name(), DUMMY_PLUGIN_NAME));
try {
// when
LoadBalancingPluginLoader.validate(config, mock(Log.class));
fail();
} catch (InvalidSettingException ignored) {
// then
}
}
use of org.neo4j.graphdb.config.InvalidSettingException in project neo4j by neo4j.
the class LoadBalancingPluginLoaderTest method shouldThrowOnInvalidPlugin.
@Test
public void shouldThrowOnInvalidPlugin() {
// given
Config config = Config.empty();
config.augment(stringMap(CausalClusteringSettings.load_balancing_plugin.name(), DOES_NOT_EXIST));
try {
// when
LoadBalancingPluginLoader.validate(config, mock(Log.class));
fail();
} catch (InvalidSettingException ignored) {
// then
}
}
use of org.neo4j.graphdb.config.InvalidSettingException in project neo4j by neo4j.
the class ConfigTest method shouldPassOnValidatorsOnWithMethods.
@Test
public void shouldPassOnValidatorsOnWithMethods() throws Exception {
// Given
ConfigurationValidator validator = spy(new ConfigurationValidator() {
@Nonnull
@Override
public Map<String, String> validate(@Nonnull Collection<SettingValidator> settingValidators, @Nonnull Map<String, String> rawConfig, @Nonnull Log log, boolean parsingFile) throws InvalidSettingException {
return rawConfig;
}
});
Config first = Config.embeddedDefaults(stringMap("first.jibberish", "bah"), Collections.singleton(validator));
// When
Config second = first.withDefaults(stringMap("second.jibberish", "baah"));
second.with(stringMap("third.jibberish", "baah"));
// Then
verify(validator, times(3)).validate(any(), any(), any(), anyBoolean());
}
Aggregations