Package org.gcube.common.iam
Class AbstractIAMResponse
java.lang.Object
org.gcube.common.iam.AbstractIAMResponse
- All Implemented Interfaces:
IAMResponse
- Direct Known Subclasses:
D4ScienceIAMClientAuthn,D4ScienceIAMClientAuthz,OIDCBearerAuth
Abstract base class for D4Science IAM responses that implements common functionality
for handling authentication and authorization responses.
- Author:
- Luca Frosini (ISTI-CNR)
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractIAMResponse(D4ScienceIAMClient iamClient, org.gcube.common.keycloak.model.TokenResponse tokenResponse) Creates a new AbstractIAMResponse with the specified IAM client and token response. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if the current response can be refreshedorg.gcube.common.keycloak.model.AccessTokenReturns the access token in the response.Returns the access token in the response as string.Returns the client's contact organization from the tokenReturns the client's contact person from the tokenReturns the resource roles for the resource specified in the token contextReturns the realm roles in the tokenReturns the IAM client instance.getName()Returns the client's name from the tokenReturns the refresh token as a string.getResourceRoles(String resource) Returns the resource roles for the resource specified in the resource parametergetRoles()Returns all the roles, realm and from all the resources in the token in the same setprotected org.gcube.common.keycloak.model.TokenResponseReturns the token response.booleanQuick way to check if the access token is valid by checking the digital signature and the token expirationbooleanisAccessTokenValid(boolean checkExpiration) Quick way to check if the access token is valid by checking the digital signature and the token expiration if thecheckExpirationparameter istruebooleanCheck if the current response is expiredbooleanQuick way to check if the refresh token present in the current response and it is valid by checking the digital signature and the token expirationbooleanisRefreshTokenValid(boolean checkExpiration) Quick way to check if the refresh token present in the current response and it is valid by checking the digital signature and the token expiration if thecheckExpirationparameter istruevoidrefresh()Refreshes the current response, new data can be obtained again with accessors.voidRefreshes the token using the specified client credentials.voidsetIamClient(D4ScienceIAMClient iamClient) Sets the IAM client instance.voidsetTokenResponse(org.gcube.common.keycloak.model.TokenResponse tokenResponse) Sets the token response.voidVerifies the access token integrity and validity; token digital signature and expiration are reported via specific exceptions.voidVerifies the refresh token integrity and validity; token digital signature and expiration are reported via specific exceptions.
-
Constructor Details
-
AbstractIAMResponse
public AbstractIAMResponse(D4ScienceIAMClient iamClient, org.gcube.common.keycloak.model.TokenResponse tokenResponse) Creates a new AbstractIAMResponse with the specified IAM client and token response.- Parameters:
iamClient- the D4Science IAM client instancetokenResponse- the token response from the authentication/authorization process
-
-
Method Details
-
setIamClient
Sets the IAM client instance.- Parameters:
iamClient- the D4Science IAM client to set
-
getIamClient
Returns the IAM client instance.- Returns:
- the D4Science IAM client
-
setTokenResponse
public void setTokenResponse(org.gcube.common.keycloak.model.TokenResponse tokenResponse) Sets the token response.- Parameters:
tokenResponse- the token response to set
-
getTokenResponse
protected org.gcube.common.keycloak.model.TokenResponse getTokenResponse()Returns the token response.- Returns:
- the token response
-
getAccessToken
public org.gcube.common.keycloak.model.AccessToken getAccessToken() throws D4ScienceIAMClientExceptionDescription copied from interface:IAMResponseReturns the access token in the response.- Specified by:
getAccessTokenin interfaceIAMResponse- Returns:
- The access token
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getAccessTokenString
Description copied from interface:IAMResponseReturns the access token in the response as string.- Specified by:
getAccessTokenStringin interfaceIAMResponse- Returns:
- The access token as string
-
isExpired
Description copied from interface:IAMResponseCheck if the current response is expired- Specified by:
isExpiredin interfaceIAMResponse- Returns:
trueif the response is expired,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getRefreshTokenString
Returns the refresh token as a string.- Returns:
- the refresh token string
-
canBeRefreshed
Description copied from interface:IAMResponseCheck if the current response can be refreshed- Specified by:
canBeRefreshedin interfaceIAMResponse- Returns:
trueif the response can be refreshed,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
refresh
Description copied from interface:IAMResponseRefreshes the current response, new data can be obtained again with accessors.- Specified by:
refreshin interfaceIAMResponse- Throws:
D4ScienceIAMClientException- if something goes wrong during the token refresh
-
refresh
Refreshes the token using the specified client credentials.- Parameters:
clientId- the client IDclientSecret- the client secret- Throws:
D4ScienceIAMClientException- if an error occurs during token refresh
-
getGlobalRoles
Description copied from interface:IAMResponseReturns the realm roles in the token- Specified by:
getGlobalRolesin interfaceIAMResponse- Returns:
- the realm roles
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getRoles
Description copied from interface:IAMResponseReturns all the roles, realm and from all the resources in the token in the same set- Specified by:
getRolesin interfaceIAMResponse- Returns:
- the union of all the roles in the token
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getResourceRoles
Description copied from interface:IAMResponseReturns the resource roles for the resource specified in the resource parameter- Specified by:
getResourceRolesin interfaceIAMResponse- Parameters:
resource- the resource of which obtain the roles- Returns:
- the roles for the resource
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getContextRoles
Description copied from interface:IAMResponseReturns the resource roles for the resource specified in the token context- Specified by:
getContextRolesin interfaceIAMResponse- Returns:
- the token context's roles
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getName
Description copied from interface:IAMResponseReturns the client's name from the token- Specified by:
getNamein interfaceIAMResponse- Returns:
- the name string
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getContactPerson
Description copied from interface:IAMResponseReturns the client's contact person from the token- Specified by:
getContactPersonin interfaceIAMResponse- Returns:
- the contact person string
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getContactOrganization
Description copied from interface:IAMResponseReturns the client's contact organization from the token- Specified by:
getContactOrganizationin interfaceIAMResponse- Returns:
- the contact organization string
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
isAccessTokenValid
Description copied from interface:IAMResponseQuick way to check if the access token is valid by checking the digital signature and the token expiration- Specified by:
isAccessTokenValidin interfaceIAMResponse- Returns:
trueif the access token is valid,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token validity checks
-
isAccessTokenValid
Description copied from interface:IAMResponseQuick way to check if the access token is valid by checking the digital signature and the token expiration if thecheckExpirationparameter istrue- Specified by:
isAccessTokenValidin interfaceIAMResponse- Parameters:
checkExpiration- checks also if the token is expired- Returns:
trueif the access token is valid,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token validity checks
-
verifyAccessToken
public void verifyAccessToken() throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, D4ScienceIAMClientExceptionDescription copied from interface:IAMResponseVerifies the access token integrity and validity; token digital signature and expiration are reported via specific exceptions.- Specified by:
verifyAccessTokenin interfaceIAMResponse- Throws:
org.gcube.io.jsonwebtoken.security.SignatureException- if the token has been tampered and/or signature is invalidorg.gcube.io.jsonwebtoken.ExpiredJwtException- if the token validity is expiredD4ScienceIAMClientException- if something else goes wrong during the token verification
-
isRefreshTokenValid
Description copied from interface:IAMResponseQuick way to check if the refresh token present in the current response and it is valid by checking the digital signature and the token expiration- Specified by:
isRefreshTokenValidin interfaceIAMResponse- Returns:
trueif the refresh token is valid,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token validity checks
-
isRefreshTokenValid
Description copied from interface:IAMResponseQuick way to check if the refresh token present in the current response and it is valid by checking the digital signature and the token expiration if thecheckExpirationparameter istrue- Specified by:
isRefreshTokenValidin interfaceIAMResponse- Parameters:
checkExpiration- checks also if the token is expired- Returns:
trueif the refresh token is valid,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token validity checks
-
verifyRefreshToken
public void verifyRefreshToken() throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, D4ScienceIAMClientExceptionDescription copied from interface:IAMResponseVerifies the refresh token integrity and validity; token digital signature and expiration are reported via specific exceptions.- Specified by:
verifyRefreshTokenin interfaceIAMResponse- Throws:
org.gcube.io.jsonwebtoken.security.SignatureException- if the token has been tampered and/or signature is invalidorg.gcube.io.jsonwebtoken.ExpiredJwtException- if the token validity is expiredD4ScienceIAMClientException- if something else goes wrong during the token verification
-