Package org.gcube.common.keycloak.model
Class ModelUtils
- java.lang.Object
-
- org.gcube.common.keycloak.model.ModelUtils
-
public class ModelUtils extends Object
- Author:
- Mauro Mugnaini
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classModelUtils.GcubeJacksonDeserializer
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Loggerlogger
-
Constructor Summary
Constructors Constructor Description ModelUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PublicKeycreatePublicKey(String publicKeyPem, String algorithm)Creates aPublicKeyinstance from its string PEM representationstatic RSAPublicKeycreateRSAPublicKey(String publicKeyPem)Creates aRSAPublicKeyinstance from its string PEM representationstatic AccessTokengetAccessTokenFrom(String authorizationHeaderOrBase64EncodedJWT)static AccessTokengetAccessTokenFrom(TokenResponse tokenResponse)static StringgetAccessTokenPayloadJSONStringFrom(TokenResponse tokenResponse)static StringgetAccessTokenPayloadJSONStringFrom(TokenResponse tokenResponse, boolean prettyPrint)protected static byte[]getBase64Decoded(String string)static StringgetClientIdFromToken(AccessToken accessToken)static byte[]getDecodedHeader(String value)static byte[]getDecodedPayload(String value)static byte[]getDecodedSignature(String value)static StringgetEncodedHeader(String encodedJWT)static StringgetEncodedPayload(String encodedJWT)static StringgetEncodedSignature(String encodedJWT)static RefreshTokengetRefreshTokenFrom(String base64EncodedJWT)static RefreshTokengetRefreshTokenFrom(TokenResponse tokenResponse)static StringgetRefreshTokenPayloadStringFrom(TokenResponse tokenResponse)static StringgetRefreshTokenPayloadStringFrom(TokenResponse tokenResponse, boolean prettyPrint)static booleanisValid(String token, PublicKey publicKey)Verifies the token validitystatic booleanisValid(String token, PublicKey publicKey, boolean checkExpiration)Verifies the token validityprotected static StringsplitAndGet(String encodedJWT, int index)static StringtoJSONString(Object object)static StringtoJSONString(Object object, boolean prettyPrint)static voidverify(String token, PublicKey publicKey)Verifies the token signature and expiration
-
-
-
Method Detail
-
createRSAPublicKey
public static RSAPublicKey createRSAPublicKey(String publicKeyPem) throws Exception
Creates aRSAPublicKeyinstance from its string PEM representation- Parameters:
publicKeyPem- the public key PEM string- Returns:
- the RSA public key
- Throws:
Exception- if it's not possible to create the RSA public key from the PEM string
-
createPublicKey
public static PublicKey createPublicKey(String publicKeyPem, String algorithm) throws Exception
Creates aPublicKeyinstance from its string PEM representation- Parameters:
publicKeyPem- the public key PEM stringalgorithm- the key type (e.g. RSA)- Returns:
- the public key
- Throws:
Exception- if it's not possible to create the public key from the PEM string
-
isValid
public static boolean isValid(String token, PublicKey publicKey) throws Exception
Verifies the token validity- Parameters:
token- the base64 JWT token stringpublicKey- the realm's public key on server- Returns:
trueif the token is valid,falseotherwise- Throws:
Exception- if an error occurs constructing the verifier
-
isValid
public static boolean isValid(String token, PublicKey publicKey, boolean checkExpiration) throws Exception
Verifies the token validity- Parameters:
token- the base64 JWT token stringpublicKey- the public key to use for verificationcheckExpiration- iffalsetoken expiration check is disabled- Returns:
trueif the token is valid,falseotherwise- Throws:
Exception- if an unexpected error occurs (e.g. constructing the verifier)
-
verify
public static void verify(String token, PublicKey publicKey) throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, org.gcube.io.jsonwebtoken.JwtException, Exception
Verifies the token signature and expiration- Parameters:
token- the base64 JWT token stringpublicKey- the public key to use for verification- Throws:
org.gcube.io.jsonwebtoken.security.SignatureException- if the token signature is invalidorg.gcube.io.jsonwebtoken.ExpiredJwtException- if the token is expiredorg.gcube.io.jsonwebtoken.JwtException- if a JWT related problem is foundException- if an unexpected error occurs (e.g. constructing the verifier)
-
getAccessTokenPayloadJSONStringFrom
public static String getAccessTokenPayloadJSONStringFrom(TokenResponse tokenResponse) throws Exception
- Throws:
Exception
-
getAccessTokenPayloadJSONStringFrom
public static String getAccessTokenPayloadJSONStringFrom(TokenResponse tokenResponse, boolean prettyPrint) throws Exception
- Throws:
Exception
-
getAccessTokenFrom
public static AccessToken getAccessTokenFrom(TokenResponse tokenResponse) throws Exception
- Throws:
Exception
-
getAccessTokenFrom
public static AccessToken getAccessTokenFrom(String authorizationHeaderOrBase64EncodedJWT) throws Exception
- Throws:
Exception
-
getRefreshTokenPayloadStringFrom
public static String getRefreshTokenPayloadStringFrom(TokenResponse tokenResponse) throws Exception
- Throws:
Exception
-
getRefreshTokenPayloadStringFrom
public static String getRefreshTokenPayloadStringFrom(TokenResponse tokenResponse, boolean prettyPrint) throws Exception
- Throws:
Exception
-
getRefreshTokenFrom
public static RefreshToken getRefreshTokenFrom(TokenResponse tokenResponse) throws Exception
- Throws:
Exception
-
getRefreshTokenFrom
public static RefreshToken getRefreshTokenFrom(String base64EncodedJWT) throws Exception
- Throws:
Exception
-
getBase64Decoded
protected static byte[] getBase64Decoded(String string)
-
getDecodedHeader
public static byte[] getDecodedHeader(String value)
-
getDecodedPayload
public static byte[] getDecodedPayload(String value)
-
getDecodedSignature
public static byte[] getDecodedSignature(String value)
-
getClientIdFromToken
public static String getClientIdFromToken(AccessToken accessToken)
-
-