Record Class SecurityIdentity
- Record Components:
principal- the caller's stable name, for example thesubclaim of a token; one to 256 characters without control charactersroles- granted roles; copied, each one to 256 characters without control characterspermissions- granted permissions; copied, each one to 256 characters without control charactersattributes- further verified facts about the caller, as text; copied
An authenticator creates the identity from credentials it verified, and authentication
middleware attaches it to the request with Context.identity(SecurityIdentity). Handlers
read it with Context.identity(). Role and permission names are compared exactly
(case-sensitive). What a role or permission means is the application's decision.
Attributes carry further verified facts about the caller that an authenticator chose to expose (for example a tenant or e-mail claim of a token) as text. They are not grants and no policy reads them; handlers do. At most 64 attributes; a name is 1 to 256 characters and a value 0 to 2,048 characters, neither with control characters.
toString() lists the principal and the number of roles, permissions and attributes
only, so a logged identity does not spell out its grants or personal data.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReads an attribute.Returns the value of theattributesrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanhasPermission(String permission) Reports whether the identity was granted a permission.booleanReports whether the identity was granted a role.static SecurityIdentityCreates an identity without roles or permissions.Returns the value of thepermissionsrecord component.Returns the value of theprincipalrecord component.roles()Returns the value of therolesrecord component.toString()Describes the identity by principal and grant counts.withAttributes(Map<String, String> additional) Returns a copy with further attributes; a name already present is replaced.
-
Constructor Details
-
SecurityIdentity
public SecurityIdentity(String principal, Set<String> roles, Set<String> permissions, Map<String, String> attributes) Validates and copies the identity.- Parameters:
principal- the caller's stable nameroles- granted rolespermissions- granted permissionsattributes- further verified facts, as text- Throws:
NullPointerException- if any argument or element is nullIllegalArgumentException- for an empty, overlong or control-character name, an overlong or control-character attribute value, or more than 64 attributes
-
SecurityIdentity
Creates an identity with grants and no attributes.- Parameters:
principal- the caller's stable nameroles- granted rolespermissions- granted permissions- Throws:
NullPointerException- if any argument or element is nullIllegalArgumentException- for an empty, overlong or control-character name
-
-
Method Details
-
of
Creates an identity without roles or permissions.- Parameters:
principal- the caller's stable name- Returns:
- identity with no grants
-
hasRole
Reports whether the identity was granted a role.- Parameters:
role- exact role name- Returns:
- true if granted
-
hasPermission
Reports whether the identity was granted a permission.- Parameters:
permission- exact permission name- Returns:
- true if granted
-
attribute
Reads an attribute.- Parameters:
name- exact attribute name- Returns:
- the value, or empty if the authenticator exposed none with that name
-
withAttributes
Returns a copy with further attributes; a name already present is replaced.- Parameters:
additional- attributes to add- Returns:
- the new identity
- Throws:
IllegalArgumentException- as for the constructor
-
toString
Describes the identity by principal and grant counts. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
principal
Returns the value of theprincipalrecord component.- Returns:
- the value of the
principalrecord component
-
roles
Returns the value of therolesrecord component.- Returns:
- the value of the
rolesrecord component
-
permissions
Returns the value of thepermissionsrecord component.- Returns:
- the value of the
permissionsrecord component
-
attributes
Returns the value of theattributesrecord component.- Returns:
- the value of the
attributesrecord component
-