Package org.gcube.common.iam
Interface IAMResponse
- All Known Implementing Classes:
AbstractIAMResponse,D4ScienceIAMClientAuthn,D4ScienceIAMClientAuthn4Client,D4ScienceIAMClientAuthn4Code,D4ScienceIAMClientAuthn4Tokens,D4ScienceIAMClientAuthn4User,D4ScienceIAMClientAuthz,OIDCBearerAuth
public interface IAMResponse
Interface for D4Science IAM response handling.
Provides methods to access tokens, custom claims, and authentication information.
- Author:
- Mauro Mugnaini (Nubisware S.r.l.)
-
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if the current response can be refreshedvoidExchanges and updates the current response with new one obtained with parameters provided.org.gcube.common.keycloak.model.AccessTokenReturns the access token in the response.Returns the access token in the response as string.default String[]Returns theaudclaim of the access token, as in the token (the contexts are URL-encoded)default StringReturns theazpclaim of the access token: the client the token was issued toReturns the client's contact organization from the tokenReturns the client's contact person from the tokenReturns the token context is issued for This is done by checking in the order: If the token contains thed4s_contextclaim, as specified also inKeycloakClient.D4S_DYNAMIC_SCOPE_NAME_TOKEN_CLAIMThe value of theaudclaim if contains a single value (for retro-compatibility) It returnsnullif none of the options are satisfied and the context cannot be determined.Returns the resource roles for the resource specified in the token contextdefault StringgetEmail()Returns theemailclaim of the access tokendefault StringReturns thefamily_nameclaim of the access tokendefault StringReturns thegiven_nameclaim of the access tokenReturns the realm roles in the tokengetName()Returns the client's name from the tokendefault StringReturns thepreferred_usernameclaim of the access tokenReturns the roles of the token per resource (client), as in theresource_accessclaim.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 setdefault StringReturns thesubclaim of the access tokenbooleanQuick 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.voidVerifies the access token integrity and validity; token digital signature and expiration are reported via specific exceptions.voidverifyAccessToken(boolean checkExpiration) Verifies the access token integrity and optionally for expiration; 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.voidverifyRefreshToken(boolean checkExpiration) Verifies the refresh token integrity and validity; token digital signature and expiration are reported via specific exceptions.
-
Method Details
-
getAccessToken
Returns the access token in the response.- Returns:
- The access token
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getAccessTokenString
String getAccessTokenString()Returns the access token in the response as string.- Returns:
- The access token as string
-
isExpired
Check if the current response is expired- Returns:
trueif the response is expired,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
canBeRefreshed
Check if the current response can be refreshed- Returns:
trueif the response can be refreshed,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
refresh
Refreshes the current response, new data can be obtained again with accessors.- Throws:
D4ScienceIAMClientException- if something goes wrong during the token refresh
-
getContext
Returns the token context is issued for This is done by checking in the order:- If the token contains the
d4s_contextclaim, as specified also inKeycloakClient.D4S_DYNAMIC_SCOPE_NAME_TOKEN_CLAIM - The value of the
audclaim if contains a single value (for retro-compatibility)
nullif none of the options are satisfied and the context cannot be determined.- Returns:
- the token context or
null - Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
- If the token contains the
-
getContextRoles
Returns the resource roles for the resource specified in the token context- Returns:
- the token context's roles
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getResourceRoles
Returns the resource roles for the resource specified in the resource parameter- 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
-
getRoles
Returns all the roles, realm and from all the resources in the token in the same set- Returns:
- the union of all the roles in the token
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getResourceAccessRoles
Returns the roles of the token per resource (client), as in theresource_accessclaim. The resources are the contexts for a D4Science token, but also the Keycloak built-in clients (e.g.account): callers interested in the contexts only skip them.- Returns:
- a new map resource to roles, empty if the token has no
resource_accessclaim - Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getAudience
Returns theaudclaim of the access token, as in the token (the contexts are URL-encoded)- Returns:
- the audiences, an empty array if the token has none
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getSubject
Returns thesubclaim of the access token- Returns:
- the subject or
null - Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getAuthorizedParty
Returns theazpclaim of the access token: the client the token was issued to- Returns:
- the authorized party or
null - Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getEmail
Returns theemailclaim of the access token- Returns:
- the e-mail address or
null - Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getGivenName
Returns thegiven_nameclaim of the access token- Returns:
- the given name or
null - Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getFamilyName
Returns thefamily_nameclaim of the access token- Returns:
- the family name or
null - Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getPreferredUsername
Returns thepreferred_usernameclaim of the access token- Returns:
- the preferred username or
null - Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getGlobalRoles
Returns the realm roles in the token- Returns:
- the realm roles
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getContactOrganization
Returns the client's contact organization from the token- Returns:
- the contact organization string
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getContactPerson
Returns the client's contact person from the token- Returns:
- the contact person string
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
getName
Returns the client's name from the token- Returns:
- the name string
- Throws:
D4ScienceIAMClientException- if something goes wrong during the token decoding or JSON parsing
-
isAccessTokenValid
Quick way to check if the access token is valid by checking the digital signature and the token expiration- Returns:
trueif the access token is valid,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token validity checks
-
isAccessTokenValid
Quick way to check if the access token is valid by checking the digital signature and the token expiration if thecheckExpirationparameter istrue- 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
void verifyAccessToken() throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, D4ScienceIAMClientExceptionVerifies the access token integrity and validity; token digital signature and expiration are reported via specific exceptions.- 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
-
verifyAccessToken
void verifyAccessToken(boolean checkExpiration) throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, D4ScienceIAMClientException Verifies the access token integrity and optionally for expiration; token digital signature and expiration are reported via specific exceptions.- Parameters:
checkExpiration- iffalsetoken expiration check is disabled- 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 expired if thecheckExpirationargument istrueD4ScienceIAMClientException- if something else goes wrong during the token verification
-
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- Returns:
trueif the refresh token is valid,falseotherwise- Throws:
D4ScienceIAMClientException- if something goes wrong during the token validity checks
-
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 if thecheckExpirationparameter istrue- 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
void verifyRefreshToken() throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, D4ScienceIAMClientExceptionVerifies the refresh token integrity and validity; token digital signature and expiration are reported via specific exceptions.- 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
-
verifyRefreshToken
void verifyRefreshToken(boolean checkExpiration) throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, D4ScienceIAMClientException Verifies the refresh token integrity and validity; token digital signature and expiration are reported via specific exceptions.- Parameters:
checkExpiration- iffalsetoken expiration check is disabled- 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 expired if thecheckExpirationargument istrueD4ScienceIAMClientException- if something else goes wrong during the token verification
-
exchange
void exchange(String clientId, String clientSecret, String audience, String scope) throws D4ScienceIAMClientException Exchanges and updates the current response with new one obtained with parameters provided.- Parameters:
clientId- the client id to be used for the exchangeclientSecret- the client secret to be used for the exchangeaudience- the audience to specify in the exchange, can benullscope- the scope (as standard space separated list) to specify in the exchange, can benull- Throws:
D4ScienceIAMClientException- if something goes wrong during the token exchange
-