Package com.microstrategy.utils
Class JsonWebTokenUtils
- java.lang.Object
-
- com.microstrategy.utils.JsonWebTokenUtils
-
public class JsonWebTokenUtils extends java.lang.ObjectClass with helper methods to create JWT token and validate it
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_ALGORITHMstatic java.lang.StringPROPERTY_ALGORITHMstatic java.lang.StringPROPERTY_SECRET_KEYstatic java.lang.StringPROPERTY_TIME_TO_LIVE
-
Constructor Summary
Constructors Constructor Description JsonWebTokenUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringdecryptString(java.lang.String str)static java.lang.StringencryptString(java.lang.String str)static java.lang.StringgenerateToken(JsonWebTokenPayLoad payload)Generate JWT Token with the supplied payloadstatic booleanisValidToken(java.lang.String compactJws)Validates if token signature is valid and not expiredstatic voidsetAlgorithm(java.lang.String algorithm)static voidsetKey(char[] key)static voidsetTokenTTL(int tokenTTL)static JsonWebTokenPayLoadvalidateToken(java.lang.String compactJws)
-
-
-
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
-
-
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)
-
generateToken
public static java.lang.String generateToken(JsonWebTokenPayLoad payload) throws WebUtilsException
Generate JWT Token with the supplied payload- Parameters:
payload-- Returns:
- Throws:
WebUtilsException
-
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 expiredio.jsonwebtoken.SignatureExceptionio.jsonwebtoken.ExpiredJwtException
-
encryptString
public static java.lang.String encryptString(java.lang.String str) throws java.security.GeneralSecurityException, WebUtilsException- Throws:
java.security.GeneralSecurityExceptionWebUtilsException
-
decryptString
public static java.lang.String decryptString(java.lang.String str) throws java.security.GeneralSecurityException, WebUtilsException- Throws:
java.security.GeneralSecurityExceptionWebUtilsException
-
-