Class SecureTransaction


  • public final class SecureTransaction
    extends java.lang.Object
    Manage transactions by making sure that the correct SecurityContext is applied.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <E extends java.lang.Exception>
      void
      accept​(SecureTransaction.TxConsumer<E> block)
      Run some code within a new Transaction under the managed SecurityContext.
      org.neo4j.kernel.internal.GraphDatabaseAPI api()
      Returns the GraphDatabaseAPI provided to this instance.
      <T,​E extends java.lang.Exception>
      T
      apply​(SecureTransaction.TxFunction<T,​E> block)
      Run some code within a new Transaction under the managed SecurityContext.
      void close()
      Closes the underlying transaction.
      SecureTransaction fork()
      Return a new SecureTransaction that owns a newly created top-level Transaction.
      static SecureTransaction of​(org.neo4j.kernel.internal.GraphDatabaseAPI api, org.neo4j.graphdb.Transaction top)
      Creates a new SecureTransaction with the same SecurityContext as the provided Transaction.
      org.neo4j.kernel.api.KernelTransaction topLevelKernelTransaction()
      Returns the KernelTransaction for the provided top-level Transaction.
      SecureTransaction withRestrictedAccess​(org.neo4j.internal.kernel.api.security.AccessMode.Static accessMode)
      Returns a new SecureTransaction restricted by the provided AccessMode.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • of

        public static SecureTransaction of​(org.neo4j.kernel.internal.GraphDatabaseAPI api,
                                           org.neo4j.graphdb.Transaction top)
        Creates a new SecureTransaction with the same SecurityContext as the provided Transaction. If this instance is closed, the supplied transaction will be closed as well.
      • apply

        public <T,​E extends java.lang.Exception> T apply​(SecureTransaction.TxFunction<T,​E> block)
                                                        throws E extends java.lang.Exception
        Run some code within a new Transaction under the managed SecurityContext. The new transaction is closed afterwards and any resource that is tied to the lifecycle of that transaction will throw a NotInTransactionException upon access.
        Throws:
        E extends java.lang.Exception
      • accept

        public <E extends java.lang.Exception> void accept​(SecureTransaction.TxConsumer<E> block)
                                                    throws E extends java.lang.Exception
        Run some code within a new Transaction under the managed SecurityContext. The new transaction is closed afterwards.
        Throws:
        E extends java.lang.Exception
      • api

        public org.neo4j.kernel.internal.GraphDatabaseAPI api()
        Returns the GraphDatabaseAPI provided to this instance.
      • topLevelKernelTransaction

        public org.neo4j.kernel.api.KernelTransaction topLevelKernelTransaction()
        Returns the KernelTransaction for the provided top-level Transaction.
      • withRestrictedAccess

        public SecureTransaction withRestrictedAccess​(org.neo4j.internal.kernel.api.security.AccessMode.Static accessMode)
        Returns a new SecureTransaction restricted by the provided AccessMode. The mode only restricts but does not override the given SecurityContext, i.e. you cannot grant more access.

        One use-case is to restrict the access to AccessMode.Static.READ to make sure that only read-only queries can be executed.

        A new instance is returned, this instance remains untouched. However, the new instance has ownership of the same top-level Transaction within this instance. Closing it would also close this instance's top-level transaction. To decouple the transaction, call fork() on the returned instance.

      • fork

        public SecureTransaction fork()
        Return a new SecureTransaction that owns a newly created top-level Transaction. The returned instance will operate under the same SecurityContext as this instance.

        This is intended for when you need to keep track of a new transaction for a longer time, in which case you can use topLevelKernelTransaction() to get the underlying transaction.

      • close

        public void close()
        Closes the underlying transaction.