Package tech.lastbox.jwt
Class TokenEntity
java.lang.Object
tech.lastbox.jwt.TokenEntity
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the expiration time of the token.Gets the issued time of the token.Retrieves the issuer of the token.getScope()Retrieves the scope associated with the token.Gets the subject associated with the token.getToken()Gets the token string.booleanChecks if the token is expired.booleanChecks if the token is revoked.booleanisValid()Checks if the token is valid.voidsetRevoked(boolean isRevoked) Sets the revocation status of the token.
-
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
Gets the token string.- Returns:
- the token string.
-
getIssuedAt
Gets the issued time of the token.- Returns:
- the timestamp when the token was issued.
-
getExpiresIn
Gets the expiration time of the token.- Returns:
- the timestamp when the token expires.
-
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
Retrieves the issuer of the token.- Returns:
- The issuer (e.g., system or service that generated the token).
-
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.
-