Package org.wildfly.security.auth.client
Class PeerIdentity
- java.lang.Object
-
- org.wildfly.security.auth.client.PeerIdentity
-
public abstract class PeerIdentity extends Object
A peer's authenticated identity.- Author:
- David M. Lloyd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPeerIdentity.ConfigurationThe opaque configuration to apply to a peer identity.
-
Field Summary
Fields Modifier and Type Field Description private PeerIdentityContextcontextprivate PrincipalpeerPrincipal
-
Constructor Summary
Constructors Modifier Constructor Description protectedPeerIdentity(PeerIdentity.Configuration configuration, Principal peerPrincipal)Construct a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Attributes.EntrygetPeerAttribute(String key)Get a specific attribute value for the peer identity.AttributesgetPeerAttributes()Get the attribute set for the peer identity.protected PeerIdentityContextgetPeerIdentityContext()Get the peer identity context for this identity.PrincipalgetPeerPrincipal()Get the peer principal.Set<String>getPeerRoles()Get the peer identity roles.booleanhasPeerRole(String roleName)Determine whether the peer identity has a given role name.booleanisSamePeerIdentityContext(PeerIdentity other)Determine if the peer identity context of this identity is the same as that of the given identity.protected voidpostAssociate()Perform an optional post-association action, called after association with the current thread has completed.protected voidpreAssociate()Perform an optional pre-association action, called before association with the current thread.voidrunAs(Runnable runnable)Run an action under this identity.<T> TrunAs(PrivilegedAction<T> action)Run an action under this identity.<T> TrunAs(PrivilegedExceptionAction<T> action)Run an action under this identity.<T> TrunAs(Callable<T> callable)Run an action under this identity.<T,P>
TrunAs(P parameter, ParametricPrivilegedAction<T,P> action)Run an action under this identity.<T,P>
TrunAs(P parameter, ParametricPrivilegedExceptionAction<T,P> action)Run an action under this identity.static voidrunAsAll(Runnable runnable, PeerIdentity... identities)Run an action under a series of identities.static <T> TrunAsAll(PrivilegedAction<T> privilegedAction, PeerIdentity... identities)Run an action under a series of identities.static <T> TrunAsAll(PrivilegedExceptionAction<T> privilegedAction, PeerIdentity... identities)Run an action under a series of identities.static <T> TrunAsAll(Callable<T> callable, PeerIdentity... identities)Run an action under a series of identities.static <T,P>
TrunAsAll(P parameter, ParametricPrivilegedAction<T,P> privilegedAction, PeerIdentity... identities)Run an action under a series of identities.static <T,P>
TrunAsAll(P parameter, ParametricPrivilegedExceptionAction<T,P> privilegedAction, PeerIdentity... identities)Run an action under a series of identities.static <T> voidrunAsAllConsumer(T parameter, Consumer<T> privilegedAction, PeerIdentity... identities)Run an action under a series of identities.static <T,U>
voidrunAsAllConsumer(T parameter1, U parameter2, BiConsumer<T,U> privilegedAction, PeerIdentity... identities)Run an action under a series of identities.static <R,T>
RrunAsAllFunction(T parameter, Function<T,R> privilegedAction, PeerIdentity... identities)Run an action under a series of identities.static <T,U,R>
RrunAsAllFunction(T parameter1, U parameter2, BiFunction<T,U,R> privilegedAction, PeerIdentity... identities)Run an action under a series of identities.static <T> voidrunAsAllObjIntConsumer(T parameter1, int parameter2, ObjIntConsumer<T> privilegedAction, PeerIdentity... identities)Run an action under a series of identities.static <T> TrunAsAllSupplier(Supplier<T> action, PeerIdentity... identities)Run an action under a series of identities.<T> voidrunAsConsumer(T parameter, Consumer<T> action)Run an action under this identity.<T,U>
voidrunAsConsumer(T parameter1, U parameter2, BiConsumer<T,U> action)Run an action under this identity.<T,R>
RrunAsFunction(T parameter, Function<T,R> action)Run an action under this identity.<T,U,R>
RrunAsFunction(T parameter1, U parameter2, BiFunction<T,U,R> action)Run an action under this identity.<T> TrunAsSupplier(Supplier<T> supplier)Run an action under this identity.private voidsafePostAssociate()
-
-
-
Field Detail
-
context
private final PeerIdentityContext context
-
peerPrincipal
private final Principal peerPrincipal
-
-
Constructor Detail
-
PeerIdentity
protected PeerIdentity(PeerIdentity.Configuration configuration, Principal peerPrincipal)
Construct a new instance.- Parameters:
configuration- the opaque configuration (must not benull)peerPrincipal- the peer principal (must not benull)
-
-
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:
trueif the identities share a context,falseotherwise
-
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 failsException
-
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> T runAs(PrivilegedExceptionAction<T> action) throws PrivilegedActionException
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) - Throws:
PrivilegedActionException- if the action fails
-
runAs
public <T,P> T runAs(P parameter, ParametricPrivilegedAction<T,P> action)Run an action under this identity.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- the action to run- Returns:
- the action result (may be
null)
-
runAs
public <T,P> T runAs(P parameter, ParametricPrivilegedExceptionAction<T,P> action) throws PrivilegedActionExceptionRun an action under this identity.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionaction- 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 typeR- the action return type- Parameters:
parameter- the parameter to pass to the actionaction- 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 typeU- the action second parameter typeR- the action return type- Parameters:
parameter1- the first parameter to pass to the actionparameter2- the second parameter to pass to the actionaction- 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 actionaction- 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 typeU- the action second parameter type- Parameters:
parameter1- the first parameter to pass to the actionparameter2- the second parameter to pass to the actionaction- 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 failsException
-
runAsAll
public static void runAsAll(Runnable runnable, PeerIdentity... identities)
Run an action under a series of identities.- Parameters:
runnable- the action to runidentities- 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 runidentities- 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 runidentities- the identities to use
-
runAsAll
public static <T> T runAsAll(PrivilegedExceptionAction<T> privilegedAction, PeerIdentity... identities) throws PrivilegedActionException
Run an action under a series of identities.- Type Parameters:
T- the action return type- Parameters:
privilegedAction- the action to runidentities- the identities to use- Throws:
PrivilegedActionException- if the action throws an exception
-
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 typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionprivilegedAction- the action to runidentities- the identities to use
-
runAsAll
public static <T,P> T runAsAll(P parameter, ParametricPrivilegedExceptionAction<T,P> privilegedAction, PeerIdentity... identities) throws PrivilegedActionExceptionRun an action under a series of identities.- Type Parameters:
T- the action return typeP- the action parameter type- Parameters:
parameter- the parameter to pass to the actionprivilegedAction- the action to runidentities- 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 typeT- the action parameter type- Parameters:
parameter- the parameter to pass to the actionprivilegedAction- the action to runidentities- 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 typeU- the action second parameter typeR- the action return type- Parameters:
parameter1- the first parameter to pass to the actionparameter2- the second parameter to pass to the actionprivilegedAction- the action to runidentities- 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 actionprivilegedAction- the action to runidentities- 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 typeU- the action second parameter type- Parameters:
parameter1- the first parameter to pass to the actionparameter2- the second parameter to pass to the actionprivilegedAction- the action to runidentities- 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 actionparameter2- the second parameter to pass to the actionprivilegedAction- the action to runidentities- 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 runidentities- 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 returnsfalse.- Parameters:
roleName- the role name- Returns:
trueif the peer identity has the role,falseotherwise
-
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 returnsnull.- Parameters:
key- the attribute name- Returns:
- the attribute value entry, or
nullif 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)
-
-