Class JWTUtil

java.lang.Object
fr.paris.lutece.util.jwt.service.JWTUtil

public class JWTUtil extends Object
Utils class for JWT
  • Constructor Details

    • JWTUtil

      public JWTUtil()
  • Method Details

    • containsValidUnsafeJWT

      public static boolean containsValidUnsafeJWT(javax.servlet.http.HttpServletRequest request, String strHeaderName)
      Check if provided request contains a JWT
      Parameters:
      request -
      strHeaderName -
      Returns:
      true if the request contains a JWT, false othewise
    • checkPayloadValues

      public static boolean checkPayloadValues(javax.servlet.http.HttpServletRequest request, String strHeaderName, Map<String,String> claimsToCheck)
      Checks claims key/value inside the JWT payload
      Parameters:
      request -
      strHeaderName -
      claimsToCheck -
      Returns:
      true if the key/values are present, false otherwise
    • getPayloadValue

      public static String getPayloadValue(javax.servlet.http.HttpServletRequest request, String strHeaderName, String strClaimName)
      Get a payload value with given claimName;
      Parameters:
      request -
      strHeaderName -
      strClaimName -
      Returns:
      true if the key/values are present, false otherwise
    • getPayloadValue

      public static String getPayloadValue(String strBase64JWT, String strClaimName)
      Get a payload value with given claimName;
      Parameters:
      strBase64JWT -
      strClaimName -
      Returns:
      true if the key/values are present, false otherwise
    • checkSignature

      public static boolean checkSignature(javax.servlet.http.HttpServletRequest request, String strHeaderName, Key key)
      Check the JWT signature with provided java security Key: this can be a RSA Public Key
      Parameters:
      request - The request
      strHeaderName - The header name
      key - The key
      Returns:
      true if the signature of the JWT is checked; false otherwise
    • buildBase64JWT

      public static String buildBase64JWT(Map<String,String> mapClaims, Date expirationDate, String strAlgo, Key key)
      Check the signature of the JWT with a secret key
      Parameters:
      mapClaims - The map of claims
      expirationDate - The expiration date
      strAlgo - The algorythm name
      key - The key
      Returns:
      true if the signature is checked, false otherwise
    • getKey

      public static Key getKey(String strSecretKey, String strAlgoName)
      Get a java security Key from a String secreyKey and algorythm name
      Parameters:
      strSecretKey - The secret Key
      strAlgoName - The algorythm name
      Returns:
      The java securitySecretKey
    • checkSignature

      public static boolean checkSignature(String strBase64JWT, Key key)
      Check a JWT signature with a Java security Key
      Parameters:
      strBase64JWT -
      key -
      Returns:
      true if the JWT is checked, false otherwise