use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class KernelTransactionsTest method exceptionWhenStartingNewTransactionOnStoppedKernelTransactions.
@Test
public void exceptionWhenStartingNewTransactionOnStoppedKernelTransactions() throws Throwable {
KernelTransactions kernelTransactions = newKernelTransactions();
SecurityContext securityContext = mock(SecurityContext.class);
t2.execute((OtherThreadExecutor.WorkerCommand<Void, Void>) state -> {
stopKernelTransactions(kernelTransactions);
return null;
}).get();
expectedException.expect(IllegalStateException.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 shouldNotLeakTransactionOnSecurityContextFreezeFailure.
@Test
public void shouldNotLeakTransactionOnSecurityContextFreezeFailure() throws Throwable {
KernelTransactions kernelTransactions = newKernelTransactions();
SecurityContext securityContext = mock(SecurityContext.class);
when(securityContext.freeze()).thenThrow(new AuthorizationExpiredException("Freeze failed."));
assertException(() -> kernelTransactions.newInstance(KernelTransaction.Type.explicit, securityContext, 0L), AuthorizationExpiredException.class, "Freeze failed.");
assertThat("We should not have any transaction", kernelTransactions.activeTransactions(), is(empty()));
}
use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class TransactionalRequestDispatcher method dispatch.
@Override
public void dispatch(Object o, final HttpContext httpContext) {
RepresentationWriteHandler representationWriteHandler = DO_NOTHING;
SecurityContext securityContext = AuthorizedRequestWrapper.getSecurityContextFromHttpContext(httpContext);
final GraphDatabaseFacade graph = database.getGraph();
if (o instanceof RestfulGraphDatabase) {
RestfulGraphDatabase restfulGraphDatabase = (RestfulGraphDatabase) o;
final Transaction transaction = graph.beginTransaction(KernelTransaction.Type.implicit, securityContext);
restfulGraphDatabase.getOutputFormat().setRepresentationWriteHandler(representationWriteHandler = new CommitOnSuccessfulStatusCodeRepresentationWriteHandler(httpContext, transaction));
} else if (o instanceof BatchOperationService) {
BatchOperationService batchOperationService = (BatchOperationService) o;
final Transaction transaction = graph.beginTransaction(KernelTransaction.Type.explicit, securityContext);
batchOperationService.setRepresentationWriteHandler(representationWriteHandler = new CommitOnSuccessfulStatusCodeRepresentationWriteHandler(httpContext, transaction));
} else if (o instanceof CypherService) {
CypherService cypherService = (CypherService) o;
final Transaction transaction = graph.beginTransaction(KernelTransaction.Type.explicit, securityContext);
cypherService.getOutputFormat().setRepresentationWriteHandler(representationWriteHandler = new CommitOnSuccessfulStatusCodeRepresentationWriteHandler(httpContext, transaction));
} else if (o instanceof DatabaseMetadataService) {
DatabaseMetadataService databaseMetadataService = (DatabaseMetadataService) o;
final Transaction transaction = graph.beginTransaction(KernelTransaction.Type.implicit, securityContext);
databaseMetadataService.setRepresentationWriteHandler(representationWriteHandler = new RepresentationWriteHandler() {
@Override
public void onRepresentationStartWriting() {
// do nothing
}
@Override
public void onRepresentationWritten() {
// doesn't need to commit
}
@Override
public void onRepresentationFinal() {
transaction.close();
}
});
} else if (o instanceof ExtensionService) {
ExtensionService extensionService = (ExtensionService) o;
extensionService.getOutputFormat().setRepresentationWriteHandler(representationWriteHandler = new RepresentationWriteHandler() {
Transaction transaction;
@Override
public void onRepresentationStartWriting() {
transaction = graph.beginTransaction(KernelTransaction.Type.implicit, securityContext);
}
@Override
public void onRepresentationWritten() {
// doesn't need to commit
}
@Override
public void onRepresentationFinal() {
if (transaction != null) {
transaction.close();
}
}
});
}
try {
requestDispatcher.dispatch(o, httpContext);
} catch (RuntimeException e) {
representationWriteHandler.onRepresentationFinal();
throw e;
}
}
use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class MultiRealmAuthManagerTest method shouldHaveNoPermissionsAfterLogout.
@Test
public void shouldHaveNoPermissionsAfterLogout() throws Throwable {
// Given
createTestUsers();
manager.start();
// When
SecurityContext securityContext = manager.login(authToken("morpheus", "abc123"));
assertTrue(securityContext.mode().allowsReads());
assertTrue(securityContext.mode().allowsWrites());
assertTrue(securityContext.mode().allowsSchemaWrites());
securityContext.subject().logout();
// Then
assertFalse(securityContext.mode().allowsReads());
assertFalse(securityContext.mode().allowsWrites());
assertFalse(securityContext.mode().allowsSchemaWrites());
}
use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class MultiRealmAuthManagerTest method userWithPublisherRoleShouldHaveCorrectPermissions.
@Test
public void userWithPublisherRoleShouldHaveCorrectPermissions() throws Throwable {
// Given
createTestUsers();
manager.start();
// When
SecurityContext securityContext = manager.login(authToken("tank", "abc123"));
// Then
assertTrue("should allow reads", securityContext.mode().allowsReads());
assertTrue("should allow writes", securityContext.mode().allowsWrites());
assertFalse("should _not_ allow schema writes", securityContext.mode().allowsSchemaWrites());
}
Aggregations