Class JWTTokenService

java.lang.Object
com.almis.awe.config.ServiceConfig
com.almis.awe.rest.service.JWTTokenService
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

public class JWTTokenService extends ServiceConfig
Util class to manage authentication with JWT tokens.
See Also:
  • Constructor Details

    • JWTTokenService

      public JWTTokenService(String authorizationHeader, String prefix, String secret, String issuer, Duration expiration)
      JWTTokenService constructor
      Parameters:
      authorizationHeader - HTTP Auth header name
      prefix - JWT token prefix
      secret - JWT token secret
      issuer - JWT token issuer
      expiration - JWT token expiration
  • Method Details

    • getJWTVerifier

      public com.auth0.jwt.JWTVerifier getJWTVerifier()
      Get JWT verifier
    • generateToken

      public JwtTokenInfo generateToken(org.springframework.security.core.Authentication authentication, jakarta.servlet.http.HttpServletResponse response)
      Generate JWT Token and add it to http response as header
      Parameters:
      authentication - Authentication object
      response - HttpServletResponse
    • verifyToken

      public com.auth0.jwt.interfaces.DecodedJWT verifyToken(String token)
      Verify token. Check if it has JWT format and if not expired
      Parameters:
      token - JWT token
      Returns:
      Decode JWT token
    • extractToken

      public String extractToken(String authorizationHeader)
      Extract token from http Authorization header
      Parameters:
      authorizationHeader - Authorization header value
      Returns:
      JWT Token