Record Class EnrollmentToken

java.lang.Object
java.lang.Record
org.jwcarman.who.enrollment.EnrollmentToken
Record Components:
id - stable UUID identifying this token record
identityId - the identity this token is associated with
value - the shareable token value delivered to the end user
status - current lifecycle status (PENDING, REDEEMED, or REVOKED)
createdAt - when the token was created
expiresAt - when the token expires
redeemedAt - when the token was redeemed, or null if 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 Details

  • Method Details

    • create

      public static EnrollmentToken create(Identity identity, Duration expiration)
      Creates a new PENDING enrollment token for the given identity.
      Parameters:
      identity - the identity this token is for
      expiration - how long until the token expires
      Returns:
      a new PENDING token
    • create

      public static EnrollmentToken create(Identity identity, Duration expiration, Instant now)
      Creates a new PENDING enrollment token for the given identity, stamped from the given instant.
      Parameters:
      identity - the identity this token is for
      expiration - how long until the token expires
      now - the creation time; the token expires at now + expiration
      Returns:
      a new PENDING token
    • toString

      public String toString()
      Returns a description of this token with the value masked, so that logging a token never leaks the secret.
      Specified by:
      toString in class Record
      Returns:
      a string with value=*** in place of the token value
    • isExpired

      public boolean isExpired()
      Returns true if the token has passed its expiration time.
      Returns:
      true if expired
    • isPending

      public boolean isPending()
      Returns true if the token is PENDING and not yet expired.
      Returns:
      true if the token can be redeemed
    • redeem

      public EnrollmentToken redeem()
      Returns a new token with REDEEMED status.
      Returns:
      redeemed copy of this token
    • revoke

      public EnrollmentToken revoke()
      Returns a new token with REVOKED status.
      Returns:
      revoked copy of this token
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • id

      public UUID id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • identityId

      public UUID identityId()
      Returns the value of the identityId record component.
      Returns:
      the value of the identityId record component
    • value

      public String value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • status

      public EnrollmentTokenStatus status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • createdAt

      public Instant createdAt()
      Returns the value of the createdAt record component.
      Returns:
      the value of the createdAt record component
    • expiresAt

      public Instant expiresAt()
      Returns the value of the expiresAt record component.
      Returns:
      the value of the expiresAt record component
    • redeemedAt

      public Instant redeemedAt()
      Returns the value of the redeemedAt record component.
      Returns:
      the value of the redeemedAt record component