Class TokenEntity

java.lang.Object
tech.lastbox.jwt.TokenEntity

@Entity public class TokenEntity extends Object
Entity class representing a token in the system. This class is mapped to a database table for storing token-related information, such as token string, issue time, expiration time, subject, and revocation status.

The entity is typically used in conjunction with a repository or data access layer for persistence and retrieval of token data.

  • Constructor Details

    • TokenEntity

      public TokenEntity()
      Default constructor. Used by JPA for entity instantiation.
    • TokenEntity

      public TokenEntity(String token, Instant issuedAt, Instant expiresIn, String subject, String issuer, List<String> scope)
      Constructor to initialize a token entity with specified values.
      Parameters:
      token - the token string.
      issuedAt - the issue timestamp of the token.
      expiresIn - the expiration timestamp of the token.
      subject - the subject associated with the token.
  • Method Details

    • getToken

      public String getToken()
      Gets the token string.
      Returns:
      the token string.
    • getIssuedAt

      public Instant getIssuedAt()
      Gets the issued time of the token.
      Returns:
      the timestamp when the token was issued.
    • getExpiresIn

      public Instant getExpiresIn()
      Gets the expiration time of the token.
      Returns:
      the timestamp when the token expires.
    • getSubject

      public String getSubject()
      Gets the subject associated with the token.
      Returns:
      the subject (typically the user or entity) associated with the token.
    • isRevoked

      public boolean isRevoked()
      Checks if the token is revoked.
      Returns:
      true if the token is revoked, false otherwise.
    • setRevoked

      public void setRevoked(boolean isRevoked)
      Sets the revocation status of the token.
      Parameters:
      isRevoked - the new revocation status.
    • getIssuer

      public String getIssuer()
      Retrieves the issuer of the token.
      Returns:
      The issuer (e.g., system or service that generated the token).
    • getScope

      public List<String> getScope()
      Retrieves the scope associated with the token.

      The scope defines the permissions or roles that the token grants to the subject.

      Returns:
      A list of scope strings.
    • isExpired

      public boolean isExpired()
      Checks if the token is expired. A token is considered expired if its expiration time is null or before the current time.
      Returns:
      true if the token is expired, false otherwise.
    • isValid

      public boolean isValid()
      Checks if the token is valid. A token is valid if it is neither expired nor revoked.
      Returns:
      true if the token is valid, false otherwise.