Package fr.paris.lutece.util.jwt.service
Class JWTUtil
java.lang.Object
fr.paris.lutece.util.jwt.service.JWTUtil
Utils class for JWT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringCheck the signature of the JWT with a secret keystatic booleancheckPayloadValues(javax.servlet.http.HttpServletRequest request, String strHeaderName, Map<String, String> claimsToCheck) Checks claims key/value inside the JWT payloadstatic booleancheckSignature(String strBase64JWT, Key key) Check a JWT signature with a Java security Keystatic booleancheckSignature(javax.servlet.http.HttpServletRequest request, String strHeaderName, Key key) Check the JWT signature with provided java security Key: this can be a RSA Public Keystatic booleancontainsValidUnsafeJWT(javax.servlet.http.HttpServletRequest request, String strHeaderName) Check if provided request contains a JWTstatic KeyGet a java security Key from a String secreyKey and algorythm namestatic StringgetPayloadValue(String strBase64JWT, String strClaimName) Get a payload value with given claimName;static StringgetPayloadValue(javax.servlet.http.HttpServletRequest request, String strHeaderName, String strClaimName) Get a payload value with given claimName;
-
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
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 requeststrHeaderName- The header namekey- 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 claimsexpirationDate- The expiration datestrAlgo- The algorythm namekey- The key- Returns:
- true if the signature is checked, false otherwise
-
getKey
Get a java security Key from a String secreyKey and algorythm name- Parameters:
strSecretKey- The secret KeystrAlgoName- The algorythm name- Returns:
- The java securitySecretKey
-
checkSignature
Check a JWT signature with a Java security Key- Parameters:
strBase64JWT-key-- Returns:
- true if the JWT is checked, false otherwise
-