Package com.microstrategy.utils
Class JsonWebTokenUtils
- java.lang.Object
-
- com.microstrategy.utils.JsonWebTokenUtils
-
public class JsonWebTokenUtils extends java.lang.Object
Class with helper methods to create JWT token and validate it
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_ALGORITHM
static java.lang.String
PROPERTY_ALGORITHM
static java.lang.String
PROPERTY_SECRET_KEY
static java.lang.String
PROPERTY_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.String
decryptString(java.lang.String str)
static java.lang.String
encryptString(java.lang.String str)
static java.lang.String
generateToken(JsonWebTokenPayLoad payload)
Generate JWT Token with the supplied payloadstatic boolean
isValidToken(java.lang.String compactJws)
Validates if token signature is valid and not expiredstatic void
setAlgorithm(java.lang.String algorithm)
static void
setKey(char[] key)
static void
setTokenTTL(int tokenTTL)
static JsonWebTokenPayLoad
validateToken(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.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
-
-