Search in sources :

Example 6 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade in project neo4j by neo4j.

the class NonUniqueIndexTests method newEmbeddedGraphDatabaseWithSlowJobScheduler.

private GraphDatabaseService newEmbeddedGraphDatabaseWithSlowJobScheduler() {
    GraphDatabaseFactoryState graphDatabaseFactoryState = new GraphDatabaseFactoryState();
    graphDatabaseFactoryState.setUserLogProvider(NullLogService.getInstance().getUserLogProvider());
    return new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, CommunityEditionModule::new) {

        @Override
        protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
            return new PlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade) {

                @Override
                protected Neo4jJobScheduler createJobScheduler() {
                    return newSlowJobScheduler();
                }

                @Override
                protected LogService createLogService(LogProvider userLogProvider) {
                    return NullLogService.getInstance();
                }
            };
        }
    }.newFacade(directory.graphDbDir(), Config.embeddedDefaults(), graphDatabaseFactoryState.databaseDependencies());
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) Config(org.neo4j.kernel.configuration.Config) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) GraphDatabaseFactoryState(org.neo4j.graphdb.factory.GraphDatabaseFactoryState) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) File(java.io.File) LogService(org.neo4j.kernel.impl.logging.LogService) NullLogService(org.neo4j.kernel.impl.logging.NullLogService)

Example 7 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade in project neo4j by neo4j.

the class CypherSessionTest method shouldReturnASingleNode.

@Test
public void shouldReturnASingleNode() throws Throwable {
    GraphDatabaseFacade graphdb = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
    Database database = new WrappedDatabase(graphdb);
    CypherExecutor executor = new CypherExecutor(database, NullLogProvider.getInstance());
    executor.start();
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getScheme()).thenReturn("http");
    when(request.getRemoteAddr()).thenReturn("127.0.0.1");
    when(request.getRemotePort()).thenReturn(5678);
    when(request.getServerName()).thenReturn("127.0.0.1");
    when(request.getServerPort()).thenReturn(7474);
    when(request.getRequestURI()).thenReturn("/");
    try {
        CypherSession session = new CypherSession(executor, NullLogProvider.getInstance(), request);
        Pair<String, String> result = session.evaluate("create (a) return a");
        assertThat(result.first(), containsString("Node[0]"));
    } finally {
        graphdb.shutdown();
    }
}
Also used : CypherExecutor(org.neo4j.server.database.CypherExecutor) HttpServletRequest(javax.servlet.http.HttpServletRequest) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Database(org.neo4j.server.database.Database) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) CypherSession(org.neo4j.server.rest.management.console.CypherSession) Test(org.junit.Test)

Example 8 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade in project neo4j by neo4j.

the class QueryLoggerIT method shouldLogTXMetaDataInQueryLog.

@Test
public void shouldLogTXMetaDataInQueryLog() throws Throwable {
    // turn on query logging
    databaseBuilder.setConfig(GraphDatabaseSettings.logs_directory, logsDirectory.getPath());
    databaseBuilder.setConfig(GraphDatabaseSettings.log_queries, Settings.TRUE);
    EmbeddedInteraction db = new EmbeddedInteraction(databaseBuilder, Collections.emptyMap());
    GraphDatabaseFacade graph = db.getLocalGraph();
    db.getLocalUserManager().setUserPassword("neo4j", "123", false);
    EnterpriseSecurityContext subject = db.login("neo4j", "123");
    db.executeQuery(subject, "UNWIND range(0, 10) AS i CREATE (:Foo {p: i})", Collections.emptyMap(), ResourceIterator::close);
    // Set meta data and execute query in transaction
    try (InternalTransaction tx = db.beginLocalTransactionAsUser(subject, KernelTransaction.Type.explicit)) {
        graph.execute("CALL dbms.setTXMetaData( { User: 'Johan' } )", Collections.emptyMap());
        graph.execute("CALL dbms.procedures() YIELD name RETURN name", Collections.emptyMap()).close();
        graph.execute("MATCH (n) RETURN n", Collections.emptyMap()).close();
        graph.execute(QUERY, Collections.emptyMap());
        tx.success();
    }
    // Ensure that old meta data is not retained
    try (InternalTransaction tx = db.beginLocalTransactionAsUser(subject, KernelTransaction.Type.explicit)) {
        graph.execute("CALL dbms.setTXMetaData( { Location: 'Sweden' } )", Collections.emptyMap());
        graph.execute("MATCH ()-[r]-() RETURN count(r)", Collections.emptyMap()).close();
        tx.success();
    }
    db.tearDown();
    // THEN
    List<String> logLines = readAllLines(logFilename);
    assertThat(logLines, hasSize(7));
    assertThat(logLines.get(0), not(containsString("User: 'Johan'")));
    // we don't care if setTXMetaData contains the meta data
    //assertThat( logLines.get( 1 ), containsString( "User: Johan" ) );
    assertThat(logLines.get(2), containsString("User: 'Johan'"));
    assertThat(logLines.get(3), containsString("User: 'Johan'"));
    assertThat(logLines.get(4), containsString("User: 'Johan'"));
    // we want to make sure that the new transaction does not carry old meta data
    assertThat(logLines.get(5), not(containsString("User: 'Johan'")));
    assertThat(logLines.get(6), containsString("Location: 'Sweden'"));
}
Also used : EnterpriseSecurityContext(org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext) EmbeddedInteraction(org.neo4j.server.security.enterprise.auth.EmbeddedInteraction) Matchers.containsString(org.hamcrest.Matchers.containsString) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) ResourceIterator(org.neo4j.graphdb.ResourceIterator) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.Test)

Example 9 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade in project neo4j by neo4j.

the class QueryLoggerIT method shouldNotLogPassword.

@Test
public void shouldNotLogPassword() throws Exception {
    GraphDatabaseFacade database = (GraphDatabaseFacade) databaseBuilder.setConfig(GraphDatabaseSettings.log_queries, Settings.TRUE).setConfig(GraphDatabaseSettings.logs_directory, logsDirectory.getPath()).setConfig(GraphDatabaseSettings.auth_enabled, Settings.TRUE).newGraphDatabase();
    EnterpriseAuthManager authManager = database.getDependencyResolver().resolveDependency(EnterpriseAuthManager.class);
    EnterpriseSecurityContext neo = authManager.login(AuthToken.newBasicAuthToken("neo4j", "neo4j"));
    String query = "CALL dbms.security.changePassword('abc123')";
    try (InternalTransaction tx = database.beginTransaction(KernelTransaction.Type.explicit, neo)) {
        Result res = database.execute(tx, query, Collections.emptyMap());
        res.close();
        tx.success();
    } finally {
        database.shutdown();
    }
    List<String> logLines = readAllLines(logFilename);
    assertEquals(1, logLines.size());
    assertThat(logLines.get(0), containsString("CALL dbms.security.changePassword(******)"));
    assertThat(logLines.get(0), not(containsString("abc123")));
    assertThat(logLines.get(0), containsString(neo.subject().username()));
}
Also used : EnterpriseSecurityContext(org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext) EnterpriseAuthManager(org.neo4j.kernel.enterprise.api.security.EnterpriseAuthManager) Matchers.containsString(org.hamcrest.Matchers.containsString) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 10 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade in project neo4j by neo4j.

the class EmbeddedBuiltInProceduresInteractionTest method shouldNotListAnyQueriesIfNotAuthenticated.

@Test
public void shouldNotListAnyQueriesIfNotAuthenticated() {
    GraphDatabaseFacade graph = neo.getLocalGraph();
    try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.explicit, AnonymousContext.none())) {
        Result result = graph.execute(tx, "CALL dbms.listQueries", Collections.emptyMap());
        assertFalse(result.hasNext());
        tx.success();
    }
}
Also used : GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Aggregations

GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)16 Test (org.junit.Test)11 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 Config (org.neo4j.kernel.configuration.Config)5 GraphDatabaseFacadeFactory (org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory)5 File (java.io.File)4 Result (org.neo4j.graphdb.Result)4 PlatformModule (org.neo4j.kernel.impl.factory.PlatformModule)4 EnterpriseSecurityContext (org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext)3 Map (java.util.Map)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Transaction (org.neo4j.graphdb.Transaction)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)2 EditionModule (org.neo4j.kernel.impl.factory.EditionModule)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1