use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class AllStoreHolder method createAggregationFunction.
private UserAggregator createAggregationFunction(int id) throws ProcedureException {
ktx.assertOpen();
AccessMode mode = ktx.securityContext().mode();
if (!globalProcedures.isBuiltInAggregatingFunction(id) && !mode.allowsExecuteAggregatingFunction(id)) {
String message = format("Executing a user defined aggregating function is not allowed for %s.", ktx.securityContext().description());
throw ktx.securityAuthorizationHandler().logAndGetAuthorizationException(ktx.securityContext(), message);
}
final SecurityContext securityContext = mode.shouldBoostAggregatingFunction(id) ? ktx.securityContext().withMode(new OverriddenAccessMode(mode, AccessMode.Static.READ)) : ktx.securityContext().withMode(new RestrictedAccessMode(mode, AccessMode.Static.READ));
try (KernelTransaction.Revertable ignore = ktx.overrideWith(securityContext)) {
UserAggregator aggregator = globalProcedures.createAggregationFunction(prepareContext(securityContext, ProcedureCallContext.EMPTY), id);
return new UserAggregator() {
@Override
public void update(AnyValue[] input) throws ProcedureException {
try (KernelTransaction.Revertable ignore = ktx.overrideWith(securityContext)) {
aggregator.update(input);
}
}
@Override
public AnyValue result() throws ProcedureException {
try (KernelTransaction.Revertable ignore = ktx.overrideWith(securityContext)) {
return aggregator.result();
}
}
};
}
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class TxStateTransactionDataViewTest method shouldAccessUsernameFromAuthSubject.
@Test
void shouldAccessUsernameFromAuthSubject() {
AuthSubject authSubject = mock(AuthSubject.class);
when(authSubject.username()).thenReturn("Christof");
when(transaction.securityContext()).thenReturn(new SecurityContext(authSubject, AccessMode.Static.FULL, EMBEDDED_CONNECTION, null));
TxStateTransactionDataSnapshot transactionDataSnapshot = snapshot();
assertEquals("Christof", transactionDataSnapshot.username());
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldIncludeAddedRelationshipsByTypeAndDirection.
@Test
void shouldIncludeAddedRelationshipsByTypeAndDirection() throws Exception {
int typeId1;
int typeId2;
long relationship1;
long relationship2;
long sourceNode;
long targetNode;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
typeId1 = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
typeId2 = tx.tokenWrite().relationshipTypeGetOrCreateForName("R2");
sourceNode = write.nodeCreate();
relationship1 = write.relationshipCreate(sourceNode, typeId1, write.nodeCreate());
relationship2 = write.relationshipCreate(sourceNode, typeId2, write.nodeCreate());
targetNode = write.nodeCreate();
tx.commit();
}
SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
try (KernelTransaction tx = beginTransaction(loginContext);
NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
Write write = tx.dataWrite();
// OUTGOING :R
long r1 = write.relationshipCreate(sourceNode, typeId1, targetNode);
// INCOMING :R
long r2 = write.relationshipCreate(targetNode, typeId1, sourceNode);
// LOOP :R
long r3 = write.relationshipCreate(sourceNode, typeId1, sourceNode);
// OUTGOING :R2
long r4 = write.relationshipCreate(sourceNode, typeId2, targetNode);
// INCOMING :R2
long r5 = write.relationshipCreate(targetNode, typeId2, sourceNode);
// LOOP :R2
long r6 = write.relationshipCreate(sourceNode, typeId2, sourceNode);
org.neo4j.internal.kernel.api.Read read = tx.dataRead();
read.singleNode(sourceNode, node);
assertTrue(node.next());
assertRelationships(node, traversal, ALL_RELATIONSHIPS, relationship1, relationship2, r1, r2, r3, r4, r5, r6);
assertRelationships(node, traversal, selection(OUTGOING), relationship1, relationship2, r1, r3, r4, r6);
assertRelationships(node, traversal, selection(typeId1, BOTH), relationship1, r1, r2, r3);
assertRelationships(node, traversal, selection(typeId1, OUTGOING), relationship1, r1, r3);
assertRelationships(node, traversal, selection(typeId1, INCOMING), r2, r3);
assertRelationships(node, traversal, selection(typeId2, BOTH), relationship2, r4, r5, r6);
assertRelationships(node, traversal, selection(typeId2, OUTGOING), relationship2, r4, r6);
assertRelationships(node, traversal, selection(typeId2, INCOMING), r5, r6);
assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, BOTH), relationship1, relationship2, r1, r2, r3, r4, r5, r6);
assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, OUTGOING), relationship1, relationship2, r1, r3, r4, r6);
assertRelationships(node, traversal, selection(new int[] { typeId1, typeId2 }, INCOMING), r2, r3, r5, r6);
}
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldCountNewRelationshipsRestrictedUser.
@Test
void shouldCountNewRelationshipsRestrictedUser() throws Exception {
int relationship;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
relationship = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
write.relationshipCreate(write.nodeCreate(), relationship, write.nodeCreate());
tx.commit();
}
SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
try (KernelTransaction tx = beginTransaction(loginContext)) {
Write write = tx.dataWrite();
write.relationshipCreate(write.nodeCreate(), relationship, write.nodeCreate());
long countsTxState = tx.dataRead().countsForRelationship(-1, relationship, -1);
long countsNoTxState = tx.dataRead().countsForRelationshipWithoutTxState(-1, relationship, -1);
assertEquals(2, countsTxState);
assertEquals(1, countsNoTxState);
}
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldNotCountRemovedRelationshipsRestrictedUser.
@Test
void shouldNotCountRemovedRelationshipsRestrictedUser() throws Exception {
int relationshipId;
long relationship;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
relationshipId = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
relationship = write.relationshipCreate(write.nodeCreate(), relationshipId, write.nodeCreate());
tx.commit();
}
SecurityContext loginContext = new SecurityContext(AuthSubject.AUTH_DISABLED, new TestAccessMode(true, false, true, false), EMBEDDED_CONNECTION, null);
try (KernelTransaction tx = beginTransaction(loginContext)) {
Write write = tx.dataWrite();
write.relationshipDelete(relationship);
long countsTxState = tx.dataRead().countsForRelationship(-1, relationshipId, -1);
long countsNoTxState = tx.dataRead().countsForRelationshipWithoutTxState(-1, relationshipId, -1);
assertEquals(0, countsTxState);
assertEquals(1, countsNoTxState);
}
}
Aggregations