public class AbstractIAMResponse extends Object implements IAMResponse
| Constructor and Description |
|---|
AbstractIAMResponse(D4ScienceIAMClient iamClient,
org.gcube.common.keycloak.model.TokenResponse tokenResponse)
Creates a new AbstractIAMResponse with the specified IAM client and token response.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canBeRefreshed()
Check if the current response can be refreshed
|
org.gcube.common.keycloak.model.AccessToken |
getAccessToken()
Returns the access token in the response.
|
String |
getAccessTokenString()
Returns the access token in the response as string.
|
String |
getContactOrganization()
Returns the client's contact organization from the token
|
String |
getContactPerson()
Returns the client's contact person from the token
|
Set<String> |
getContextRoles()
Returns the resource roles for the resource specified in the token context
|
Set<String> |
getGlobalRoles()
Returns the realm roles in the token
|
D4ScienceIAMClient |
getIamClient()
Returns the IAM client instance.
|
String |
getName()
Returns the client's name from the token
|
String |
getRefreshTokenString()
Returns the refresh token as a string.
|
Set<String> |
getResourceRoles(String resource)
Returns the resource roles for the resource specified in the resource parameter
|
Set<String> |
getRoles()
Returns all the roles, realm and from all the resources in the token in the same set
|
protected org.gcube.common.keycloak.model.TokenResponse |
getTokenResponse()
Returns the token response.
|
boolean |
isAccessTokenValid()
Quick way to check if the access token is valid by checking the digital signature and the token expiration
|
boolean |
isAccessTokenValid(boolean checkExpiration)
Quick way to check if the access token is valid by checking the digital signature and the token expiration if the
checkExpiration parameter is true |
boolean |
isExpired()
Check if the current response is expired
|
boolean |
isRefreshTokenValid()
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
|
boolean |
isRefreshTokenValid(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 the
checkExpiration parameter is true |
void |
refresh()
Refreshes the current response, new data can be obtained again with accessors.
|
void |
refresh(String clientId,
String clientSecret)
Refreshes the token using the specified client credentials.
|
void |
setIamClient(D4ScienceIAMClient iamClient)
Sets the IAM client instance.
|
void |
setTokenResponse(org.gcube.common.keycloak.model.TokenResponse tokenResponse)
Sets the token response.
|
void |
verifyAccessToken()
Verifies the access token integrity and validity; token digital signature and expiration are reported via specific exceptions.
|
void |
verifyRefreshToken()
Verifies the refresh token integrity and validity; token digital signature and expiration are reported via specific exceptions.
|
public AbstractIAMResponse(D4ScienceIAMClient iamClient, org.gcube.common.keycloak.model.TokenResponse tokenResponse)
iamClient - the D4Science IAM client instancetokenResponse - the token response from the authentication/authorization processpublic void setIamClient(D4ScienceIAMClient iamClient)
iamClient - the D4Science IAM client to setpublic D4ScienceIAMClient getIamClient()
public void setTokenResponse(org.gcube.common.keycloak.model.TokenResponse tokenResponse)
tokenResponse - the token response to setprotected org.gcube.common.keycloak.model.TokenResponse getTokenResponse()
public org.gcube.common.keycloak.model.AccessToken getAccessToken()
throws D4ScienceIAMClientException
IAMResponsegetAccessToken in interface IAMResponseD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic String getAccessTokenString()
IAMResponsegetAccessTokenString in interface IAMResponsepublic boolean isExpired()
throws D4ScienceIAMClientException
IAMResponseisExpired in interface IAMResponsetrue if the response is expired, false otherwiseD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic String getRefreshTokenString()
public boolean canBeRefreshed()
throws D4ScienceIAMClientException
IAMResponsecanBeRefreshed in interface IAMResponsetrue if the response can be refreshed, false otherwiseD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic void refresh()
throws D4ScienceIAMClientException
IAMResponserefresh in interface IAMResponseD4ScienceIAMClientException - if something goes wrong during the token refreshpublic void refresh(String clientId, String clientSecret) throws D4ScienceIAMClientException
clientId - the client IDclientSecret - the client secretD4ScienceIAMClientException - if an error occurs during token refreshpublic Set<String> getGlobalRoles() throws D4ScienceIAMClientException
IAMResponsegetGlobalRoles in interface IAMResponseD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic Set<String> getRoles() throws D4ScienceIAMClientException
IAMResponsegetRoles in interface IAMResponseD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic Set<String> getResourceRoles(String resource) throws D4ScienceIAMClientException
IAMResponsegetResourceRoles in interface IAMResponseresource - the resource of which obtain the rolesD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic Set<String> getContextRoles() throws D4ScienceIAMClientException
IAMResponsegetContextRoles in interface IAMResponseD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic String getName() throws D4ScienceIAMClientException
IAMResponsegetName in interface IAMResponseD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic String getContactPerson() throws D4ScienceIAMClientException
IAMResponsegetContactPerson in interface IAMResponseD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic String getContactOrganization() throws D4ScienceIAMClientException
IAMResponsegetContactOrganization in interface IAMResponseD4ScienceIAMClientException - if something goes wrong during the token decoding or JSON parsingpublic boolean isAccessTokenValid()
throws D4ScienceIAMClientException
IAMResponseisAccessTokenValid in interface IAMResponsetrue if the access token is valid, false otherwiseD4ScienceIAMClientException - if something goes wrong during the token validity checkspublic boolean isAccessTokenValid(boolean checkExpiration)
throws D4ScienceIAMClientException
IAMResponsecheckExpiration parameter is trueisAccessTokenValid in interface IAMResponsecheckExpiration - checks also if the token is expiredtrue if the access token is valid, false otherwiseD4ScienceIAMClientException - if something goes wrong during the token validity checkspublic void verifyAccessToken()
throws org.gcube.io.jsonwebtoken.security.SignatureException,
org.gcube.io.jsonwebtoken.ExpiredJwtException,
D4ScienceIAMClientException
IAMResponseverifyAccessToken in interface IAMResponseorg.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 verificationpublic boolean isRefreshTokenValid()
throws D4ScienceIAMClientException
IAMResponseisRefreshTokenValid in interface IAMResponsetrue if the refresh token is valid, false otherwiseD4ScienceIAMClientException - if something goes wrong during the token validity checkspublic boolean isRefreshTokenValid(boolean checkExpiration)
throws D4ScienceIAMClientException
IAMResponsecheckExpiration parameter is trueisRefreshTokenValid in interface IAMResponsecheckExpiration - checks also if the token is expiredtrue if the refresh token is valid, false otherwiseD4ScienceIAMClientException - if something goes wrong during the token validity checkspublic void verifyRefreshToken()
throws org.gcube.io.jsonwebtoken.security.SignatureException,
org.gcube.io.jsonwebtoken.ExpiredJwtException,
D4ScienceIAMClientException
IAMResponseverifyRefreshToken in interface IAMResponseorg.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 verificationCopyright © 2026. All rights reserved.