use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class OperationsFacade method callProcedure.
private RawIterator<Object[], ProcedureException> callProcedure(QualifiedName name, Object[] input, final AccessMode override) throws ProcedureException {
statement.assertOpen();
final SecurityContext procedureSecurityContext = tx.securityContext().withMode(override);
final RawIterator<Object[], ProcedureException> procedureCall;
try (KernelTransaction.Revertable ignore = tx.overrideWith(procedureSecurityContext)) {
BasicContext ctx = new BasicContext();
ctx.put(Context.KERNEL_TRANSACTION, tx);
ctx.put(Context.THREAD, Thread.currentThread());
ctx.put(Context.SECURITY_CONTEXT, procedureSecurityContext);
procedureCall = procedures.callProcedure(ctx, name, input);
}
return new RawIterator<Object[], ProcedureException>() {
@Override
public boolean hasNext() throws ProcedureException {
try (KernelTransaction.Revertable ignore = tx.overrideWith(procedureSecurityContext)) {
return procedureCall.hasNext();
}
}
@Override
public Object[] next() throws ProcedureException {
try (KernelTransaction.Revertable ignore = tx.overrideWith(procedureSecurityContext)) {
return procedureCall.next();
}
}
};
}
use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class KernelTransactionImplementation method overrideWith.
@Override
public Revertable overrideWith(SecurityContext context) {
SecurityContext oldContext = this.securityContext;
this.securityContext = context;
return () -> this.securityContext = oldContext;
}
use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class KernelTransactionsTest method exceptionWhenStartingNewTransactionOnShutdownInstance.
@Test
public void exceptionWhenStartingNewTransactionOnShutdownInstance() throws Throwable {
KernelTransactions kernelTransactions = newKernelTransactions();
SecurityContext securityContext = mock(SecurityContext.class);
availabilityGuard.shutdown();
expectedException.expect(DatabaseShutdownException.class);
kernelTransactions.newInstance(KernelTransaction.Type.explicit, securityContext, 0L);
}
use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class KernelTransactionsTest method startNewTransactionOnRestartedKErnelTransactions.
@Test
public void startNewTransactionOnRestartedKErnelTransactions() throws Throwable {
KernelTransactions kernelTransactions = newKernelTransactions();
SecurityContext securityContext = mock(SecurityContext.class);
kernelTransactions.stop();
kernelTransactions.start();
assertNotNull("New transaction created by restarted kernel transactions component.", kernelTransactions.newInstance(KernelTransaction.Type.explicit, securityContext, 0L));
}
use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class TransactionEventsIT method shouldGetSpecifiedUsernameAndMetaDataInTXData.
@Test
public void shouldGetSpecifiedUsernameAndMetaDataInTXData() {
final AtomicReference<String> usernameRef = new AtomicReference<>();
final AtomicReference<Map<String, Object>> metaDataRef = new AtomicReference<>();
db.registerTransactionEventHandler(getBeforeCommitHandler(txData -> {
usernameRef.set(txData.username());
metaDataRef.set(txData.metaData());
}));
AuthSubject subject = mock(AuthSubject.class);
when(subject.username()).thenReturn("Christof");
SecurityContext securityContext = new SecurityContext.Frozen(subject, AccessMode.Static.WRITE);
Map<String, Object> metadata = genericMap("username", "joe");
runTransaction(securityContext, metadata);
assertThat("Should have specified username", usernameRef.get(), equalTo("Christof"));
assertThat("Should have metadata with specified username", metaDataRef.get(), equalTo(metadata));
}
Aggregations