Class JwtService

java.lang.Object
com.greenloop.auth_service.security.JwtService

@Service public class JwtService extends Object
Utility service for generating and validating JWT tokens.
  • Constructor Details

    • JwtService

      public JwtService()
  • Method Details

    • generateToken

      public String generateToken(User user)
      Generates a signed JWT for the given user with role and email claims.
    • extractAllClaims

      public io.jsonwebtoken.Claims extractAllClaims(String token)
      Parses and validates the token, returning all claims or throwing a descriptive exception for invalid/expired tokens.
    • extractClaim

      public <T> T extractClaim(String token, Function<io.jsonwebtoken.Claims,T> claimsResolver)
      Extracts a single claim using the provided resolver function.
    • extractUsername

      public String extractUsername(String token)
      Returns the email (username) from the token.
    • extractUserId

      public UUID extractUserId(String token)
      Returns the user id (subject) from the token.
    • extractRole

      public String extractRole(String token)
      Returns the role claim from the token.
    • extractExpiration

      public Date extractExpiration(String token)
      Returns expiration date of the token.
    • isTokenExpired

      public boolean isTokenExpired(String token)
      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

      public boolean isTokenValid(String token)
      Validates the token structure/signature and expiration.