Class JsonWebTokenUtils


  • public class JsonWebTokenUtils
    extends java.lang.Object
    Class with helper methods to create JWT token and validate it
    • Field Detail

      • PROPERTY_SECRET_KEY

        public static final java.lang.String PROPERTY_SECRET_KEY
        See Also:
        Constant Field Values
      • PROPERTY_ALGORITHM

        public static final java.lang.String PROPERTY_ALGORITHM
        See Also:
        Constant Field Values
      • PROPERTY_TIME_TO_LIVE

        public static final java.lang.String PROPERTY_TIME_TO_LIVE
        See Also:
        Constant Field Values
      • DEFAULT_ALGORITHM

        public static final java.lang.String DEFAULT_ALGORITHM
        See Also:
        Constant Field Values
    • Constructor Detail

      • JsonWebTokenUtils

        public JsonWebTokenUtils()
    • Method Detail

      • setKey

        public static void setKey​(char[] key)
      • setAlgorithm

        public static void setAlgorithm​(java.lang.String algorithm)
      • setTokenTTL

        public static void setTokenTTL​(int tokenTTL)
      • isValidToken

        public static boolean isValidToken​(java.lang.String compactJws)
        Validates if token signature is valid and not expired
        Parameters:
        compactJws -
        Returns:
        Throws:
        WebUtilsException
      • validateToken

        public static JsonWebTokenPayLoad validateToken​(java.lang.String compactJws)
                                                 throws io.jsonwebtoken.SignatureException,
                                                        io.jsonwebtoken.ExpiredJwtException,
                                                        WebUtilsException
        Parameters:
        compactJws -
        Returns:
        Throws:
        WebUtilsException - Validates if token signature is valid and not expired
        io.jsonwebtoken.SignatureException
        io.jsonwebtoken.ExpiredJwtException
      • encryptString

        public static java.lang.String encryptString​(java.lang.String str)
                                              throws java.security.GeneralSecurityException,
                                                     WebUtilsException
        Throws:
        java.security.GeneralSecurityException
        WebUtilsException
      • decryptString

        public static java.lang.String decryptString​(java.lang.String str)
                                              throws java.security.GeneralSecurityException,
                                                     WebUtilsException
        Throws:
        java.security.GeneralSecurityException
        WebUtilsException