Record Class Token

java.lang.Object
java.lang.Record
tech.lastbox.jwt.Token

public record Token(String token, String subject, LocalDateTime issuedAt, LocalDateTime expiresIn, String issuer, List<String> scope, boolean isRevoked) extends Record
Represents a JWT (JSON Web Token) in the system. This record encapsulates information related to the token, including its value, subject, issue and expiration times, issuer, scope, and revocation status.

This class is typically used for transferring JWT-related data and is ideal for scenarios where immutable data structures are required. It encapsulates the following fields:

  • token: The string representation of the token itself.
  • subject: The subject associated with the token (typically the user or entity).
  • issuedAt: The timestamp representing when the token was issued.
  • expiresIn: The timestamp representing when the token will expire.
  • issuer: The entity that issued the token.
  • scope: A list of string values representing the scopes/permissions granted by the token.
  • isRevoked: A boolean flag indicating whether the token has been revoked.

This record is designed for use in scenarios where tokens are immutable, such as when tokens are validated or stored for reference. The fields provided allow for detailed tracking of token properties and status.

  • Constructor Details

    • Token

      public Token(String token, String subject, LocalDateTime issuedAt, LocalDateTime expiresIn, String issuer, List<String> scope, boolean isRevoked)
      Creates an instance of a Token record class.
      Parameters:
      token - the value for the token record component
      subject - the value for the subject record component
      issuedAt - the value for the issuedAt record component
      expiresIn - the value for the expiresIn record component
      issuer - the value for the issuer record component
      scope - the value for the scope record component
      isRevoked - the value for the isRevoked record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • token

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

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

      public LocalDateTime issuedAt()
      Returns the value of the issuedAt record component.
      Returns:
      the value of the issuedAt record component
    • expiresIn

      public LocalDateTime expiresIn()
      Returns the value of the expiresIn record component.
      Returns:
      the value of the expiresIn record component
    • issuer

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

      public List<String> scope()
      Returns the value of the scope record component.
      Returns:
      the value of the scope record component
    • isRevoked

      public boolean isRevoked()
      Returns the value of the isRevoked record component.
      Returns:
      the value of the isRevoked record component