Search in sources :

Example 1 with InvalidSettingException

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;
}
Also used : InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) Nonnull(javax.annotation.Nonnull)

Example 2 with InvalidSettingException

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;
}
Also used : HTTP(org.neo4j.kernel.configuration.Connector.ConnectorType.HTTP) Log(org.neo4j.logging.Log) Collection(java.util.Collection) SettingValidator(org.neo4j.graphdb.config.SettingValidator) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) List(java.util.List) Matcher(java.util.regex.Matcher) BOLT(org.neo4j.kernel.configuration.Connector.ConnectorType.BOLT) Map(java.util.Map) Pattern(java.util.regex.Pattern) Nonnull(javax.annotation.Nonnull) InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) Nonnull(javax.annotation.Nonnull)

Example 3 with InvalidSettingException

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
    }
}
Also used : Log(org.neo4j.logging.Log) Config(org.neo4j.kernel.configuration.Config) InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) Test(org.junit.Test)

Example 4 with InvalidSettingException

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
    }
}
Also used : Log(org.neo4j.logging.Log) Config(org.neo4j.kernel.configuration.Config) InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) Test(org.junit.Test)

Example 5 with InvalidSettingException

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());
}
Also used : Nonnull(javax.annotation.Nonnull) Log(org.neo4j.logging.Log) SettingValidator(org.neo4j.graphdb.config.SettingValidator) LoadableConfig(org.neo4j.configuration.LoadableConfig) InvalidSettingException(org.neo4j.graphdb.config.InvalidSettingException) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Test(org.junit.Test)

Aggregations

InvalidSettingException (org.neo4j.graphdb.config.InvalidSettingException)5 Log (org.neo4j.logging.Log)4 Nonnull (javax.annotation.Nonnull)3 Test (org.junit.Test)3 Map (java.util.Map)2 SettingValidator (org.neo4j.graphdb.config.SettingValidator)2 Config (org.neo4j.kernel.configuration.Config)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 LoadableConfig (org.neo4j.configuration.LoadableConfig)1 MapUtil.stringMap (org.neo4j.helpers.collection.MapUtil.stringMap)1 BOLT (org.neo4j.kernel.configuration.Connector.ConnectorType.BOLT)1 HTTP (org.neo4j.kernel.configuration.Connector.ConnectorType.HTTP)1