protected Transaction newTransaction() throws TransactionFailureException { transaction = kernel.beginTransaction( implicit, AnonymousContext.read() ); return transaction; }
@Test public void failWhenCallingNonExistingProcedures() { try { dbmsOperations().procedureCallDbms( procedureName( "dbms", "iDoNotExist" ), new Object[0], dependencyResolver, AnonymousContext.none().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), resourceTracker ); fail( "This should never get here" ); } catch ( Exception e ) { // Then assertThat( e.getClass(), equalTo( ProcedureException.class ) ); } }
private void runTransaction() { runTransaction( AnonymousContext.write(), Collections.emptyMap() ); }
@Test public void shouldGetEmptyUsernameForAnonymousContext() { when( transaction.securityContext() ).thenReturn( AnonymousContext.read().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ) ); TxStateTransactionDataSnapshot transactionDataSnapshot = snapshot(); assertEquals( "", transactionDataSnapshot.username() ); }
protected TokenWrite tokenWriteInNewTransaction() throws KernelException { transaction = kernel.beginTransaction( implicit, AnonymousContext.writeToken() ); return transaction.tokenWrite(); }
public static LoginContext getLoginContextFromUserPrincipal( Principal principal ) { if ( principal instanceof DelegatingPrincipal ) { return ((DelegatingPrincipal) principal).getLoginContext(); } // If whitelisted uris can start transactions we cannot throw exception here //throw new IllegalArgumentException( "Tried to get access mode on illegal user principal" ); return AnonymousContext.none(); }
public static AnonymousContext read() { return new AnonymousContext( AccessMode.Static.READ ); }
public void setNodeProperties( long nodeId, Map<String, Object> properties ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) ) { Node node = database.getGraph().getNodeById( nodeId ); for ( Map.Entry<String, Object> propertyEntry : properties.entrySet() ) { node.setProperty( propertyEntry.getKey(), propertyEntry.getValue() ); } tx.success(); } }
private static KernelTransaction getKernelTransaction( KernelTransactions transactions ) { return transactions.newInstance( KernelTransaction.Type.implicit, AnonymousContext.none(), 0L ); }
public static AnonymousContext full() { return new AnonymousContext( AccessMode.Static.FULL ); }
protected Procedures procs() throws TransactionFailureException { transaction = kernel.beginTransaction( implicit, AnonymousContext.read() ); return transaction.procedures(); }
protected Write dataWriteInNewTransaction() throws KernelException { transaction = kernel.beginTransaction( implicit, AnonymousContext.write() ); return transaction.dataWrite(); }
public void setRelationshipProperties( long relationshipId, Map<String, Object> properties ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) ) { Relationship relationship = database.getGraph().getRelationshipById( relationshipId ); for ( Map.Entry<String, Object> propertyEntry : properties.entrySet() ) { relationship.setProperty( propertyEntry.getKey(), propertyEntry.getValue() ); } tx.success(); } }
@Test public void shouldFailWhenChangePasswordWithStaticAccessModeInDbmsMode() throws Throwable { // Given Object[] inputArray = new Object[1]; inputArray[0] = "newPassword"; // Then exception.expect( ProcedureException.class ); exception.expectMessage( "Anonymous cannot change password" ); // When dbmsOperations().procedureCallDbms( procedureName( "dbms", "security", "changePassword" ), inputArray, dependencyResolver, AnonymousContext.none().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), resourceTracker ); }
@Test public void incrementalUserTransactionId() throws Throwable { KernelTransactions kernelTransactions = newKernelTransactions(); try ( KernelTransaction kernelTransaction = kernelTransactions .newInstance( KernelTransaction.Type.explicit, AnonymousContext.none(), 0L ) ) { assertEquals( 1, kernelTransactions.activeTransactions().iterator().next().getUserTransactionId() ); } try ( KernelTransaction kernelTransaction = kernelTransactions .newInstance( KernelTransaction.Type.explicit, AnonymousContext.none(), 0L ) ) { assertEquals( 2, kernelTransactions.activeTransactions().iterator().next().getUserTransactionId() ); } try ( KernelTransaction kernelTransaction = kernelTransactions .newInstance( KernelTransaction.Type.explicit, AnonymousContext.none(), 0L ) ) { assertEquals( 3, kernelTransactions.activeTransactions().iterator().next().getUserTransactionId() ); } }
public static AnonymousContext none() { return new AnonymousContext( AccessMode.Static.NONE ); }
public int getNumberOfNodes() { Kernel kernel = database.getGraph().getDependencyResolver().resolveDependency( Kernel.class ); try ( org.neo4j.internal.kernel.api.Transaction tx = kernel.beginTransaction( implicit, AnonymousContext.read() ) ) { return Math.toIntExact( tx.dataRead().nodesGetCount() ); } catch ( TransactionFailureException e ) { throw new RuntimeException( e ); } }
@Test public void shouldNotAllowSchemaWriteAccessInWriteMode() throws Throwable { // Given KernelTransactionImplementation tx = newTransaction( AnonymousContext.write() ); // Expect exception.expect( AuthorizationViolationException.class ); // When tx.schemaWrite(); }
public long createNode( Map<String, Object> properties, Label... labels ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) ) { Node node = database.getGraph().createNode( labels ); for ( Map.Entry<String, Object> entry : properties.entrySet() ) { node.setProperty( entry.getKey(), entry.getValue() ); } tx.success(); return node.getId(); } }