Class PeerIdentity


  • public abstract class PeerIdentity
    extends Object
    A peer's authenticated identity.
    Author:
    David M. Lloyd
    • Constructor Detail

      • PeerIdentity

        protected PeerIdentity​(PeerIdentity.Configuration configuration,
                               Principal peerPrincipal)
        Construct a new instance.
        Parameters:
        configuration - the opaque configuration (must not be null)
        peerPrincipal - the peer principal (must not be null)
    • Method Detail

      • preAssociate

        protected void preAssociate()
        Perform an optional pre-association action, called before association with the current thread.
      • postAssociate

        protected void postAssociate()
        Perform an optional post-association action, called after association with the current thread has completed.
      • safePostAssociate

        private void safePostAssociate()
      • isSamePeerIdentityContext

        public boolean isSamePeerIdentityContext​(PeerIdentity other)
        Determine if the peer identity context of this identity is the same as that of the given identity.
        Parameters:
        other - the other peer identity
        Returns:
        true if the identities share a context, false otherwise
      • runAs

        public void runAs​(Runnable runnable)
        Run an action under this identity.
        Parameters:
        runnable - the action to run
      • runAs

        public <T> T runAs​(Callable<T> callable)
                    throws Exception
        Run an action under this identity.
        Type Parameters:
        T - the action return type
        Parameters:
        callable - the action to run
        Returns:
        the action result (may be null)
        Throws:
        PrivilegedActionException - if the action fails
        Exception
      • runAs

        public <T> T runAs​(PrivilegedAction<T> action)
        Run an action under this identity.
        Type Parameters:
        T - the action return type
        Parameters:
        action - the action to run
        Returns:
        the action result (may be null)
      • runAs

        public <T,​P> T runAs​(P parameter,
                                   ParametricPrivilegedAction<T,​P> action)
        Run an action under this identity.
        Type Parameters:
        T - the action return type
        P - the action parameter type
        Parameters:
        parameter - the parameter to pass to the action
        action - the action to run
        Returns:
        the action result (may be null)
      • runAs

        public <T,​P> T runAs​(P parameter,
                                   ParametricPrivilegedExceptionAction<T,​P> action)
                            throws PrivilegedActionException
        Run an action under this identity.
        Type Parameters:
        T - the action return type
        P - the action parameter type
        Parameters:
        parameter - the parameter to pass to the action
        action - the action to run
        Returns:
        the action result (may be null)
        Throws:
        PrivilegedActionException - if the action fails
      • runAsFunction

        public <T,​R> R runAsFunction​(T parameter,
                                           Function<T,​R> action)
        Run an action under this identity.
        Type Parameters:
        T - the action parameter type
        R - the action return type
        Parameters:
        parameter - the parameter to pass to the action
        action - the action to run
        Returns:
        the action result (may be null)
      • runAsFunction

        public <T,​U,​R> R runAsFunction​(T parameter1,
                                                   U parameter2,
                                                   BiFunction<T,​U,​R> action)
        Run an action under this identity.
        Type Parameters:
        T - the action first parameter type
        U - the action second parameter type
        R - the action return type
        Parameters:
        parameter1 - the first parameter to pass to the action
        parameter2 - the second parameter to pass to the action
        action - the action to run
        Returns:
        the action result (may be null)
      • runAsConsumer

        public <T> void runAsConsumer​(T parameter,
                                      Consumer<T> action)
        Run an action under this identity.
        Type Parameters:
        T - the action parameter type
        Parameters:
        parameter - the parameter to pass to the action
        action - the action to run
      • runAsConsumer

        public <T,​U> void runAsConsumer​(T parameter1,
                                              U parameter2,
                                              BiConsumer<T,​U> action)
        Run an action under this identity.
        Type Parameters:
        T - the action first parameter type
        U - the action second parameter type
        Parameters:
        parameter1 - the first parameter to pass to the action
        parameter2 - the second parameter to pass to the action
        action - the action to run
      • runAsSupplier

        public <T> T runAsSupplier​(Supplier<T> supplier)
                            throws Exception
        Run an action under this identity.
        Type Parameters:
        T - the action return type
        Parameters:
        supplier - the action to run
        Returns:
        the action result (may be null)
        Throws:
        PrivilegedActionException - if the action fails
        Exception
      • runAsAll

        public static void runAsAll​(Runnable runnable,
                                    PeerIdentity... identities)
        Run an action under a series of identities.
        Parameters:
        runnable - the action to run
        identities - the identities to use
      • runAsAll

        public static <T> T runAsAll​(Callable<T> callable,
                                     PeerIdentity... identities)
                              throws Exception
        Run an action under a series of identities.
        Type Parameters:
        T - the action return type
        Parameters:
        callable - the action to run
        identities - the identities to use
        Throws:
        Exception
      • runAsAll

        public static <T> T runAsAll​(PrivilegedAction<T> privilegedAction,
                                     PeerIdentity... identities)
        Run an action under a series of identities.
        Type Parameters:
        T - the action return type
        Parameters:
        privilegedAction - the action to run
        identities - the identities to use
      • runAsAll

        public static <T,​P> T runAsAll​(P parameter,
                                             ParametricPrivilegedAction<T,​P> privilegedAction,
                                             PeerIdentity... identities)
        Run an action under a series of identities.
        Type Parameters:
        T - the action return type
        P - the action parameter type
        Parameters:
        parameter - the parameter to pass to the action
        privilegedAction - the action to run
        identities - the identities to use
      • runAsAll

        public static <T,​P> T runAsAll​(P parameter,
                                             ParametricPrivilegedExceptionAction<T,​P> privilegedAction,
                                             PeerIdentity... identities)
                                      throws PrivilegedActionException
        Run an action under a series of identities.
        Type Parameters:
        T - the action return type
        P - the action parameter type
        Parameters:
        parameter - the parameter to pass to the action
        privilegedAction - the action to run
        identities - the identities to use
        Throws:
        PrivilegedActionException - if the action throws an exception
      • runAsAllFunction

        public static <R,​T> R runAsAllFunction​(T parameter,
                                                     Function<T,​R> privilegedAction,
                                                     PeerIdentity... identities)
        Run an action under a series of identities.
        Type Parameters:
        R - the action return type
        T - the action parameter type
        Parameters:
        parameter - the parameter to pass to the action
        privilegedAction - the action to run
        identities - the identities to use
      • runAsAllFunction

        public static <T,​U,​R> R runAsAllFunction​(T parameter1,
                                                             U parameter2,
                                                             BiFunction<T,​U,​R> privilegedAction,
                                                             PeerIdentity... identities)
        Run an action under a series of identities.
        Type Parameters:
        T - the action first parameter type
        U - the action second parameter type
        R - the action return type
        Parameters:
        parameter1 - the first parameter to pass to the action
        parameter2 - the second parameter to pass to the action
        privilegedAction - the action to run
        identities - the identities to use
      • runAsAllConsumer

        public static <T> void runAsAllConsumer​(T parameter,
                                                Consumer<T> privilegedAction,
                                                PeerIdentity... identities)
        Run an action under a series of identities.
        Type Parameters:
        T - the action parameter type
        Parameters:
        parameter - the parameter to pass to the action
        privilegedAction - the action to run
        identities - the identities to use
      • runAsAllConsumer

        public static <T,​U> void runAsAllConsumer​(T parameter1,
                                                        U parameter2,
                                                        BiConsumer<T,​U> privilegedAction,
                                                        PeerIdentity... identities)
        Run an action under a series of identities.
        Type Parameters:
        T - the action first parameter type
        U - the action second parameter type
        Parameters:
        parameter1 - the first parameter to pass to the action
        parameter2 - the second parameter to pass to the action
        privilegedAction - the action to run
        identities - the identities to use
      • runAsAllObjIntConsumer

        public static <T> void runAsAllObjIntConsumer​(T parameter1,
                                                      int parameter2,
                                                      ObjIntConsumer<T> privilegedAction,
                                                      PeerIdentity... identities)
        Run an action under a series of identities.
        Type Parameters:
        T - the action first parameter type
        Parameters:
        parameter1 - the first parameter to pass to the action
        parameter2 - the second parameter to pass to the action
        privilegedAction - the action to run
        identities - the identities to use
      • runAsAllSupplier

        public static <T> T runAsAllSupplier​(Supplier<T> action,
                                             PeerIdentity... identities)
        Run an action under a series of identities.
        Type Parameters:
        T - the action return type
        Parameters:
        action - the action to run
        identities - the identities to use
      • getPeerPrincipal

        public Principal getPeerPrincipal()
        Get the peer principal.
        Returns:
        the peer principal (not null)
      • getPeerRoles

        public Set<String> getPeerRoles()
        Get the peer identity roles. The default implementation returns an empty set.
        Returns:
        the peer identity role set (not null)
      • hasPeerRole

        public boolean hasPeerRole​(String roleName)
        Determine whether the peer identity has a given role name. The default implementation returns false.
        Parameters:
        roleName - the role name
        Returns:
        true if the peer identity has the role, false otherwise
      • getPeerAttributes

        public Attributes getPeerAttributes()
        Get the attribute set for the peer identity. The default implementation returns an empty attributes set.
        Returns:
        the peer identity attributes
      • getPeerAttribute

        public Attributes.Entry getPeerAttribute​(String key)
        Get a specific attribute value for the peer identity. The default implementation returns null.
        Parameters:
        key - the attribute name
        Returns:
        the attribute value entry, or null if there is no matching entry
      • getPeerIdentityContext

        protected final PeerIdentityContext getPeerIdentityContext()
        Get the peer identity context for this identity.
        Returns:
        the peer identity context for this identity (not null)