Class JwtUtil

java.lang.Object
balu.pizza.webapp.security.JwtUtil

@Component public class JwtUtil extends Object
A class for generating and validating JWT-token

When accessing through the project's REST API, authentication is required. If authorization is successful, a generated, unique JWT token is returned to the user in the response. By adding this token to the header of all subsequent requests, the user can confirm that the requests come from an authorized user.

The token has a validity of 60 minutes. If the user wants to interact with the server for longer, he/she needs to reauthorize and get a new token

  • Constructor Details

    • JwtUtil

      public JwtUtil()
  • Method Details

    • generateToken

      public String generateToken(String username)
      Generate JWT-token
      Parameters:
      username -
      Returns:
      JWT-token
    • validateTokenAndRetrieveClaim

      public String validateTokenAndRetrieveClaim(String token) throws com.auth0.jwt.exceptions.JWTVerificationException
      Validate JWT-token
      Parameters:
      token -
      Returns:
      Throws:
      com.auth0.jwt.exceptions.JWTVerificationException - - the token did not pass validation