本文整理汇总了Java中org.neo4j.driver.v1.AuthTokens类的典型用法代码示例。如果您正苦于以下问题:Java AuthTokens类的具体用法?Java AuthTokens怎么用?Java AuthTokens使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthTokens类属于org.neo4j.driver.v1包,在下文中一共展示了AuthTokens类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Neo4jConnectionManager
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
public Neo4jConnectionManager(Properties properties) {
this.neo4jUrl = properties.getProperty(NEO4J_SERVER_URL);
this.config = Config.build()
.withMaxIdleSessions(Integer.parseInt(properties.getProperty(NEO4J_MAX_CONCURRENCY)))
.toConfig();
String authType = properties.getProperty(NEO4J_AUTH_TYPE);
switch (Neo4jAuthType.valueOf(authType.toUpperCase())) {
case BASIC:
String username = properties.getProperty(NEO4J_AUTH_USER);
String password = properties.getProperty(NEO4J_AUTH_PASSWORD);
this.authToken = AuthTokens.basic(username, password);
break;
case NONE:
LOGGER.debug("Creating NONE authentication");
this.authToken = AuthTokens.none();
break;
default:
throw new RuntimeException("Neo4j authentication type not supported");
}
}
示例2: shouldAuthenticateAndAuthorizeKalleMoraeusAsAdmin
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
@Test
public void shouldAuthenticateAndAuthorizeKalleMoraeusAsAdmin() throws Exception
{
Driver driver = GraphDatabase.driver( server.boltURI(), AuthTokens.basic( "moraeus", "suearom" ) );
Session session = driver.session();
session.run( "CREATE (a:Person {name:'Kalle Moraeus', title:'Riksspelman'})" );
StatementResult result =
session.run( "MATCH (a:Person) WHERE a.name = 'Kalle Moraeus' RETURN a.name AS name, a.title AS title" );
assertTrue( result.hasNext() );
while ( result.hasNext() )
{
Record record = result.next();
assertThat( record.get( "name" ).asString(), equalTo( "Kalle Moraeus" ) );
assertThat( record.get( "title" ).asString(), equalTo( "Riksspelman" ) );
System.out.println( record.get( "title" ).asString() + " " + record.get( "name" ).asString() );
}
session.close();
driver.close();
}
示例3: clear
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
@Override
public void clear(Graph graph, Configuration configuration) throws Exception {
// check graph instance
if (graph != null) {
// close graph instance
graph.close();
}
// connect to server
try (Driver driver = GraphDatabase.driver(configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JUrlConfigurationKey), AuthTokens.basic(configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JUsernameConfigurationKey), configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JPasswordConfigurationKey)), Config.defaultConfig())) {
// open session
try (Session session = driver.session()) {
// begin transaction
try (org.neo4j.driver.v1.Transaction transaction = session.beginTransaction()) {
// delete everything in database
transaction.run(new Statement("MATCH (n) DETACH DELETE n"));
// commit
transaction.success();
}
}
}
}
示例4: connect
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
@Override
public void connect(@Nonnull ConnectionConfig connectionConfig) throws CommandException {
if (isConnected()) {
throw new CommandException("Already connected");
}
final AuthToken authToken = AuthTokens.basic(connectionConfig.username(), connectionConfig.password());
try {
driver = getDriver(connectionConfig, authToken);
reconnect();
} catch (Throwable t) {
try {
silentDisconnect();
} catch (Exception e) {
t.addSuppressed(e);
}
throw t;
}
}
示例5: init
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void init() {
if (driver == null) {
String address = String.format("bolt://%s", hostname);
driver = GraphDatabase.driver(address, AuthTokens.basic(password, username));
logger.info("NeoDriver created: {}", driver.toString());
}
}
示例6: Neo4jConnector
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
public Neo4jConnector(String path, String usr, String pwd){
this.path = path;
this.usr= usr;//"C:/Users/Utente/Documents/Dottorato/Dataset/ontologies/biopax.owl";
this.pwd= pwd;
driver= GraphDatabase.driver(path,AuthTokens.basic(usr, pwd));
session = driver.session();
}
示例7: shouldAuthenticateNeo4jUser
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
@Test
public void shouldAuthenticateNeo4jUser() throws Throwable
{
// When & Then
try( Driver driver = GraphDatabase.driver( server.boltURI(),
AuthTokens.basic( "neo4j", "neo4j" ) );
Session session = driver.session() )
{
Value single = session.run( "RETURN 1" ).single().get( 0 );
assertThat( single.asLong(), equalTo( 1L ) );
}
}
示例8: init
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
public void init(Neo4jSyncConfManager configuration)
{
log.info("configure neo4j connection to {}, user {}",configuration.getNeo4jHostname(),configuration.getNeo4jUsername());
Driver driver = GraphDatabase.driver("bolt://"+configuration.getNeo4jHostname(),
AuthTokens.basic(configuration.getNeo4jUsername(), configuration.getNeo4jPassword()));
session = driver.session();
}
示例9: open
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
public static Graph open(Configuration configuration) {
if (configuration == null)
throw Graph.Exceptions.argumentCanNotBeNull("configuration");
try {
// neo4j driver configuration
Config config = Config.build()
.toConfig();
// graph name
String graphName = configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JGraphNameConfigurationKey);
// create driver instance
Driver driver = GraphDatabase.driver(configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JUrlConfigurationKey), AuthTokens.basic(configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JUsernameConfigurationKey), configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JPasswordConfigurationKey)), config);
// create providers
Neo4JElementIdProvider<?> vertexIdProvider = loadProvider(driver, configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JVertexIdProviderClassNameConfigurationKey));
Neo4JElementIdProvider<?> edgeIdProvider = loadProvider(driver, configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JEdgeIdProviderClassNameConfigurationKey));
// graph instance
Neo4JGraph graph;
// check a read partition is required
if (graphName != null)
graph = new Neo4JGraph(new AnyLabelReadPartition(graphName), new String[]{graphName}, driver, vertexIdProvider, edgeIdProvider, configuration);
else
graph = new Neo4JGraph(new NoReadPartition(), new String[]{}, driver, vertexIdProvider, edgeIdProvider, configuration);
// close driver when graph is closed
graph.addCloseListener(g -> driver.close());
// return graph instance
return graph;
}
catch (Throwable ex) {
// throw runtime exception
throw new RuntimeException("Error creating Graph instance from configuration", ex);
}
}
示例10: CypherPoolingDbConnectionStore
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
public CypherPoolingDbConnectionStore(Map<String, String> properties, CypherBiQueryStore store) {
super(properties, store);
String endPoint = properties.get("endpoint");
String user = properties.get("user");
String password = properties.get("password");
driver = GraphDatabase.driver(endPoint, AuthTokens.basic(user, password));
}
示例11: testRemoteBasicAuth
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
@Test
public void testRemoteBasicAuth() {
Properties props = new Properties();
props.setProperty(DBProperties.SERVER_ROOT_URI, "http://localhost:7474"); // not Bolt
props.setProperty(DBProperties.DATABASE_DIR, "C:/NEO4J_DBS/01");
DBType dbType = DBType.REMOTE;
AuthToken auth = AuthTokens.basic("user", "password");
IDBAccess dba = DBAccessFactory.createDBAccess(dbType, props, auth);
String bauth = ((RemoteDBAccess)dba).getAuth();
assertEquals("Basic dXNlcjpwYXNzd29yZA==", bauth);
return;
}
示例12: bolt
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
private Block bolt(final String uri, final String dbkey, final String user, final String pass) {
return unit -> {
AuthToken token = unit.mock(AuthToken.class);
unit.mockStatic(AuthTokens.class);
expect(AuthTokens.basic(user, pass)).andReturn(token);
Binder binder = unit.get(Binder.class);
Session session = unit.registerMock(Session.class);
LinkedBindingBuilder<Session> lbbs = unit.mock(LinkedBindingBuilder.class);
lbbs.toInstance(session);
expect(binder.bind(Key.get(Session.class))).andReturn(lbbs);
Driver driver = unit.registerMock(Driver.class);
expect(driver.session()).andReturn(session);
LinkedBindingBuilder lbb = unit.mock(LinkedBindingBuilder.class);
lbb.toInstance(driver);
expect(binder.bind(Key.get(Driver.class))).andReturn(lbb);
unit.mockStatic(GraphDatabase.class);
expect(GraphDatabase.driver(uri, token)).andReturn(driver);
ServiceKey keys = unit.get(ServiceKey.class);
keys.generate(eq(Driver.class), eq(dbkey), unit.capture(Consumer.class));
keys.generate(eq(Session.class), eq(dbkey), unit.capture(Consumer.class));
};
}
示例13: create
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
public static Neo4jModule create(String neo4jHost, int neo4jPort, int maxIdleSessions) {
Neo4jSessionFactory sessionFactory = Neo4jSessionFactory.create(
neo4jHost,
neo4jPort,
AuthTokens.none(),
maxIdleSessions
);
return new Neo4jModule(sessionFactory);
}
示例14: authTokens
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
private static AuthToken authTokens(String username, String password) {
if (username.isEmpty()) {
return AuthTokens.none();
}
return AuthTokens.basic(username, password);
}
示例15: prepare
import org.neo4j.driver.v1.AuthTokens; //导入依赖的package包/类
@Before
public void prepare() throws IOException {
dump = folder.newFile("dump.cypher");
exporter = new ExerciseExporter(graphDb.boltURI().toString(), AuthTokens.none());
}