private static Driver getDriver(Neo4jContainer container) { AuthToken authToken = AuthTokens.none(); if (container.getAdminPassword() != null) { authToken = AuthTokens.basic("neo4j", container.getAdminPassword()); } return GraphDatabase.driver(container.getBoltUrl(), authToken); } }
public void initialize() throws URISyntaxException { this.url = getConfiguredUri(this.url); URI uri; try { uri = new URI(this.url); } catch (URISyntaxException e) { throw new URISyntaxException(e.getInput(), e.getMessage()); } this.uri = uri; String[] userInfoArray = uri.getUserInfo() == null ? new String[2] : uri.getUserInfo().split(":"); String user = userInfoArray[0]; String password = userInfoArray[1]; if(user != null && password == null || user == null && password != null) throw new RuntimeException("user and password don't defined check your URL or if you use a key the property in your neo4j.conf file"); this.token = (user != null && password != null) ? AuthTokens.basic(user, password) : AuthTokens.none(); } }
/** * Return a driver for a Neo4j instance with custom configuration. * * @param uri the URL to a Neo4j instance * @param config user defined configuration * @return a new driver to the database instance specified by the URL */ public static Driver driver( URI uri, Config config ) { return driver( uri, AuthTokens.none(), config ); }
public Neo4jBoltDatabase(Neo4jBoltConfiguration configuration) { String host = configuration.getHost(); Integer port = configuration.getPort(); String username = configuration.getUser(); String password = configuration.getPassword(); this.url = String.format("bolt://%s:%s", host, port); if (username != null && password != null) { auth = AuthTokens.basic(username, password); } else { auth = AuthTokens.none(); } }
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()); }
private void initializeDriver() { final String serviceUnavailableMessage = "Could not create driver instance"; try { if (credentials != null) { UsernamePasswordCredentials credentials = (UsernamePasswordCredentials) this.credentials; AuthToken authToken = AuthTokens.basic(credentials.getUsername(), credentials.getPassword()); boltDriver = createDriver(configuration, driverConfig, authToken); } else { try { boltDriver = createDriver(configuration, driverConfig, AuthTokens.none()); } catch (ServiceUnavailableException e) { throw new ConnectionException(serviceUnavailableMessage, e); } LOGGER.debug("Bolt Driver credentials not supplied"); } } catch (ServiceUnavailableException e) { throw new ConnectionException(serviceUnavailableMessage, e); } }
private void initializeDriver() { final String serviceUnavailableMessage = "Could not create driver instance"; try { if (credentials != null) { UsernamePasswordCredentials usernameAndPassword = (UsernamePasswordCredentials) this.credentials; AuthToken authToken = AuthTokens.basic(usernameAndPassword.getUsername(), usernameAndPassword.getPassword()); boltDriver = createDriver(configuration, authToken); } else { try { boltDriver = createDriver(configuration, AuthTokens.none()); } catch (ServiceUnavailableException e) { throw new ConnectionException(serviceUnavailableMessage, e); } LOGGER.debug("Bolt Driver credentials not supplied"); } } catch (ServiceUnavailableException e) { throw new ConnectionException(serviceUnavailableMessage, e); } }
public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings routingSettings, RetrySettings retrySettings, Config config ) { authToken = authToken == null ? AuthTokens.none() : authToken; BoltServerAddress address = new BoltServerAddress( uri ); RoutingSettings newRoutingSettings = routingSettings.withRoutingContext( new RoutingContext( uri ) ); SecurityPlan securityPlan = createSecurityPlan( address, config ); InternalLoggerFactory.setDefaultFactory( new NettyLogging( config.logging() ) ); Bootstrap bootstrap = createBootstrap(); EventExecutorGroup eventExecutorGroup = bootstrap.config().group(); RetryLogic retryLogic = createRetryLogic( retrySettings, eventExecutorGroup, config.logging() ); InternalAbstractMetrics metrics = createDriverMetrics( config ); ConnectionPool connectionPool = createConnectionPool( authToken, securityPlan, bootstrap, metrics, config ); InternalDriver driver = createDriver( uri, securityPlan, address, connectionPool, eventExecutorGroup, newRoutingSettings, retryLogic, metrics, config ); verifyConnectivity( driver, connectionPool, config ); return driver; }