Search in sources :

Example 1 with Configuration

use of org.neo4j.graphdb.config.Configuration in project neo4j by neo4j.

the class Settings method advertisedAddress.

public static BaseSetting<AdvertisedSocketAddress> advertisedAddress(String name, Setting<ListenSocketAddress> listenAddressSetting) {
    return new ScopeAwareSetting<AdvertisedSocketAddress>() {

        @Override
        protected String provideName() {
            return name;
        }

        @Override
        public String getDefaultValue() {
            return default_advertised_address.getDefaultValue() + ":" + LISTEN_SOCKET_ADDRESS.apply(listenAddressSetting.getDefaultValue()).socketAddress().getPort();
        }

        @Override
        public AdvertisedSocketAddress from(Configuration config) {
            return config.get(this);
        }

        @Override
        public AdvertisedSocketAddress apply(Function<String, String> config) {
            ListenSocketAddress listenSocketAddress = listenAddressSetting.apply(config);
            String hostname = default_advertised_address.apply(config);
            int port = listenSocketAddress.socketAddress().getPort();
            String name = name();
            String value = config.apply(name);
            return SocketAddressFormat.socketAddress(name, value, hostname, port, AdvertisedSocketAddress::new);
        }

        @Override
        public void withScope(Function<String, String> scopingRule) {
            super.withScope(scopingRule);
            listenAddressSetting.withScope(scopingRule);
        }

        @Override
        public String valueDescription() {
            return ADVERTISED_SOCKET_ADDRESS.toString();
        }
    };
}
Also used : BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) Configuration(org.neo4j.graphdb.config.Configuration) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ScopeAwareSetting(org.neo4j.graphdb.config.ScopeAwareSetting) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress)

Example 2 with Configuration

use of org.neo4j.graphdb.config.Configuration in project neo4j by neo4j.

the class URLAccessRules method combined.

public static URLAccessRule combined(final Map<String, URLAccessRule> urlAccessRules) {
    return new URLAccessRule() {

        @Override
        public URL validate(Configuration config, URL url) throws URLAccessValidationError {
            String protocol = url.getProtocol();
            URLAccessRule protocolRule = urlAccessRules.get(protocol);
            if (protocolRule == null) {
                throw new URLAccessValidationError("loading resources via protocol '" + protocol + "' is not permitted");
            }
            return protocolRule.validate(config, url);
        }
    };
}
Also used : URLAccessRule(org.neo4j.graphdb.security.URLAccessRule) Configuration(org.neo4j.graphdb.config.Configuration) URL(java.net.URL) URLAccessValidationError(org.neo4j.graphdb.security.URLAccessValidationError)

Example 3 with Configuration

use of org.neo4j.graphdb.config.Configuration in project neo4j by neo4j.

the class Settings method pathSetting.

public static Setting<File> pathSetting(String name, String defaultValue) {
    return new ScopeAwareSetting<File>() {

        @Override
        protected String provideName() {
            return name;
        }

        @Override
        public String getDefaultValue() {
            return defaultValue;
        }

        @Override
        public File from(Configuration config) {
            return config.get(this);
        }

        @Override
        public File apply(Function<String, String> config) {
            String value = config.apply(name());
            if (value == null) {
                value = defaultValue;
            }
            if (value == null) {
                return null;
            }
            String setting = fixSeparatorsInPath(value);
            File settingFile = new File(setting);
            if (settingFile.isAbsolute()) {
                return settingFile;
            } else {
                return new File(GraphDatabaseSettings.neo4j_home.apply(config), setting);
            }
        }

        @Override
        public String valueDescription() {
            return "A filesystem path; relative paths are resolved against the installation root, _<neo4j-home>_";
        }
    };
}
Also used : BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) Configuration(org.neo4j.graphdb.config.Configuration) ScopeAwareSetting(org.neo4j.graphdb.config.ScopeAwareSetting) File(java.io.File)

Aggregations

Configuration (org.neo4j.graphdb.config.Configuration)3 BiFunction (java.util.function.BiFunction)2 Function (java.util.function.Function)2 ScopeAwareSetting (org.neo4j.graphdb.config.ScopeAwareSetting)2 File (java.io.File)1 URL (java.net.URL)1 URLAccessRule (org.neo4j.graphdb.security.URLAccessRule)1 URLAccessValidationError (org.neo4j.graphdb.security.URLAccessValidationError)1 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1