String username = conf.getString(dbkey + ".user"); String password = conf.getString(dbkey + ".password"); Driver driver = GraphDatabase.driver(db, AuthTokens.basic(username, password)); Session session = driver.session(); props.setProperty(DBProperties.SERVER_ROOT_URI, db);
/** * 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 ); }
/** * A custom authentication token used for doing custom authentication on the server side. * @param principal this used to identify who this token represents * @param credentials this is credentials authenticating the principal * @param realm this is the "realm:, specifying the authentication provider. * @param scheme this it the authentication scheme, specifying what kind of authentication that should be used * @return an authentication token that can be used to connect to Neo4j * @see GraphDatabase#driver(String, AuthToken) * @throws NullPointerException when either principal, credentials or scheme is {@code null} */ public static AuthToken custom( String principal, String credentials, String realm, String scheme) { return custom( principal, credentials, realm, scheme, null ); }
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; }
@Test public void shouldStart() { boolean actual = neo4jContainer.isRunning(); assertThat(actual).isTrue(); try (Driver driver = GraphDatabase .driver(neo4jContainer.getBoltUrl(), AuthTokens.basic("neo4j", "password")); Session session = driver.session() ) { long one = session.run("RETURN 1", Collections.emptyMap()).next().get(0).asLong(); assertThat(one).isEqualTo(1L); } catch (Exception e) { fail(e.getMessage()); } }
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(); } }
@Override public void setAuth(String userId, String password) { if (userId != null && password != null) this.authToken = AuthTokens.basic(userId, password); }
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(); } }
/** * The basic authentication scheme, using a username and a password. * @param username this is the "principal", identifying who this token represents * @param password this is the "credential", proving the identity of the user * @return an authentication token that can be used to connect to Neo4j * @see GraphDatabase#driver(String, AuthToken) * @throws NullPointerException when either username or password is {@code null} */ public static AuthToken basic( String username, String password ) { return basic( username, password, null ); }
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()); }
@Override public void setAuth(String userId, String password) { if (userId != null && password != null) this.authToken = AuthTokens.basic(userId, password); }
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); } }
private static Driver open(String neo4jDriverURL, String neo4jDriverUsername, String neo4jDriverPassword) { return GraphDatabase.driver(neo4jDriverURL, AuthTokens.basic(neo4jDriverUsername, neo4jDriverPassword)); } }
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); } }
@Override protected Graph createGraph() { driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(neo4jUsername, neo4jPassword)); Neo4JElementIdProvider<?> vertexIdProvider = new DatabaseSequenceElementIdProvider(driver); Neo4JElementIdProvider<?> edgeIdProvider = new DatabaseSequenceElementIdProvider(driver); // create graph instance return new Neo4JGraph(driver, vertexIdProvider, edgeIdProvider); }
@Override protected Graph createGraph() { driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(neo4jUsername, neo4jPassword)); Neo4JElementIdProvider<?> vertexIdProvider = new DatabaseSequenceElementIdProvider(driver); Neo4JElementIdProvider<?> edgeIdProvider = new DatabaseSequenceElementIdProvider(driver); // create graph instance return new Neo4JGraph(driver, vertexIdProvider, edgeIdProvider); }
@Override protected Graph createGraph() { driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(neo4jUsername, neo4jPassword)); Neo4JElementIdProvider<?> vertexIdProvider = new DatabaseSequenceElementIdProvider(driver); Neo4JElementIdProvider<?> edgeIdProvider = new DatabaseSequenceElementIdProvider(driver); // create graph instance return new Neo4JGraph(driver, vertexIdProvider, edgeIdProvider); }
@Override protected Graph createGraph() { driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(neo4jUsername, neo4jPassword)); Neo4JElementIdProvider<?> vertexIdProvider = new DatabaseSequenceElementIdProvider(driver); Neo4JElementIdProvider<?> edgeIdProvider = new DatabaseSequenceElementIdProvider(driver); // create graph instance return new Neo4JGraph(driver, vertexIdProvider, edgeIdProvider); }
config.action = commandLine.getOptionValue("a"); driver = GraphDatabase.driver(config.neoUrl, AuthTokens.basic(config.neoUser, config.neoPswd));