Instances of this class will always be available for injection even if no authentication has taken place.
In this case isAnonymous() will return true, and the security identity will generally have no roles.
Implementations should be immutable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe attribute name that is used to store the underlying security identity representation. -
Method Summary
Modifier and TypeMethodDescriptiondefault io.smallrye.mutiny.Uni<Boolean>checkPermission(String permission) Checks if a security identity holds a given permission.io.smallrye.mutiny.Uni<Boolean>checkPermission(Permission permission) Checks if a security identity holds a given permission.default booleancheckPermissionBlocking(String permission) Checks if a security identity holds a given permission.default booleancheckPermissionBlocking(Permission permission) Checks if a security identity holds a given permission.<T> TgetAttribute(String name) Gets an attribute from the identity.<T extends Credential>
TgetCredential(Class<T> credentialType) Gets the security identity credential of the given type, ornullif a credential of the given type is not present.Returns a set of all credentials owned by this security identity.Returns an unmodifiable set of permissions held by the security identity that have already been resolved and can be represented asPermission.default <T extends Principal>
TgetPrincipal(Class<T> clazz) getRoles()Returns the set of all roles held by the security identity.booleanChecks if a security identity has a given role.boolean
-
Field Details
-
USER_ATTRIBUTE
The attribute name that is used to store the underlying security identity representation.- See Also:
-
-
Method Details
-
getPrincipal
Principal getPrincipal()- Returns:
- the
Principalrepresenting the current security identity.
-
getPrincipal
-
isAnonymous
boolean isAnonymous()- Returns:
trueif this identity is anonymous
-
getRoles
Returns the set of all roles held by the security identity. These roles must be resolvable in advance for every request.Note that roles are returned on a best effort basis. To actually check if a user holds a role
hasRole(String)should be used instead. Some API's (e.g. JAX-RS) do not allow for all roles to be returned, so if the underlying identity representation does not support retrieving all the roles this method will not always be reliable. In general all built in Quarkus security extensions should provide this, unless it is documented otherwise.This set should either be unmodifiable, or a defensive copy so attempts to change the role set do not modify the underlying identity.
- Returns:
- The set of all roles held by the user
-
hasRole
Checks if a security identity has a given role. These roles must be resolvable in advance for every request.- Returns:
trueif the identity has the specified role.
-
getPermissions
Set<Permission> getPermissions()Returns an unmodifiable set of permissions held by the security identity that have already been resolved and can be represented asPermission.Note that this set of permissions is not guaranteed to represent a complete set of permissions held by the identity. For example, a JSON Web Token (JWT) token scope might be represented as a
Permissioninstance, while an unresolved permission that requires an asynchronous or remote permission check can not be.- Returns:
- The set of resolved permissions that can be represented as
Permission
-
getCredential
Gets the security identity credential of the given type, ornullif a credential of the given type is not present.- Type Parameters:
T- The type of the credential- Parameters:
credentialType- The type of the credential- Returns:
- The credential
-
getCredentials
Set<Credential> getCredentials()Returns a set of all credentials owned by this security identity.- Returns:
- a set of all credentials
-
getAttribute
Gets an attribute from the identity.These can be arbitrary, and extensions are encouraged to use name spaced attribute names in a similar manner to package names.
The `quarkus.` namespace is reserved
The root
- Type Parameters:
T- The type of the attribute- Parameters:
name- The attribute name- Returns:
- The attribute value
-
getAttributes
- Returns:
- All the request attributes
-
checkPermission
Checks if a security identity holds a given permission.This method is asynchronous, as it may involve calls to a remote resource.
- Parameters:
permission- The permission- Returns:
- Uni that will resolve to true if the security identity has the specified permission
-
checkPermissionBlocking
Checks if a security identity holds a given permission.This method is a blocking version of
checkPermission(Permission)..- Parameters:
permission- The permission- Returns:
- true if the security identity has the specified permission
-
checkPermission
Checks if a security identity holds a given permission.This method is asynchronous, as it may involve calls to a remote resource.
- Parameters:
permission- The permission- Returns:
- Uni that will resolve to true if the security identity has the specified permission
-
checkPermissionBlocking
Checks if a security identity holds a given permission.This method is a blocking version of
checkPermission(Permission). By default it will just wait for theCompletionStageto be complete, however it is likely that some implementations will want to provide a more efficient version.- Parameters:
permission- The permission- Returns:
- Uni that will resolve to true if the security identity has the specified permission
-