use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class Neo4jTransactionalContextTest method neverStopsExecutingQueryDuringCommitAndRestartTx.
@Test
void neverStopsExecutingQueryDuringCommitAndRestartTx() throws TransactionFailureException {
// Given
KernelTransaction initialKTX = mockTransaction(statement);
InternalTransaction userTransaction = mock(InternalTransaction.class, new ReturnsDeepStubs());
KernelTransaction.Type transactionType = KernelTransaction.Type.IMPLICIT;
SecurityContext securityContext = SecurityContext.AUTH_DISABLED;
ClientConnectionInfo connectionInfo = ClientConnectionInfo.EMBEDDED_CONNECTION;
when(userTransaction.transactionType()).thenReturn(transactionType);
when(userTransaction.securityContext()).thenReturn(securityContext);
when(userTransaction.terminationReason()).thenReturn(Optional.empty());
when(userTransaction.clientInfo()).thenReturn(connectionInfo);
QueryRegistry initialQueryRegistry = mock(QueryRegistry.class);
ExecutingQuery executingQuery = mock(ExecutingQuery.class);
KernelStatement secondStatement = mock(KernelStatement.class);
KernelTransaction secondKTX = mockTransaction(secondStatement);
QueryRegistry secondQueryRegistry = mock(QueryRegistry.class);
when(transactionFactory.beginKernelTransaction(transactionType, securityContext, connectionInfo)).thenReturn(secondKTX);
when(executingQuery.databaseId()).thenReturn(Optional.of(namedDatabaseId));
when(statement.queryRegistration()).thenReturn(initialQueryRegistry);
when(userTransaction.kernelTransaction()).thenReturn(initialKTX, initialKTX, secondKTX);
when(secondStatement.queryRegistration()).thenReturn(secondQueryRegistry);
Neo4jTransactionalContext context = new Neo4jTransactionalContext(queryService, userTransaction, statement, executingQuery, transactionFactory);
// When
context.commitAndRestartTx();
// Then
Object[] mocks = { userTransaction, initialKTX, initialQueryRegistry, secondQueryRegistry, secondKTX };
InOrder order = Mockito.inOrder(mocks);
// (0) Constructor
order.verify(userTransaction).transactionType();
order.verify(userTransaction).securityContext();
order.verify(userTransaction).clientInfo();
// not terminated check
order.verify(userTransaction).terminationReason();
// (1) Collect stats
order.verify(initialKTX).executionStatistics();
// (3) Register new
order.verify(secondKTX).acquireStatement();
order.verify(secondQueryRegistry).registerExecutingQuery(executingQuery);
// (4) Unregister, and close old
order.verify(initialQueryRegistry).unregisterExecutingQuery(executingQuery);
order.verify(initialKTX).commit();
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class SecurityContextDescriptionTest method shouldMakeNiceDescriptionAuthDisabled.
@Test
void shouldMakeNiceDescriptionAuthDisabled() {
SecurityContext disabled = SecurityContext.AUTH_DISABLED;
assertThat(disabled.description()).isEqualTo("AUTH_DISABLED with FULL");
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class SecurityContextDescriptionTest method shouldMakeNiceDescriptionOverridden.
@Test
void shouldMakeNiceDescriptionOverridden() {
SecurityContext overridden = context.withMode(new OverriddenAccessMode(context.mode(), AccessMode.Static.READ));
assertThat(overridden.description()).isEqualTo("user 'johan' with FULL overridden by READ");
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class SecurityContextDescriptionTest method shouldMakeNiceDescriptionAuthDisabledAndRestricted.
@Test
void shouldMakeNiceDescriptionAuthDisabledAndRestricted() {
SecurityContext disabled = SecurityContext.AUTH_DISABLED;
SecurityContext restricted = disabled.withMode(new RestrictedAccessMode(disabled.mode(), AccessMode.Static.READ));
assertThat(restricted.description()).isEqualTo("AUTH_DISABLED with FULL restricted to READ");
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class AllStoreHolder method callProcedure.
private RawIterator<AnyValue[], ProcedureException> callProcedure(int id, AnyValue[] input, final AccessMode.Static procedureMode, ProcedureCallContext procedureCallContext) throws ProcedureException {
ktx.assertOpen();
AccessMode mode = ktx.securityContext().mode();
if (!mode.allowsExecuteProcedure(id)) {
String message = format("Executing procedure is not allowed for %s.", ktx.securityContext().description());
throw ktx.securityAuthorizationHandler().logAndGetAuthorizationException(ktx.securityContext(), message);
}
final SecurityContext procedureSecurityContext = mode.shouldBoostProcedure(id) ? ktx.securityContext().withMode(new OverriddenAccessMode(mode, procedureMode)).withMode(AdminAccessMode.FULL) : ktx.securityContext().withMode(new RestrictedAccessMode(mode, procedureMode));
final RawIterator<AnyValue[], ProcedureException> procedureCall;
try (KernelTransaction.Revertable ignore = ktx.overrideWith(procedureSecurityContext);
Statement statement = ktx.acquireStatement()) {
procedureCall = globalProcedures.callProcedure(prepareContext(procedureSecurityContext, procedureCallContext), id, input, statement);
}
return createIterator(procedureSecurityContext, procedureCall);
}
Aggregations