Record Class ApiKeyRecord
java.lang.Object
java.lang.Record
com.svenruppert.jsentinel.authentication.ApiKeyRecord
- Record Components:
keyHash- non-blank API-key hashtenant- tenant scope;nullbecomesTenantId.DEFAULTsubjectId- subject that issued the keyname- non-blank human-readable labelscopes- immutable permission set the key grants;nullbecomes emptycreatedAt- issuance instantexpiresAt- absolute expiry; if present must be strictly aftercreatedAt; empty for keys without expirylastUsedAt- last successful authentication; if present must not predatecreatedAtrevokedAt- revocation instant; if present must not predatecreatedAt
@ExperimentalJSentinelApi
public record ApiKeyRecord(String keyHash, TenantId tenant, SubjectId subjectId, String name, Set<PermissionName> scopes, Instant createdAt, Optional<Instant> expiresAt, Optional<Instant> lastUsedAt, Optional<Instant> revokedAt)
extends Record
Persistent representation of a single long-lived API key.
Stores only the hash of the key; the plain value is shown to the user exactly once at creation time and never persisted. Each key carries its own scope set — usually a subset of the issuing subject's permissions, narrowed to the operations the key holder needs.
Lifecycle states reachable through the with… helpers:
- fresh —
lastUsedAt+revokedAtempty. - used —
lastUsedAtpresent,revokedAtempty;isActive(Instant)stilltrue. - revoked —
revokedAtpresent;isActive(Instant)alwaysfalsethereafter. - expired —
expiresAtpresent andnow >= expiresAt;isActive(Instant)alsofalse.
-
Constructor Summary
ConstructorsConstructorDescriptionApiKeyRecord(String keyHash, TenantId tenant, SubjectId subjectId, String name, Set<PermissionName> scopes, Instant createdAt, Optional<Instant> expiresAt, Optional<Instant> lastUsedAt, Optional<Instant> revokedAt) Validates the record components, normalisesnulltenant toTenantId.DEFAULT, defensively copiesscopes, and replacesnullOptionals withOptional.empty(). -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thecreatedAtrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theexpiresAtrecord component.final inthashCode()Returns a hash code value for this object.booleanWhether the key is admissible atnow— neither revoked nor expired.booleanWhether the key is expired atnow.booleanWhetherrevokedAt()is present.keyHash()Returns the value of thekeyHashrecord component.Returns the value of thelastUsedAtrecord component.name()Returns the value of thenamerecord component.Returns the value of therevokedAtrecord component.scopes()Returns the value of thescopesrecord component.Returns the value of thesubjectIdrecord component.tenant()Returns the value of thetenantrecord component.final StringtoString()Returns a string representation of this record class.Returns a copy withlastUsedAt()set toat.withRevokedAt(Instant at) Returns a copy withrevokedAt()set toat.
-
Constructor Details
-
ApiKeyRecord
public ApiKeyRecord(String keyHash, TenantId tenant, SubjectId subjectId, String name, Set<PermissionName> scopes, Instant createdAt, Optional<Instant> expiresAt, Optional<Instant> lastUsedAt, Optional<Instant> revokedAt) Validates the record components, normalisesnulltenant toTenantId.DEFAULT, defensively copiesscopes, and replacesnullOptionals withOptional.empty().
-
-
Method Details
-
withLastUsedAt
Returns a copy withlastUsedAt()set toat.- Parameters:
at- instant the key was used; non-null- Returns:
- new record
-
withRevokedAt
Returns a copy withrevokedAt()set toat.- Parameters:
at- instant the key was revoked; non-null- Returns:
- new record
-
isRevoked
public boolean isRevoked()WhetherrevokedAt()is present. -
isExpired
Whether the key is expired atnow. A key without anexpiresAt()value never expires.- Parameters:
now- reference instant; non-null- Returns:
- whether the key is expired
-
isActive
Whether the key is admissible atnow— neither revoked nor expired.- Parameters:
now- reference instant; non-null- Returns:
- whether the key can authenticate
-
toString
-
hashCode
-
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). -
keyHash
-
tenant
-
subjectId
-
name
-
scopes
-
createdAt
-
expiresAt
-
lastUsedAt
Returns the value of thelastUsedAtrecord component.- Returns:
- the value of the
lastUsedAtrecord component
-
revokedAt
-