Search in sources :

Example 6 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction 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 7 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class Start method createTransactionContext.

private TransactionalContext createTransactionContext(String queryText, Map<String, Object> queryParameters, Session session) {
    DependencyResolver dependencyResolver = getDependencyResolver();
    GraphDatabaseQueryService graph = dependencyResolver.resolveDependency(GraphDatabaseQueryService.class);
    TransactionalContextFactory contextFactory = Neo4jTransactionalContextFactory.create(graph, new PropertyContainerLocker());
    InternalTransaction transaction = graph.beginTransaction(KernelTransaction.Type.implicit, SecurityContext.AUTH_DISABLED);
    return contextFactory.newContext(new ShellConnectionInfo(session.getId()), transaction, queryText, queryParameters);
}
Also used : PropertyContainerLocker(org.neo4j.kernel.impl.coreapi.PropertyContainerLocker) ShellConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.ShellConnectionInfo) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TransactionalContextFactory(org.neo4j.kernel.impl.query.TransactionalContextFactory) Neo4jTransactionalContextFactory(org.neo4j.kernel.impl.query.Neo4jTransactionalContextFactory) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 8 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class ExecutionEngineTests method shouldConvertListsAndMapsWhenPassingFromScalaToJava.

@Test
public void shouldConvertListsAndMapsWhenPassingFromScalaToJava() throws Exception {
    GraphDatabaseQueryService graph = new GraphDatabaseCypherService(this.database.getGraphDatabaseAPI());
    KernelAPI kernelAPI = graph.getDependencyResolver().resolveDependency(KernelAPI.class);
    Monitors monitors = graph.getDependencyResolver().resolveDependency(Monitors.class);
    NullLogProvider nullLogProvider = NullLogProvider.getInstance();
    CommunityCompatibilityFactory compatibilityFactory = new CommunityCompatibilityFactory(graph, kernelAPI, monitors, nullLogProvider);
    ExecutionEngine executionEngine = new ExecutionEngine(graph, nullLogProvider, compatibilityFactory);
    Result result;
    try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.implicit, SecurityContext.AUTH_DISABLED)) {
        String query = "RETURN { key : 'Value' , collectionKey: [{ inner: 'Map1' }, { inner: 'Map2' }]}";
        TransactionalContext tc = createTransactionContext(graph, tx, query);
        result = executionEngine.executeQuery(query, NO_PARAMS, tc);
        tx.success();
    }
    Map firstRowValue = (Map) result.next().values().iterator().next();
    assertThat(firstRowValue.get("key"), is("Value"));
    List theList = (List) firstRowValue.get("collectionKey");
    assertThat(((Map) theList.get(0)).get("inner"), is("Map1"));
    assertThat(((Map) theList.get(1)).get("inner"), is("Map2"));
}
Also used : GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) GraphDatabaseCypherService(org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Monitors(org.neo4j.kernel.monitoring.Monitors) NullLogProvider(org.neo4j.logging.NullLogProvider) CommunityCompatibilityFactory(org.neo4j.cypher.internal.CommunityCompatibilityFactory) List(java.util.List) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) KernelAPI(org.neo4j.kernel.api.KernelAPI) Map(java.util.Map) Test(org.junit.Test)

Example 9 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction 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)

Example 10 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class ConfiguredAuthScenariosInteractionTestBase method shouldWarnWhenUsingNativeAndOtherProvider.

@Test
public void shouldWarnWhenUsingNativeAndOtherProvider() throws Throwable {
    configuredSetup(stringMap(SecuritySettings.auth_providers.name(), "native ,LDAP"));
    assertSuccess(adminSubject, "CALL dbms.security.listUsers", r -> assertKeyIsMap(r, "username", "roles", userList));
    GraphDatabaseFacade localGraph = neo.getLocalGraph();
    InternalTransaction transaction = localGraph.beginTransaction(KernelTransaction.Type.explicit, StandardEnterpriseSecurityContext.AUTH_DISABLED);
    Result result = localGraph.execute(transaction, "EXPLAIN CALL dbms.security.listUsers", Collections.emptyMap());
    String description = String.format("%s (%s)", Status.Procedure.ProcedureWarning.code().description(), "dbms.security.listUsers only applies to native users.");
    assertThat(containsNotification(result, description), equalTo(true));
    transaction.success();
    transaction.close();
}
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

InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)126 Transaction (org.neo4j.graphdb.Transaction)58 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)53 Test (org.junit.jupiter.api.Test)46 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 Node (org.neo4j.graphdb.Node)16 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 Result (org.neo4j.graphdb.Result)12 TokenRead (org.neo4j.internal.kernel.api.TokenRead)11 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)8 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)7 Relationship (org.neo4j.graphdb.Relationship)6 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)6 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)5