Search in sources :

Example 1 with UsernamePasswordCredentials

use of org.neo4j.ogm.config.UsernamePasswordCredentials in project neo4j-ogm by neo4j.

the class BoltDriver method initializeDriver.

private void initializeDriver() {
    final String serviceUnavailableMessage = "Could not create driver instance";
    Driver driver = null;
    try {
        if (credentials != null) {
            UsernamePasswordCredentials usernameAndPassword = (UsernamePasswordCredentials) this.credentials;
            AuthToken authToken = AuthTokens.basic(usernameAndPassword.getUsername(), usernameAndPassword.getPassword());
            driver = createDriver(authToken);
        } else {
            LOGGER.debug("Bolt Driver credentials not supplied");
            driver = createDriver(AuthTokens.none());
        }
        driver.verifyConnectivity();
        boltDriver = driver;
        // set null to skip close() in finally
        driver = null;
    } catch (ServiceUnavailableException e) {
        throw new ConnectionException(serviceUnavailableMessage, e);
    } finally {
        if (driver != null) {
            driver.close();
        }
    }
}
Also used : AbstractConfigurableDriver(org.neo4j.ogm.driver.AbstractConfigurableDriver) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ConnectionException(org.neo4j.ogm.exception.ConnectionException) UsernamePasswordCredentials(org.neo4j.ogm.config.UsernamePasswordCredentials)

Aggregations

ServiceUnavailableException (org.neo4j.driver.exceptions.ServiceUnavailableException)1 UsernamePasswordCredentials (org.neo4j.ogm.config.UsernamePasswordCredentials)1 AbstractConfigurableDriver (org.neo4j.ogm.driver.AbstractConfigurableDriver)1 ConnectionException (org.neo4j.ogm.exception.ConnectionException)1