Package org.wildfly.security.auth.server
Class SecurityIdentity
java.lang.Object
org.wildfly.security.auth.server.SecurityIdentity
- All Implemented Interfaces:
Supplier<SecurityIdentity>,Scoped,PermissionMappable,PermissionVerifier
public final class SecurityIdentity
extends Object
implements PermissionVerifier, PermissionMappable, Supplier<SecurityIdentity>, Scoped
A loaded and authenticated security identity.
- Author:
- David M. Lloyd
-
Field Summary
Fields inherited from interface org.wildfly.security.permission.PermissionVerifier
ALL, NONE -
Method Summary
Modifier and TypeMethodDescriptionCreate a new flexible identity association, initializing it with this identity.Attempt to create a new identity that can be used to run as an anonymous user.createRunAsAnonymous(boolean authorize) Attempt to create a new identity that can be used to run as an anonymous user Calling with enabled security manager requiressetRunAsPrincipalElytronPermission.createRunAsIdentity(String name) Attempt to create a new identity that can be used to run as a user with the given name.createRunAsIdentity(String name, boolean authorize) Attempt to create a new identity that can be used to run as a user with the given name.createRunAsIdentity(Principal principal, boolean authorize) Attempt to create a new identity that can be used to run as a user with the given principal.get()Get this identity.Get the attributes associated with this identity.Get the creation time of this identity, which is the time that the initial authentication occurred.Get the principal of this identity.Get the private credentials of this identity.Get the public credentials of this identity.getRoles()Get the roles associated with this identity.Get the mapped roles associated with this identity.Get the mapped roles associated with this identity.booleanimplies(Permission permission) Determine if the permission is verified by this object.intersectWith(PermissionVerifier verifier) Create a new security identity which is the same as this one, but which limits authorization privileges to the intersection of the current privileges and the given verifier.booleanConvenience method to determine if this identity is anonymous.<T> TrunAs(PrivilegedAction<T> action) Deprecated.<T> TrunAs(PrivilegedExceptionAction<T> action) Deprecated.UseScoped.runAsSupplierEx(ExceptionSupplier)instead.<T,P> T runAs(P parameter, ParametricPrivilegedAction<T, P> action) Deprecated.UseScoped.runAsFunction(Function, Object)instead.<T,P> T runAs(P parameter, ParametricPrivilegedExceptionAction<T, P> action) Deprecated.UseScoped.runAsFunctionEx(ExceptionFunction, Object)instead.static <T> TrunAsAll(PrivilegedExceptionAction<T> action, SecurityIdentity... identities) Run an action under a series of identities.<T,U> boolean runAsBiPredicate(BiPredicate<T, U> action, T parameter1, U parameter2) Run an action under this identity.<T,U> void runAsConsumer(BiConsumer<T, U> action, T parameter1, U parameter2) Run an action under this identity.<T,U, E extends Exception>
voidrunAsConsumerEx(ExceptionBiConsumer<T, U, E> action, T parameter1, U parameter2) Run an action under this identity.<T,U, E extends Exception>
booleanrunAsExBiPredicate(ExceptionBiPredicate<T, U, E> action, T parameter1, U parameter2) Run an action under this identity.<T,U, R> R runAsFunction(BiFunction<T, U, R> action, T parameter1, U parameter2) Run an action under this identity.<T,U, R, E extends Exception>
RrunAsFunctionEx(ExceptionBiFunction<T, U, R, E> action, T parameter1, U parameter2) Run an action under this identity.<T> voidrunAsObjIntConsumer(ObjIntConsumer<T> action, T parameter1, int parameter2) Run an action under this identity.<T,E extends Exception>
voidrunAsObjIntConsumerEx(ExceptionObjIntConsumer<T, E> action, T parameter1, int parameter2) Run an action under this identity.toString()withDefaultRoleMapper(RoleMapper roleMapper) Attempt to create a new identity which wraps the default roles with a default role mapper.withPrivateCredential(Credential credential) Create a new security identity which is the same as this one, but which includes the given credential as a private credential.withPrivateCredentials(IdentityCredentials credentials) Create a new security identity which is the same as this one, but which includes the given credentials as private credentials.withPublicCredential(Credential credential) Create a new security identity which is the same as this one, but which includes the given credential as a public credential.withPublicCredentials(IdentityCredentials credentials) Create a new security identity which is the same as this one, but which includes the given credentials as public credentials.withRoleMapper(String category, RoleMapper roleMapper) Attempt to create a new identity which replaces a role mapper category on the current identity.withRuntimeAttributes(Attributes runtimeAttributes) Create a new security identity which is the same as this one, but which includes the given runtime attributes.withSecurityIdentity(SecurityIdentity securityIdentity) Attempt to create a new identity that is the same as this identity but with an additional identity from a different security domain that will be associated with all 'run' calls.withSecurityIdentitySupplier(Supplier<SecurityIdentity[]> securityIdentities) Attempt to create a new identity that is the same as this identity but with aSupplier<SecurityIdentity[]>to supply identities that will be associated with all 'run' calls.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.wildfly.security.permission.PermissionVerifier
and, checkPermission, not, or, toPermissionCollection, unless, xorMethods inherited from interface org.wildfly.security.auth.server.Scoped
runAs, runAs, runAsAction, runAsConsumer, runAsConsumerEx, runAsExceptionAction, runAsExIntFunction, runAsExLongFunction, runAsExPredicate, runAsFunction, runAsFunctionEx, runAsIntFunction, runAsLongFunction, runAsPredicate, runAsSupplier, runAsSupplierEx
-
Method Details
-
runAs
Deprecated.UseScoped.runAsSupplier(Supplier)instead.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
@Deprecated public <T> T runAs(PrivilegedExceptionAction<T> action) throws PrivilegedActionException Deprecated.UseScoped.runAsSupplierEx(ExceptionSupplier)instead.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
Deprecated.UseScoped.runAsFunction(Function, Object)instead.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
@Deprecated public <T,P> T runAs(P parameter, ParametricPrivilegedExceptionAction<T, P> action) throws PrivilegedActionExceptionDeprecated.UseScoped.runAsFunctionEx(ExceptionFunction, Object)instead.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) - Throws:
PrivilegedActionException- if the action fails
-
runAsFunction
Run an action under this identity.- Specified by:
runAsFunctionin interfaceScoped- Type Parameters:
R- the action return typeT- 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- Returns:
- the action result (may be
null)
-
runAsConsumer
Run an action under this identity.- Specified by:
runAsConsumerin interfaceScoped- 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
-
runAsObjIntConsumer
Run an action under this identity.- Specified by:
runAsObjIntConsumerin interfaceScoped- 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 actionaction- the action to run
-
runAsFunctionEx
public <T,U, R runAsFunctionExR, E extends Exception> (ExceptionBiFunction<T, U, throws ER, E> action, T parameter1, U parameter2) Run an action under this identity.- Specified by:
runAsFunctionExin interfaceScoped- Type Parameters:
R- the action return typeT- the action first parameter typeU- the action second parameter typeE- the action exception 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) - Throws:
E- if the action throws this exception
-
runAsConsumerEx
public <T,U, void runAsConsumerExE extends Exception> (ExceptionBiConsumer<T, U, throws EE> action, T parameter1, U parameter2) Run an action under this identity.- Specified by:
runAsConsumerExin interfaceScoped- Type Parameters:
T- the action first parameter typeU- the action second parameter typeE- the action exception type- Parameters:
parameter1- the first parameter to pass to the actionparameter2- the second parameter to pass to the actionaction- the action to run- Throws:
E- if the action throws this exception
-
runAsObjIntConsumerEx
public <T,E extends Exception> void runAsObjIntConsumerEx(ExceptionObjIntConsumer<T, E> action, T parameter1, int parameter2) throws ERun an action under this identity.- Specified by:
runAsObjIntConsumerExin interfaceScoped- Type Parameters:
T- the action first parameter typeE- the action exception type- Parameters:
parameter1- the first parameter to pass to the actionparameter2- the second parameter to pass to the actionaction- the action to run- Throws:
E- if the action throws this exception
-
runAsBiPredicate
Run an action under this identity.- Specified by:
runAsBiPredicatein interfaceScoped- 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- Returns:
- the action result (may be
null)
-
runAsExBiPredicate
public <T,U, boolean runAsExBiPredicateE extends Exception> (ExceptionBiPredicate<T, U, throws EE> action, T parameter1, U parameter2) Run an action under this identity.- Specified by:
runAsExBiPredicatein interfaceScoped- Type Parameters:
T- the action first parameter typeU- the action second parameter typeE- the action exception 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) - Throws:
E- if the action throws this exception
-
runAsAll
public static <T> T runAsAll(PrivilegedExceptionAction<T> action, SecurityIdentity... identities) throws PrivilegedActionException Run an action under a series of identities.- Type Parameters:
T- the action return type- Parameters:
action- the action to runidentities- the identities to set up- Returns:
- the action result (may be
null) - Throws:
PrivilegedActionException- if the action fails
-
getRoles
Get the roles associated with this identity.- Returns:
- the roles associated with this identity
-
getRoles
Get the mapped roles associated with this identity. If no role mapping exists for the given category, an empty role set is returned.- Parameters:
category- the role mapping category- Returns:
- the category roles
-
withSecurityIdentitySupplier
public SecurityIdentity withSecurityIdentitySupplier(Supplier<SecurityIdentity[]> securityIdentities) Attempt to create a new identity that is the same as this identity but with aSupplier<SecurityIdentity[]>to supply identities that will be associated with all 'run' calls. Any existing individual identities associated with this identity will be dropped. The supplier will be called for each run call so were possible should handle it's own optimisation.- Parameters:
securityIdentities- aSupplier<SecurityIdentity[]>for identities to be associated with every run call.- Returns:
- the new identity
- Throws:
IllegalArgumentException- if the supplied identity
-
withSecurityIdentity
Attempt to create a new identity that is the same as this identity but with an additional identity from a different security domain that will be associated with all 'run' calls. If aSupplier<SecurityIdentity[]>has previously been associated with this identity it will be dropped.- Parameters:
securityIdentity- theSecurityIdentityto also be associated with all run calls made to this identity.- Returns:
- the new identity
- Throws:
IllegalArgumentException- if the supplied identity
-
getRoles
Get the mapped roles associated with this identity.- Parameters:
category- the role mapping categoryfallbackToDefault-trueif the default roles associated with this identity should be returned if no role mapping exists for the given category,falseotherwise- Returns:
- the category roles
-
withRoleMapper
Attempt to create a new identity which replaces a role mapper category on the current identity. If the given role mapper is already set on the current identity, the current identity is returned.- Parameters:
category- the category nameroleMapper- the role mapper to use- Returns:
- the new identity
- Throws:
SecurityException- if the calling class is not granted theChangeRoleMapperPermissionfor the given category name
-
withDefaultRoleMapper
Attempt to create a new identity which wraps the default roles with a default role mapper.- Parameters:
roleMapper- the roleMapper to map the roles.- Returns:
- the new identity
- Throws:
SecurityException- if the calling class is not granted the withDefaultRoleMapper permission.
-
createRunAsIdentity
Attempt to create a new identity that can be used to run as a user with the given name. If the current identity is not authorized to run as a user with the given name, an exception is thrown. Calling with enabled security manager requiressetRunAsPrincipalElytronPermission. Regardless security manager is enabled,RunAsPrincipalPermissionfor given name is required.- Parameters:
name- the name to attempt to run as- Returns:
- the new security identity
- Throws:
SecurityException- if the operation authorization failed for any reason
-
createRunAsIdentity
public SecurityIdentity createRunAsIdentity(String name, boolean authorize) throws SecurityException Attempt to create a new identity that can be used to run as a user with the given name. Calling with enabled security manager requiressetRunAsPrincipalElytronPermission.- Parameters:
name- the name to attempt to run asauthorize- whether to check the current identity is authorized to run as a user with the given principal (hasRunAsPrincipalPermission)- Returns:
- the new security identity
- Throws:
SecurityException- if the caller does not have thesetRunAsPrincipalElytronPermissionor if the operation authorization failed for any other reason
-
createRunAsIdentity
public SecurityIdentity createRunAsIdentity(Principal principal, boolean authorize) throws SecurityException Attempt to create a new identity that can be used to run as a user with the given principal. Calling with enabled security manager requiressetRunAsPrincipalElytronPermission.- Parameters:
principal- the principal to attempt to run asauthorize- whether to check the current identity is authorized to run as a user with the given principal (hasRunAsPrincipalPermission)- Returns:
- the new security identity
- Throws:
SecurityException- if the caller does not have thesetRunAsPrincipalElytronPermissionor if the operation authorization failed for any other reason
-
createRunAsAnonymous
Attempt to create a new identity that can be used to run as an anonymous user. If the current identity is not authorized to run as an anonymous user, an exception is thrown. Calling with enabled security manager requiressetRunAsPrincipalElytronPermission.LoginPermissiongranted to the anonymous identity will be required.- Returns:
- the new security identity
- Throws:
SecurityException- if the operation authorization failed for any reason
-
createRunAsAnonymous
Attempt to create a new identity that can be used to run as an anonymous user Calling with enabled security manager requiressetRunAsPrincipalElytronPermission.- Parameters:
authorize- whether to check the anonymous identity is authorized to log in (hasLoginPermission)- Returns:
- the new security identity
- Throws:
SecurityException- if the caller does not have thesetRunAsPrincipalElytronPermissionor if the operation authorization failed for any other reason
-
intersectWith
Create a new security identity which is the same as this one, but which limits authorization privileges to the intersection of the current privileges and the given verifier.- Parameters:
verifier- the restricted verifier (must not benull)- Returns:
- the restricted identity
-
implies
Description copied from interface:PermissionVerifierDetermine if the permission is verified by this object.- Specified by:
impliesin interfacePermissionVerifier- Parameters:
permission- the permission to verify (must not benull)- Returns:
trueif the permission is implied by this verifier,falseotherwise
-
getAttributes
Get the attributes associated with this identity.- Specified by:
getAttributesin interfacePermissionMappable- Returns:
- a read-only instance of
Attributeswith all attributes associated with this identity
-
getPrincipal
Get the principal of this identity.- Specified by:
getPrincipalin interfacePermissionMappable- Returns:
- the principal of this identity
-
getCreationTime
Get the creation time of this identity, which is the time that the initial authentication occurred.- Specified by:
getCreationTimein interfacePermissionMappable- Returns:
- the creation time of this identity (not
null)
-
getPublicCredentials
Get the public credentials of this identity.- Specified by:
getPublicCredentialsin interfacePermissionMappable- Returns:
- the public credentials of this identity (not
null)
-
isAnonymous
public boolean isAnonymous()Convenience method to determine if this identity is anonymous.- Returns:
trueif the identity is anonymous,falseotherwise
-
withPublicCredential
Create a new security identity which is the same as this one, but which includes the given credential as a public credential.- Parameters:
credential- the credential (must not benull)- Returns:
- the new identity
-
withPublicCredentials
Create a new security identity which is the same as this one, but which includes the given credentials as public credentials.- Parameters:
credentials- the credential set (must not benull)- Returns:
- the new identity
-
withPrivateCredential
Create a new security identity which is the same as this one, but which includes the given credential as a private credential.- Parameters:
credential- the credential (must not benull)- Returns:
- the new identity
-
withPrivateCredentials
Create a new security identity which is the same as this one, but which includes the given credentials as private credentials.- Parameters:
credentials- the credential set (must not benull)- Returns:
- the new identity
-
withRuntimeAttributes
Create a new security identity which is the same as this one, but which includes the given runtime attributes.- Parameters:
runtimeAttributes- the runtime attributes (must not benull)- Returns:
- the new identity
-
getPrivateCredentials
Get the private credentials of this identity. The caller must have thegetPrivateCredentialsElytronPermission.- Returns:
- the private credentials of this identity (not
null)
-
get
Get this identity.- Specified by:
getin interfaceSupplier<SecurityIdentity>- Returns:
- this identity
-
createFlexibleAssociation
Create a new flexible identity association, initializing it with this identity.- Returns:
- the new flexible identity association (not
null)
-
toString
-
Scoped.runAsSupplier(Supplier)instead.