Class JwtService
java.lang.Object
com.greenloop.auth_service.security.JwtService
Utility service for generating and validating JWT tokens.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionio.jsonwebtoken.ClaimsextractAllClaims(String token) Parses and validates the token, returning all claims or throwing a descriptive exception for invalid/expired tokens.<T> TextractClaim(String token, Function<io.jsonwebtoken.Claims, T> claimsResolver) Extracts a single claim using the provided resolver function.extractExpiration(String token) Returns expiration date of the token.extractRole(String token) Returns the role claim from the token.extractUserId(String token) Returns the user id (subject) from the token.extractUsername(String token) Returns the email (username) from the token.generateToken(User user) Generates a signed JWT for the given user with role and email claims.booleanisTokenExpired(String token) Indicates whether the token is expired.booleanisTokenValid(String token) Validates the token structure/signature and expiration.booleanisTokenValid(String token, org.springframework.security.core.userdetails.UserDetails userDetails) Validates the token against the given user details.
-
Constructor Details
-
JwtService
public JwtService()
-
-
Method Details
-
generateToken
Generates a signed JWT for the given user with role and email claims. -
extractAllClaims
Parses and validates the token, returning all claims or throwing a descriptive exception for invalid/expired tokens. -
extractClaim
Extracts a single claim using the provided resolver function. -
extractUsername
Returns the email (username) from the token. -
extractUserId
Returns the user id (subject) from the token. -
extractRole
Returns the role claim from the token. -
extractExpiration
Returns expiration date of the token. -
isTokenExpired
Indicates whether the token is expired. -
isTokenValid
public boolean isTokenValid(String token, org.springframework.security.core.userdetails.UserDetails userDetails) Validates the token against the given user details. -
isTokenValid
Validates the token structure/signature and expiration.
-