Search in sources :

Example 31 with SecurityContext

use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.

the class TransactionalService method executeStatementsInNewTransaction.

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response executeStatementsInNewTransaction(final InputStream input, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
    try {
        usage.get(features).flag(http_tx_endpoint);
        SecurityContext securityContext = AuthorizedRequestWrapper.getSecurityContextFromHttpServletRequest(request);
        long customTransactionTimeout = HttpHeaderUtils.getTransactionTimeout(request, log);
        TransactionHandle transactionHandle = facade.newTransactionHandle(uriScheme, false, securityContext, customTransactionTimeout);
        return createdResponse(transactionHandle, executeStatements(input, transactionHandle, uriInfo.getBaseUri(), request));
    } catch (TransactionLifecycleException e) {
        return invalidTransaction(e, uriInfo.getBaseUri());
    }
}
Also used : SecurityContext(org.neo4j.kernel.api.security.SecurityContext) TransactionHandle(org.neo4j.server.rest.transactional.TransactionHandle) TransactionLifecycleException(org.neo4j.server.rest.transactional.error.TransactionLifecycleException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 32 with SecurityContext

use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.

the class TransactionalService method commitNewTransaction.

@POST
@Path("/commit")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Response commitNewTransaction(final InputStream input, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
    final TransactionHandle transactionHandle;
    try {
        SecurityContext securityContext = AuthorizedRequestWrapper.getSecurityContextFromHttpServletRequest(request);
        long customTransactionTimeout = HttpHeaderUtils.getTransactionTimeout(request, log);
        transactionHandle = facade.newTransactionHandle(uriScheme, true, securityContext, customTransactionTimeout);
    } catch (TransactionLifecycleException e) {
        return invalidTransaction(e, uriInfo.getBaseUri());
    }
    final StreamingOutput streamingResults = executeStatementsAndCommit(input, transactionHandle, uriInfo.getBaseUri(), request);
    return okResponse(streamingResults);
}
Also used : TransactionHandle(org.neo4j.server.rest.transactional.TransactionHandle) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) StreamingOutput(javax.ws.rs.core.StreamingOutput) TransactionLifecycleException(org.neo4j.server.rest.transactional.error.TransactionLifecycleException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 33 with SecurityContext

use of org.neo4j.kernel.api.security.SecurityContext in project neo4j by neo4j.

the class CypherExecutorTest method setUpMocks.

private void setUpMocks() {
    database = mock(Database.class);
    databaseFacade = mock(GraphDatabaseFacade.class);
    resolver = mock(DependencyResolver.class);
    executionEngine = mock(ExecutionEngine.class);
    statementBridge = mock(ThreadToStatementContextBridge.class);
    databaseQueryService = mock(GraphDatabaseQueryService.class);
    kernelTransaction = mock(KernelTransaction.class);
    statement = mock(Statement.class);
    request = mock(HttpServletRequest.class);
    InternalTransaction transaction = new TopLevelTransaction(kernelTransaction, () -> statement);
    SecurityContext securityContext = AUTH_DISABLED;
    KernelTransaction.Type type = KernelTransaction.Type.implicit;
    QueryRegistryOperations registryOperations = mock(QueryRegistryOperations.class);
    when(statement.queryRegistration()).thenReturn(registryOperations);
    when(statementBridge.get()).thenReturn(statement);
    when(kernelTransaction.securityContext()).thenReturn(securityContext);
    when(kernelTransaction.transactionType()).thenReturn(type);
    when(database.getGraph()).thenReturn(databaseFacade);
    when(databaseFacade.getDependencyResolver()).thenReturn(resolver);
    when(resolver.resolveDependency(QueryExecutionEngine.class)).thenReturn(executionEngine);
    when(resolver.resolveDependency(ThreadToStatementContextBridge.class)).thenReturn(statementBridge);
    when(resolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(databaseQueryService);
    when(databaseQueryService.beginTransaction(type, securityContext)).thenReturn(transaction);
    when(databaseQueryService.beginTransaction(type, securityContext, CUSTOM_TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(transaction);
    when(databaseQueryService.getDependencyResolver()).thenReturn(resolver);
    when(request.getScheme()).thenReturn("http");
    when(request.getRemoteAddr()).thenReturn("127.0.0.1");
    when(request.getRemotePort()).thenReturn(5678);
    when(request.getServerName()).thenReturn("127.0.0.1");
    when(request.getServerPort()).thenReturn(7474);
    when(request.getRequestURI()).thenReturn("/");
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Statement(org.neo4j.kernel.api.Statement) QueryRegistryOperations(org.neo4j.kernel.api.QueryRegistryOperations) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) DependencyResolver(org.neo4j.graphdb.DependencyResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) ExecutionEngine(org.neo4j.cypher.internal.javacompat.ExecutionEngine) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade)

Aggregations

SecurityContext (org.neo4j.kernel.api.security.SecurityContext)33 Test (org.junit.Test)20 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)6 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)4 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 IOException (java.io.IOException)2 Principal (java.security.Principal)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 InOrder (org.mockito.InOrder)2 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)2 Transaction (org.neo4j.graphdb.Transaction)2 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)2 Statement (org.neo4j.kernel.api.Statement)2 InvalidArgumentsException (org.neo4j.kernel.api.exceptions.InvalidArgumentsException)2 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)2 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)2 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)2