Package org.gcube.common.keycloak.model
Class ModelUtils
java.lang.Object
org.gcube.common.keycloak.model.ModelUtils
- Author:
- Mauro Mugnaini
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 booleanVerifies the token validitystatic booleanVerifies the token validityprotected static StringsplitAndGet(String encodedJWT, int index) static StringtoJSONString(Object object) static StringtoJSONString(Object object, boolean prettyPrint) static voidVerifies the token signature and expiration
-
Field Details
-
logger
protected static final org.slf4j.Logger logger
-
-
Constructor Details
-
ModelUtils
public ModelUtils()
-
-
Method Details
-
toJSONString
-
toJSONString
-
createRSAPublicKey
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
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
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
- Throws:
Exception
-
getAccessTokenFrom
public static AccessToken getAccessTokenFrom(String authorizationHeaderOrBase64EncodedJWT) throws Exception - Throws:
Exception
-
getRefreshTokenPayloadStringFrom
- Throws:
Exception
-
getRefreshTokenPayloadStringFrom
public static String getRefreshTokenPayloadStringFrom(TokenResponse tokenResponse, boolean prettyPrint) throws Exception - Throws:
Exception
-
getRefreshTokenFrom
- Throws:
Exception
-
getRefreshTokenFrom
- Throws:
Exception
-
getBase64Decoded
-
splitAndGet
-
getDecodedHeader
-
getEncodedHeader
-
getDecodedPayload
-
getEncodedPayload
-
getDecodedSignature
-
getEncodedSignature
-
getClientIdFromToken
-