private Config configuration() { return Config.build().withEncryptionLevel( Config.EncryptionLevel.NONE ) .withConnectionTimeout( 10, TimeUnit.SECONDS ) .toConfig(); }
private static Config getOrDefault( Config config ) { return config != null ? config : Config.defaultConfig(); } }
/** * Create a config instance from this builder. * * @return a new {@link Config} instance. */ public Config build() { return new Config( this ); } }
private static synchronized void cleanupNeo4jKnownHosts(Neo4jServerLoader neo4jServerLoader) { File hostsFile = Config.defaultConfig().trustStrategy().certFile(); try { if (hostsFile != null && hostsFile.isFile()) { List<String> lines = FileUtil.loadLines(hostsFile); List<String> updatedLines = lines.stream() .filter((line) -> !line.startsWith(neo4jServerLoader.getBoltHost() + ":" + neo4jServerLoader.getBoltPort())) .filter((line) -> !line.isEmpty()) .collect(Collectors.toList()); FileUtil.writeToFile(hostsFile, String.join(System.lineSeparator(), updatedLines) + System.lineSeparator()); } } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } } }
throws GeneralSecurityException, IOException if ( config.encrypted() ) Logger logger = config.logging().getLog( "SecurityPlan" ); Config.TrustStrategy trustStrategy = config.trustStrategy(); boolean hostnameVerificationEnabled = trustStrategy.isHostnameVerificationEnabled(); switch ( trustStrategy.strategy() )
/** * Start building a {@link Config} object using a newly created builder. * <p> * <b>Please use {@link #builder()} method instead.</b> * * @return a new {@link ConfigBuilder} instance. */ public static ConfigBuilder build() { return builder(); }
/** * @return A config with all default settings */ public static Config defaultConfig() { return Config.builder().build(); }
Long connectionTimeoutMillis = (Long) driverConfMap.getOrDefault("connectionTimeoutMillis", 5000L); Long maxRetryTimeMs = (Long) driverConfMap.getOrDefault("maxRetryTimeMs", 30000L); Config.ConfigBuilder config = Config.build(); config.withLogging(new JULogging(Level.parse(logging))); if(!encryption) config.withoutEncryption();
protected Config neo4jConfig() { return Config.defaultConfig(); }
private Driver getDriver(@Nonnull ConnectionConfig connectionConfig, @Nullable AuthToken authToken) { Config config = Config.build() .withLogging(NullLogging.NULL_LOGGING) .withEncryptionLevel(connectionConfig.encryption()).toConfig(); return driverProvider.apply(connectionConfig.driverUrl(), authToken, config); }
protected Config neo4jConfig() { return Config.defaultConfig(); }
public BoltCypherExecutor(String url, String username, String password) { boolean hasPassword = password != null && !password.isEmpty(); AuthToken token = hasPassword ? AuthTokens.basic(username, password) : AuthTokens.none(); driver = GraphDatabase.driver(url, token, Config.build().withEncryptionLevel(Config.EncryptionLevel.NONE).toConfig()); }
/** * Return a driver for a Neo4j instance with the default configuration settings * * @param uri the URL to a Neo4j instance * @return a new driver to the database instance specified by the URL */ public static Driver driver( URI uri ) { return driver( uri, Config.defaultConfig() ); }
private Config buildDriverConfig(Configuration driverConfig) { try { BoltConfig boltConfig = getBoltConfiguration(driverConfig); Config.ConfigBuilder configBuilder = Config.build(); configBuilder.withMaxSessions(boltConfig.sessionPoolSize); if (boltConfig.encryptionLevel.equals(Config.EncryptionLevel.REQUIRED)) {
/** * Return a driver for a Neo4j instance with the default configuration settings * * @param uri the URL to a Neo4j instance * @return a new driver to the database instance specified by the URL */ public static Driver driver( String uri ) { return driver( uri, Config.defaultConfig() ); }
private Config buildDriverConfig() { try { BoltConfig boltConfig = getBoltConfiguration(); Config.ConfigBuilder configBuilder = Config.build(); configBuilder.withMaxSessions(boltConfig.sessionPoolSize); if (boltConfig.encryptionLevel.equals(Config.EncryptionLevel.REQUIRED)) {
/** * Return a driver for a Neo4j instance with the default configuration settings * * @param uri the URL to a Neo4j instance * @param authToken authentication to use, see {@link AuthTokens} * @return a new driver to the database instance specified by the URL */ public static Driver driver( String uri, AuthToken authToken ) { return driver( uri, authToken, Config.defaultConfig() ); }
@Test public void shouldDiffGetTheDiffBetweenTwoStatesCorrectlyWithDifferentObjectTypes() { // This is in a try-block, to make sure we close the driver after the test try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) { // Given session.run("CREATE (s:State:From {a:1, b:1, c:'stringA', d:'string', e: [1, 2], f: [1, 2]})"); session.run("CREATE (s:State:To {a:2, b:1, c:'stringB', d:'string', e:[1, 2], f: [1, 3]})"); // When StatementResult result = session .run("MATCH (stateTo:State:To), (stateFrom:State:From) WITH stateFrom, stateTo CALL graph.versioner.diff(stateFrom, stateTo) YIELD operation, label, oldValue, newValue RETURN operation, label, oldValue, newValue"); // Then assertThat(result.next().values().stream().map(value -> value.asObject().toString()).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_UPDATE, "a", "1", "2")); assertThat(result.next().values().stream().map(value -> value.asObject().toString()).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_UPDATE, "c", "stringA", "stringB")); assertThat(result.next().values().stream().map(value -> value.asObject().toString()).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_UPDATE, "f", "[1, 2]", "[1, 3]")); assertThat(result.hasNext(), is(false)); } }
/** * Return a driver for a Neo4j instance with the default configuration settings * * @param uri the URL to a Neo4j instance * @param authToken authentication to use, see {@link AuthTokens} * @return a new driver to the database instance specified by the URL */ public static Driver driver( URI uri, AuthToken authToken ) { return driver( uri, authToken, Config.defaultConfig() ); }
@Test public void shouldDiffGetTheDiffBetweenTwoStatesCorrectly() { // This is in a try-block, to make sure we close the driver after the test try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) { // Given session.run("CREATE (s:State:From {keep:'keep', update:'old', delete:'delete'})"); session.run("CREATE (s:State:To {keep:'keep', update:'new', new:'new'})"); // When StatementResult result = session .run("MATCH (stateTo:State:To), (stateFrom:State:From) WITH stateFrom, stateTo CALL graph.versioner.diff(stateFrom, stateTo) YIELD operation, label, oldValue, newValue RETURN operation, label, oldValue, newValue"); // Then assertThat(result.next().values().stream().map(Value::asString).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_REMOVE, "delete", "delete", "null")); assertThat(result.next().values().stream().map(Value::asString).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_UPDATE, "update", "old", "new")); assertThat(result.next().values().stream().map(Value::asString).collect(Collectors.toList()), contains(Utility.DIFF_OPERATION_ADD, "new", "null", "new")); assertThat(result.hasNext(), is(false)); } }