Record Class EnrollmentToken
java.lang.Object
java.lang.Record
org.jwcarman.who.enrollment.EnrollmentToken
- Record Components:
id- stable UUID identifying this token recordidentityId- the identity this token is associated withvalue- the shareable token value delivered to the end userstatus- current lifecycle status (PENDING,REDEEMED, orREVOKED)createdAt- when the token was createdexpiresAt- when the token expiresredeemedAt- when the token was redeemed, ornullif not yet redeemed
public record EnrollmentToken(UUID id, UUID identityId, String value, EnrollmentTokenStatus status, Instant createdAt, Instant expiresAt, Instant redeemedAt)
extends Record
An immutable enrollment token that links a
Credential to a
pre-existing Identity.
The token value is a secret random string, distinct from the id, and is what gets
shared with the end user. toString() never prints it. Expiry is determined at runtime —
EXPIRED is not stored as a status.
-
Constructor Summary
ConstructorsConstructorDescriptionEnrollmentToken(UUID id, UUID identityId, String value, EnrollmentTokenStatus status, Instant createdAt, Instant expiresAt, Instant redeemedAt) Compact constructor for null-safety validation. -
Method Summary
Modifier and TypeMethodDescriptionstatic EnrollmentTokenCreates a new PENDING enrollment token for the given identity.static EnrollmentTokenCreates a new PENDING enrollment token for the given identity, stamped from the given instant.Returns 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.id()Returns the value of theidrecord component.Returns the value of theidentityIdrecord component.booleanReturnstrueif the token has passed its expiration time.booleanReturnstrueif the token isPENDINGand not yet expired.redeem()Returns a new token withREDEEMEDstatus.Returns the value of theredeemedAtrecord component.revoke()Returns a new token withREVOKEDstatus.status()Returns the value of thestatusrecord component.toString()Returns a description of this token with thevaluemasked, so that logging a token never leaks the secret.value()Returns the value of thevaluerecord component.
-
Constructor Details
-
EnrollmentToken
-
-
Method Details
-
create
Creates a new PENDING enrollment token for the given identity.- Parameters:
identity- the identity this token is forexpiration- how long until the token expires- Returns:
- a new
PENDINGtoken
-
create
Creates a new PENDING enrollment token for the given identity, stamped from the given instant.- Parameters:
identity- the identity this token is forexpiration- how long until the token expiresnow- the creation time; the token expires atnow + expiration- Returns:
- a new
PENDINGtoken
-
toString
-
isExpired
public boolean isExpired()Returnstrueif the token has passed its expiration time.- Returns:
trueif expired
-
isPending
public boolean isPending()Returnstrueif the token isPENDINGand not yet expired.- Returns:
trueif the token can be redeemed
-
redeem
Returns a new token withREDEEMEDstatus.- Returns:
- redeemed copy of this token
-
revoke
Returns a new token withREVOKEDstatus.- Returns:
- revoked copy of this token
-
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). -
id
-
identityId
Returns the value of theidentityIdrecord component.- Returns:
- the value of the
identityIdrecord component
-
value
-
status
-
createdAt
-
expiresAt
-
redeemedAt
Returns the value of theredeemedAtrecord component.- Returns:
- the value of the
redeemedAtrecord component
-