Class OperationAuthoriser

  • All Implemented Interfaces:
    GraphHook

    public class OperationAuthoriser
    extends Object
    implements GraphHook
    An OperationAuthoriser is a GraphHook that checks a user is authorised to execute an operation chain. This class requires a map of operation authorisations.
    • Constructor Detail

      • OperationAuthoriser

        public OperationAuthoriser()
    • Method Detail

      • preExecute

        public void preExecute​(OperationChain<?> opChain,
                               Context context)
        Checks the Operations in the provided OperationChain are allowed to be executed by the user. This is done by checking the user's auths against the operation auths. If an operation cannot be executed then an IllegalAccessError is thrown.
        Specified by:
        preExecute in interface GraphHook
        Parameters:
        context - the user to authorise.
        opChain - the operation chain.
      • postExecute

        public <T> T postExecute​(T result,
                                 OperationChain<?> opChain,
                                 Context context)
        Description copied from interface: GraphHook
        Called from Graph after an OperationChain is executed.
        Specified by:
        postExecute in interface GraphHook
        Type Parameters:
        T - the result type
        Parameters:
        result - the result from the operation chain
        opChain - the OperationChain that was executed. This can be modified/optimised in any GraphHook.
        context - the Context in which the operation chain was executed. The context also holds a reference to the original operation chain.
        Returns:
        result object
      • onFailure

        public <T> T onFailure​(T result,
                               OperationChain<?> opChain,
                               Context context,
                               Exception e)
        Description copied from interface: GraphHook
        Called from Graph if an error occurs whilst executing the OperationChain.
        Specified by:
        onFailure in interface GraphHook
        Type Parameters:
        T - the result type
        Parameters:
        result - the result from the operation chain - likely to be null.
        opChain - the OperationChain that was executed. This can be modified/optimised in any GraphHook.
        context - the Context in which the operation chain was executed. The context also holds a reference to the original operation chain.
        e - the exception
        Returns:
        result object
      • addAuths

        public void addAuths​(Class<? extends Operation> opClass,
                             String... auths)
        Add operation authorisations for a given operation class. This can be called multiple times for the same operation class and the authorisations will be appended.
        Parameters:
        opClass - the operation class
        auths - the authorisations
      • getAllAuths

        public Set<String> getAllAuths()