public interface KeycloakClient
| Modifier and Type | Field and Description |
|---|---|
static String |
AVATAR_URI_PATH |
static String |
D4S_CONTEXT_HEADER_NAME |
static String |
D4S_DYNAMIC_SCOPE_NAME |
static String |
D4S_DYNAMIC_SCOPE_NAME_TOKEN_CLAIM |
static String |
D4S_EU_EXTENDED_PROFILE_SCOPE |
static String |
D4S_IDENTITY_SCOPE |
static String |
DEFAULT_DYNAMIC_SCOPE_SEPARATOR |
static String |
DEFAULT_REALM |
static String |
JWK_URI_PATH |
static String |
OPEN_ID_URI_PATH |
static String |
PROD_ROOT_SCOPE |
static String |
TOKEN_INTROSPECT_URI_PATH |
static String |
TOKEN_URI_PATH |
| Modifier and Type | Method and Description |
|---|---|
KeycloakClient |
addDynamicScope(String dynamicScope,
String value)
Adds the dynamic scope to the list of scopes to use for the next OIDC token
requests
|
KeycloakClient |
addScopes(List<String> scopes)
Adds the provided OIDC scopes to the list of scopes to use for the next OIDC
token requests
|
URL |
computeIntrospectionEndpointURL(URL tokenEndpointURL)
Compute the keycloak
introspection endpoint URL starting
from the provided token endpoint. |
TokenResponse |
exchangeTokenForAccessToken(String context,
String oidcAccessToken,
String clientId,
String clientSecret,
String audience)
Exchanges a token for another access token for a specific client and a
specific audience
|
TokenResponse |
exchangeTokenForAccessToken(URL tokenURL,
String oidcAccessToken,
String clientId,
String clientSecret,
String audience)
Exchanges a token for another access token for a specific client and a
specific audience
|
TokenResponse |
exchangeTokenForOfflineToken(String context,
String oidcAccessToken,
String clientId,
String clientSecret,
String audience)
Exchanges a token for another access and an offline refresh tokens for a
specific client and a specific audience
The refresh token will be of the offline type only if the original token has
the
offline_access within its scopes |
TokenResponse |
exchangeTokenForOfflineToken(URL tokenURL,
String oidcAccessToken,
String clientId,
String clientSecret,
String audience)
Exchanges a token for another access and an offline refresh tokens for a
specific client and a specific audience
The refresh token will be of the offline type only if the original token has
the scope
offline_access within its scopes |
TokenResponse |
exchangeTokenForRefreshToken(String context,
String oidcAccessToken,
String clientId,
String clientSecret,
String audience)
Exchanges a token for another access and a refresh tokens for a specific
client and a specific audience
|
TokenResponse |
exchangeTokenForRefreshToken(URL tokenURL,
String oidcAccessToken,
String clientId,
String clientSecret,
String audience)
Exchanges a token for another access and a refresh tokens for a specific
client and a specific audience
|
byte[] |
getAvatarData(String context,
TokenResponse tokenResponse)
Retrieves the user's avatar image data from Keycloak server.
|
byte[] |
getAvatarData(URL avatarURL,
String authorization)
Retrieves the user's avatar image data from Keycloak server.
|
byte[] |
getAvatarData(URL avatarURL,
TokenResponse tokenResponse)
Retrieves the user's avatar image data from Keycloak server.
|
URL |
getAvatarEndpointURL(URL realmBaseURL)
Constructs the Keycloak
avatar endpoint URL from the
realm's base URL. |
URL |
getIntrospectionEndpointURL(URL realmBaseURL)
Constructs the Keycloak
introspection endpoint URL from
the realm's base URL. |
URL |
getJWKEndpointURL(URL realmBaseURL)
Constructs the Keycloak
JWK endpoint URL from the
realm's base URL. |
URL |
getRealmBaseURL(String context)
Returns the Keycloak base
URL for the given context and the default
realm (d4science) |
URL |
getRealmBaseURL(String context,
String realm)
Returns the Keycloak base
URL for the given context and in the given
realm. |
PublishedRealmRepresentation |
getRealmInfo(URL realmURL)
Gets the realm info setup (RSA
public_key,
token-service URL,
account-service URL and tokens-not-before setting) |
JSONWebKeySet |
getRealmJSONWebKeySet(URL jwkURL)
Loads the actual JWK from the Keycloak server
|
URL |
getTokenEndpointURL(URL realmBaseURL)
Constructs the Keycloak
token endpoint URL from the
realm's base URL. |
TokenIntrospectionResponse |
introspectAccessToken(String context,
String clientId,
String clientSecret,
String accessTokenJWTString)
Introspects an access token against the Keycloak server.
|
TokenIntrospectionResponse |
introspectAccessToken(URL introspectionURL,
String clientId,
String clientSecret,
String accessTokenJWTString)
Introspects an access token against the Keycloak server.
|
boolean |
isAccessTokenVerified(String context,
String clientId,
String clientSecret,
String accessTokenJWTString)
Verifies an access token against the Keycloak server.
|
boolean |
isAccessTokenVerified(URL introspectionURL,
String clientId,
String clientSecret,
String accessTokenJWTString)
Verifies an access token against the Keycloak server.
|
TokenResponse |
queryOIDCToken(String context,
String authorization)
Queries an OIDC token from the Keycloak server, by using provided
authorization.
|
TokenResponse |
queryOIDCToken(String context,
String authorization,
Map<String,String> extraHeaders)
Queries an OIDC token from the Keycloak server, by using provided
authorization.
|
TokenResponse |
queryOIDCToken(String context,
String clientId,
String clientSecret)
Queries an OIDC token from the context's Keycloak server, by using provided
clientId and client secret.
|
TokenResponse |
queryOIDCToken(String context,
String clientId,
String clientSecret,
Map<String,String> extraHeaders)
Queries an OIDC token from the context's Keycloak server, by using provided
clientId and client secret.
|
TokenResponse |
queryOIDCToken(URL tokenURL,
String authorization)
Queries an OIDC token from the Keycloak server, by using provided
authorization.
|
TokenResponse |
queryOIDCToken(URL tokenURL,
String authorization,
Map<String,String> extraHeaders)
Queries an OIDC token from the Keycloak server, by using provided
authorization.
|
TokenResponse |
queryOIDCToken(URL tokenURL,
String clientId,
String clientSecret)
Queries an OIDC token from the Keycloak server, by using provided clientId
and client secret.
|
TokenResponse |
queryOIDCToken(URL tokenURL,
String clientId,
String clientSecret,
Map<String,String> extraHeaders)
Queries an OIDC token from the Keycloak server, by using provided clientId
and client secret.
|
TokenResponse |
queryOIDCTokenOfUser(String context,
String clientId,
String clientSecret,
String username,
String password)
Queries an OIDC token for a specific user from the context's Keycloak server,
by using provided clientId and client secret and user's username and
password.
|
TokenResponse |
queryOIDCTokenOfUser(String context,
String clientId,
String clientSecret,
String username,
String password,
Map<String,String> extraHeaders)
Queries an OIDC token for a specific user from the context's Keycloak server,
by using provided clientId and client secret and user's username and
password.
|
TokenResponse |
queryOIDCTokenOfUserWithContext(String context,
String authorization,
String username,
String password,
String audience)
Queries an OIDC token for a specific user from the context's Keycloak server,
by using provided clientId and client secret and user's username and
password.
|
TokenResponse |
queryOIDCTokenOfUserWithContext(String context,
String authorization,
String username,
String password,
String audience,
Map<String,String> extraHeaders)
Queries an OIDC token for a specific user from the context's Keycloak server,
by using provided clientId and client secret and user's username and
password.
|
TokenResponse |
queryOIDCTokenOfUserWithContext(String context,
String clientId,
String clientSecret,
String username,
String password,
String audience)
Queries an OIDC token for a specific user from the Keycloak server, by using
provided clientId and client secret and user's username and password,
reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenOfUserWithContext(String context,
String clientId,
String clientSecret,
String username,
String password,
String audience,
Map<String,String> extraHeaders)
Queries an OIDC token for a specific user from the Keycloak server, by using
provided clientId and client secret and user's username and password,
reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenOfUserWithContext(URL tokenURL,
String authorization,
String username,
String password,
String audience)
Queries an OIDC token for a specific user from the context's Keycloak server,
by using provided clientId and client secret and user's username and
password.
|
TokenResponse |
queryOIDCTokenOfUserWithContext(URL tokenURL,
String authorization,
String username,
String password,
String audience,
Map<String,String> extraHeaders)
Queries an OIDC token for a specific user from the context's Keycloak server,
by using provided clientId and client secret and user's username and
password.
|
TokenResponse |
queryOIDCTokenOfUserWithContext(URL tokenURL,
String clientId,
String clientSecret,
String username,
String password,
String audience)
Queries an OIDC token for a specific user from the context's Keycloak server,
by using provided clientId and client secret and user's username and
password, reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenOfUserWithContext(URL tokenURL,
String clientId,
String clientSecret,
String username,
String password,
String audience,
Map<String,String> extraHeaders)
Queries an OIDC token for a specific user from the context's Keycloak server,
by using provided clientId and client secret and user's username and
password, , reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenWithContext(String context,
String authorization,
String audience)
Queries an OIDC token from the Keycloak server, by using provided
authorization, reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenWithContext(String context,
String authorization,
String audience,
Map<String,String> extraHeaders)
Queries an OIDC token from the Keycloak server, by using provided
authorization, reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenWithContext(String context,
String clientId,
String clientSecret,
String audience)
Queries an OIDC token from the context's Keycloak server, by using provided
clientId and client secret, reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenWithContext(String context,
String clientId,
String clientSecret,
String audience,
Map<String,String> extraHeaders)
Queries an OIDC token from the context's Keycloak server, by using provided
clientId and client secret, reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenWithContext(URL tokenURL,
String authorization,
String audience)
Queries an OIDC token from the Keycloak server, by using provided
authorization, reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenWithContext(URL tokenURL,
String authorization,
String audience,
Map<String,String> extraHeaders)
Queries an OIDC token from the Keycloak server, by using provided
authorization, reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenWithContext(URL tokenURL,
String clientId,
String clientSecret,
String audience)
Queries an OIDC token from the Keycloak server, by using provided clientId
and client secret, reducing the audience to the requested one.
|
TokenResponse |
queryOIDCTokenWithContext(URL tokenURL,
String clientId,
String clientSecret,
String audience,
Map<String,String> extraHeaders)
Queries an OIDC token from the Keycloak server, by using provided clientId
and client secret, reducing the audience to the requested one.
|
TokenResponse |
queryUMAToken(String context,
String authorization,
String audience,
List<String> permissions)
Queries an UMA token from the Keycloak server, by using provided
authorization, for the given audience (context),
in URLEncoded form or not, and optionally a list of permissions.
|
TokenResponse |
queryUMAToken(String context,
String clientId,
String clientSecret,
String audience,
List<String> permissions)
Queries an UMA token from the Keycloak server, by using provided clientId and
client secret for the given audience
(context), in URLEncoded form or not, and optionally a list of permissions.
|
TokenResponse |
queryUMAToken(String context,
TokenResponse oidcTokenResponse,
String audience,
List<String> permissions)
Queries an UMA token from the Keycloak server, by using access-token provided
by the
TokenResponse object
for the given audience (context), in URLEncoded form or not, and optionally a
list of permissions. |
TokenResponse |
queryUMAToken(URL tokenURL,
String authorization,
String audience,
List<String> permissions)
Queries an UMA token from the Keycloak server, by using provided
authorization, for the given audience (context),
in URLEncoded form or not, and optionally a list of permissions.
|
TokenResponse |
queryUMAToken(URL tokenURL,
String clientId,
String clientSecret,
String audience,
List<String> permissions)
Queries an UMA token from the Keycloak server, by using provided clientId and
client secret for the given audience
(context), in URLEncoded form or not, and optionally a list of permissions.
|
TokenResponse |
queryUMAToken(URL tokenURL,
TokenResponse oidcTokenResponse,
String audience,
List<String> permissions)
Queries an UMA token from the Keycloak server, by using access-token provided
by the
TokenResponse object
for the given audience (context), in URLEncoded form or not, and optionally a
list of permissions. |
TokenResponse |
refreshToken(String context,
String clientId,
String clientSecret,
String refreshTokenJWTString)
Refreshes a previously issued token from the Keycloak server by using the
client id and secret
and the refresh token JWT encoded string obtained with the access token in
the previous token response.
|
TokenResponse |
refreshToken(String context,
String clientId,
String clientSecret,
TokenResponse tokenResponse)
Refreshes a previously issued token from the Keycloak server using the
refresh token JWT encoded string in the
token response object and the provided client id and secret.
|
TokenResponse |
refreshToken(String context,
TokenResponse tokenResponse)
Refreshes a previously issued token from the Keycloak server using the
refresh token JWT encoded string in the
token response object.
|
TokenResponse |
refreshToken(URL tokenURL,
String clientId,
String clientSecret,
String refreshTokenJWTString)
Refreshes a previously issued token from the Keycloak server by using the
client id and secret
and the refresh token JWT encoded string obtained with the access token in
the previous token response.
|
TokenResponse |
refreshToken(URL tokenURL,
String clientId,
String clientSecret,
TokenResponse tokenResponse)
Refreshes a previously issued token from the Keycloak server using the
refresh token JWT encoded string in the
token response object and the provided client id and secret.
|
TokenResponse |
refreshToken(URL tokenURL,
TokenResponse tokenResponse)
Refreshes a previously issued token from the Keycloak server using the
refresh token JWT encoded string in the
token response object.
|
KeycloakClient |
removeAllScopes()
Removes all the custom OIDC scopes from the list of scopes to use the next
OIDC token requests
|
KeycloakClient |
removeScopes(List<String> scopes)
Removes the provided OIDC scopes from the list of scopes to use for the next
OIDC token requests
|
KeycloakClient |
useDynamicScopeInsteadOfCustomHeaderForContextRestricion(boolean useDynamicScopeInsteadOfCustomHeaderForContextRestricion)
Sets a flag to use dynamic scope (
D4S_DYNAMIC_SCOPE_NAME =
"d4s-context") instead of custom header
(D4S_CONTEXT_HEADER_NAME = "x-d4science-context")
when an OIDC token with context is used |
KeycloakClient |
useScopes(List<String> scopes)
Replaces the list of the provided OIDC scopes for the next OIDC token
requests
|
static final String PROD_ROOT_SCOPE
static final String OPEN_ID_URI_PATH
static final String TOKEN_URI_PATH
static final String JWK_URI_PATH
static final String TOKEN_INTROSPECT_URI_PATH
static final String AVATAR_URI_PATH
static final String D4S_CONTEXT_HEADER_NAME
static final String D4S_IDENTITY_SCOPE
static final String D4S_EU_EXTENDED_PROFILE_SCOPE
static final String D4S_DYNAMIC_SCOPE_NAME
static final String D4S_DYNAMIC_SCOPE_NAME_TOKEN_CLAIM
static final String DEFAULT_DYNAMIC_SCOPE_SEPARATOR
static final String DEFAULT_REALM
KeycloakClient useScopes(List<String> scopes)
scopes - the list of scopes to use in the callsKeycloakClient addScopes(List<String> scopes)
scopes - the list of scopes to addKeycloakClient addDynamicScope(String dynamicScope, String value)
dynamicScope - the dynamic scope that will be the prefixvalue - the value of the dynamic scopeKeycloakClient removeScopes(List<String> scopes)
scopes - the list of scopes to removeKeycloakClient removeAllScopes()
KeycloakClient useDynamicScopeInsteadOfCustomHeaderForContextRestricion(boolean useDynamicScopeInsteadOfCustomHeaderForContextRestricion)
D4S_DYNAMIC_SCOPE_NAME =
"d4s-context") instead of custom header
(D4S_CONTEXT_HEADER_NAME = "x-d4science-context")
when an OIDC token with context is useduseDynamicScopeInsteadOfCustomHeaderForContextRestricion - use or not use dynamic scopeURL getRealmBaseURL(String context) throws KeycloakClientException
URL for the given context and the default
realm (d4science)context - the context where the endpoint is needed (e.g.
/gcube for DEV)token endpoint URLKeycloakClientException - if something goes wrong discovering the
endpoint URLURL getRealmBaseURL(String context, String realm) throws KeycloakClientException
URL for the given context and in the given
realm.context - the context where the endpoint is needed (e.g.
/gcube for DEV)realm - the realm to use to construct the base URLtoken endpoint URLKeycloakClientException - if something goes wrong discovering the
endpoint URLURL getTokenEndpointURL(URL realmBaseURL) throws KeycloakClientException
token endpoint URL from the
realm's base URL.realmBaseURL - the realm's base URL to usetoken endpoint URLKeycloakClientException - if something goes wrong discovering the
endpoint URLURL getJWKEndpointURL(URL realmBaseURL) throws KeycloakClientException
JWK endpoint URL from the
realm's base URL.realmBaseURL - the realm's base URL to useJWK endpoint URLKeycloakClientException - if something goes wrong discovering the
endpoint URLURL getIntrospectionEndpointURL(URL realmBaseURL) throws KeycloakClientException
introspection endpoint URL from
the realm's base URL.realmBaseURL - the realm's base URL to useintrospection endpoint URLKeycloakClientException - if something goes wrong discovering the
endpoint URLURL computeIntrospectionEndpointURL(URL tokenEndpointURL) throws KeycloakClientException
introspection endpoint URL starting
from the provided token endpoint.tokenEndpointURL - the token endpoint to use in the computeintrospection endpoint URLKeycloakClientException - if something goes wrong discovering the
endpoint URLURL getAvatarEndpointURL(URL realmBaseURL) throws KeycloakClientException
avatar endpoint URL from the
realm's base URL.realmBaseURL - the realm's base URL to useavatar endpoint URLKeycloakClientException - if something goes wrong discovering the
endpoint URLPublishedRealmRepresentation getRealmInfo(URL realmURL) throws KeycloakClientException
public_key,
token-service URL,
account-service URL and tokens-not-before setting)realmURL - the realm URLKeycloakClientException - if something goes wrong getting realm infoJSONWebKeySet getRealmJSONWebKeySet(URL jwkURL) throws KeycloakClientException
jwkURL - the server's jwk URL to useKeycloakClientException - if something goes wrong getting JWK infoTokenResponse queryOIDCToken(String context, String clientId, String clientSecret) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the client idclientSecret - the client secretTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCToken(String context, String clientId, String clientSecret, Map<String,String> extraHeaders) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the client idclientSecret - the client secretextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCToken(URL tokenURL, String clientId, String clientSecret) throws KeycloakClientException
tokenURL - the token endpoint URL of the Keycloak serverclientId - the client idclientSecret - the client secretTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCToken(URL tokenURL, String clientId, String clientSecret, Map<String,String> extraHeaders) throws KeycloakClientException
tokenURL - the token endpoint URL of the Keycloak serverclientId - the client idclientSecret - the client secretextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCToken(String context, String authorization) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)authorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)TokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCToken(String context, String authorization, Map<String,String> extraHeaders) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)authorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)extraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCToken(URL tokenURL, String authorization) throws KeycloakClientException
tokenURL - the token endpoint URL of the OIDC serverauthorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)TokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCToken(URL tokenURL, String authorization, Map<String,String> extraHeaders) throws KeycloakClientException
tokenURL - the token endpoint URL of the OIDC serverauthorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)extraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenWithContext(String context, String clientId, String clientSecret, String audience) throws KeycloakClientException
x-d4science-context HTTP
header that the proper mapper on Keycloak uses to reduce the audiencecontext - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the client idclientSecret - the client secretaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenWithContext(String context, String clientId, String clientSecret, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
x-d4science-context HTTP
header that the proper mapper on Keycloak uses to reduce the audiencecontext - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the client idclientSecret - the client secretaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenWithContext(URL tokenURL, String clientId, String clientSecret, String audience) throws KeycloakClientException
x-d4science-context HTTP
header that the proper mapper on Keycloak uses to reduce the audiencetokenURL - the token endpoint URL of the Keycloak serverclientId - the client idclientSecret - the client secretaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenWithContext(URL tokenURL, String clientId, String clientSecret, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
x-d4science-context HTTP
header that the proper mapper on Keycloak uses to reduce the audiencetokenURL - the token endpoint URL of the Keycloak serverclientId - the client idclientSecret - the client secretaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenWithContext(String context, String authorization, String audience) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)authorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)audience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenWithContext(String context, String authorization, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)authorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)audience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenWithContext(URL tokenURL, String authorization, String audience) throws KeycloakClientException
tokenURL - the token endpoint URL of the OIDC serverauthorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)audience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenWithContext(URL tokenURL, String authorization, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
tokenURL - the token endpoint URL of the OIDC serverauthorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)audience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUser(String context, String clientId, String clientSecret, String username, String password) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the client idclientSecret - the client secretusername - the user's usernamepassword - the user's passwordTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUser(String context, String clientId, String clientSecret, String username, String password, Map<String,String> extraHeaders) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the client idclientSecret - the client secretusername - the user's usernamepassword - the user's passwordextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUserWithContext(String context, String authorization, String username, String password, String audience) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)authorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)username - the user's usernamepassword - the user's passwordaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUserWithContext(String context, String clientId, String clientSecret, String username, String password, String audience) throws KeycloakClientException
x-d4science-context HTTP
header that the proper mapper on Keycloak uses to reduce the audiencecontext - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the client idclientSecret - the client secretusername - the user's usernamepassword - the user's passwordaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUserWithContext(String context, String clientId, String clientSecret, String username, String password, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
x-d4science-context HTTP
header that the proper mapper on Keycloak uses to reduce the audiencecontext - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the client idclientSecret - the client secretusername - the user's usernamepassword - the user's passwordaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUserWithContext(URL tokenURL, String clientId, String clientSecret, String username, String password, String audience) throws KeycloakClientException
x-d4science-context HTTP
header that the proper mapper on Keycloak uses to reduce the audiencetokenURL - the token endpoint URL of the Keycloak serverclientId - the client idclientSecret - the client secretusername - the user's usernamepassword - the user's passwordaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUserWithContext(URL tokenURL, String clientId, String clientSecret, String username, String password, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
tokenURL - the token endpoint URL of the Keycloak serverclientId - the client idclientSecret - the client secretusername - the user's usernamepassword - the user's passwordaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUserWithContext(String context, String authorization, String username, String password, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)authorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)username - the user's usernamepassword - the user's passwordaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUserWithContext(URL tokenURL, String authorization, String username, String password, String audience) throws KeycloakClientException
tokenURL - the token endpoint URL of the OIDC serverauthorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)username - the user's usernamepassword - the user's passwordaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryOIDCTokenOfUserWithContext(URL tokenURL, String authorization, String username, String password, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
tokenURL - the token endpoint URL of the OIDC serverauthorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)username - the user's usernamepassword - the user's passwordaudience - an optional parameter to shrink the token's audience to
the requested one (e.g. a specific context), by
leveraging on the custom HTTP header and corresponding
mapper on KeycloakextraHeaders - extra HTTP headers to add to the requestTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryUMAToken(String context, String authorization, String audience, List<String> permissions) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)authorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)audience - the audience (context) where to request the issuing of
the ticket (URLEncoded)permissions - a list of permissions, can be nullTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryUMAToken(URL tokenURL, String authorization, String audience, List<String> permissions) throws KeycloakClientException
tokenURL - the token endpoint URL of the OIDC serverauthorization - the authorization to be set as header (e.g. a "Basic
...." auth or an encoded JWT access token preceded by
the "Bearer " string)audience - the audience (context) where to request the issuing of
the ticket (URLEncoded)permissions - a list of permissions, can be nullTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryUMAToken(String context, TokenResponse oidcTokenResponse, String audience, List<String> permissions) throws KeycloakClientException
TokenResponse object
for the given audience (context), in URLEncoded form or not, and optionally a
list of permissions.context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)oidcTokenResponse - the previously issued token as TokenResponse
objectaudience - the audience (context) where to request the issuing
of the ticketpermissions - a list of permissions, can be nullTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryUMAToken(URL tokenURL, TokenResponse oidcTokenResponse, String audience, List<String> permissions) throws KeycloakClientException
TokenResponse object
for the given audience (context), in URLEncoded form or not, and optionally a
list of permissions.tokenURL - the token endpoint URL of the OIDC serveroidcTokenResponse - the previously issued token as TokenResponse
objectaudience - the audience (context) where to request the issuing
of the ticketpermissions - a list of permissions, can be nullTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryUMAToken(String context, String clientId, String clientSecret, String audience, List<String> permissions) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the client idclientSecret - the client secretaudience - the audience (context) where to request the issuing of
the ticketpermissions - a list of permissions, can be nullTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse queryUMAToken(URL tokenURL, String clientId, String clientSecret, String audience, List<String> permissions) throws KeycloakClientException
tokenURL - the token endpoint URL of the Keycloak serverclientId - the client idclientSecret - the client secretaudience - the audience (context) where to request the issuing of
the ticketpermissions - a list of permissions, can be nullTokenResponse objectKeycloakClientException - if something goes wrong performing the queryTokenResponse refreshToken(String context, TokenResponse tokenResponse) throws KeycloakClientException
public clients types only.context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)tokenResponse - the previously issued token as TokenResponse
objectTokenResponse objectKeycloakClientException - if something goes wrong performing the
refresh queryTokenResponse refreshToken(URL tokenURL, TokenResponse tokenResponse) throws KeycloakClientException
public clients types only.tokenURL - the token endpoint URL of the OIDC servertokenResponse - the previously issued token as TokenResponse
objectTokenResponse objectKeycloakClientException - if something goes wrong performing the
refresh queryTokenResponse refreshToken(String context, String clientId, String clientSecret, TokenResponse tokenResponse) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the requestor client id, may be null and in
this case will be take from the access token "issued
for" claimclientSecret - the requestor client secret, may be null
for non-confidential clientstokenResponse - the previously issued token as TokenResponse
objectTokenResponse objectKeycloakClientException - if something goes wrong performing the
refresh queryTokenResponse refreshToken(URL tokenURL, String clientId, String clientSecret, TokenResponse tokenResponse) throws KeycloakClientException
tokenURL - the token endpoint URL of the OIDC serverclientId - the requestor client id, may be null and in
this case will be take from the access token "issued
for" claimclientSecret - the requestor client secret, may be null
for non-confidential clientstokenResponse - the previously issued token as TokenResponse
objectTokenResponse objectKeycloakClientException - if something goes wrong performing the
refresh queryTokenResponse refreshToken(String context, String clientId, String clientSecret, String refreshTokenJWTString) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the requestor client idclientSecret - the requestor client secret, may be
null for non-confidential clientsrefreshTokenJWTString - the previously issued refresh token JWT stringTokenResponse objectKeycloakClientException - if something goes wrong performing the
refresh queryTokenResponse refreshToken(URL tokenURL, String clientId, String clientSecret, String refreshTokenJWTString) throws KeycloakClientException
tokenURL - the token endpoint URL of the OIDC
serverclientId - the requestor client idclientSecret - the requestor client secret, may be
null for non-confidential clientsrefreshTokenJWTString - the previously issued refresh token JWT stringTokenResponse objectKeycloakClientException - if something goes wrong performing the
refresh queryTokenResponse exchangeTokenForAccessToken(String context, String oidcAccessToken, String clientId, String clientSecret, String audience) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)oidcAccessToken - the original access token to exchangeclientId - the authorized client's idclientSecret - the authorized client's secretaudience - the requested token audienceKeycloakClientException - if an error occurs during the exchangeTokenResponse exchangeTokenForAccessToken(URL tokenURL, String oidcAccessToken, String clientId, String clientSecret, String audience) throws KeycloakClientException
tokenURL - the token endpoint URLoidcAccessToken - the original access token to exchangeclientId - the authorized client's idclientSecret - the authorized client's secretaudience - the requested token audienceKeycloakClientException - if an error occurs during the exchangeTokenResponse exchangeTokenForRefreshToken(String context, String oidcAccessToken, String clientId, String clientSecret, String audience) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)oidcAccessToken - the original access token to exchangeclientId - the authorized client's idclientSecret - the authorized client's secretaudience - the requested token audienceKeycloakClientException - if an error occurs during the exchangeTokenResponse exchangeTokenForRefreshToken(URL tokenURL, String oidcAccessToken, String clientId, String clientSecret, String audience) throws KeycloakClientException
tokenURL - the token endpoint URLoidcAccessToken - the original access token to exchangeclientId - the authorized client's idclientSecret - the authorized client's secretaudience - the requested token audienceKeycloakClientException - if an error occurs during the exchangeTokenResponse exchangeTokenForOfflineToken(String context, String oidcAccessToken, String clientId, String clientSecret, String audience) throws IllegalArgumentException, KeycloakClientException
offline_access within its scopescontext - the token endpoint URLoidcAccessToken - the original access token to exchangeclientId - the authorized client's idclientSecret - the authorized client's secretaudience - the requested token audienceIllegalArgumentException - if the original token does'nt contains the
offline_access scope within its
scopes or if is impossible to parse the
access token as JSONKeycloakClientException - if an error occurs during the exchangeTokenResponse exchangeTokenForOfflineToken(URL tokenURL, String oidcAccessToken, String clientId, String clientSecret, String audience) throws IllegalArgumentException, KeycloakClientException
offline_access within its scopestokenURL - the token endpoint URLoidcAccessToken - the original access token to exchangeclientId - the authorized client's idclientSecret - the authorized client's secretaudience - the requested token audienceIllegalArgumentException - if the original token does'nt contains the
offline_access scope within its
scopes or if is impossible to parse the
access token as JSONKeycloakClientException - if an error occurs during the exchangeTokenIntrospectionResponse introspectAccessToken(String context, String clientId, String clientSecret, String accessTokenJWTString) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the requestor client idclientSecret - the requestor client secretaccessTokenJWTString - the access token to verifyTokenIntrospectionResponse object with the introspection
results; in particular, the active field represents the
token validityKeycloakClientException - if something goes wrong performing the
verificationTokenIntrospectionResponse introspectAccessToken(URL introspectionURL, String clientId, String clientSecret, String accessTokenJWTString) throws KeycloakClientException
introspectionURL - the introspection endpoint URL of the
Keycloak serverclientId - the requestor client idclientSecret - the requestor client secretaccessTokenJWTString - the access token to verifyTokenIntrospectionResponse object with the introspection
results; in particular, the active field represents the
token validityKeycloakClientException - if something goes wrong performing the
verificationboolean isAccessTokenVerified(String context, String clientId, String clientSecret, String accessTokenJWTString) throws KeycloakClientException
context - the context where the Keycloak's is needed (e.g.
/gcube for DEV)clientId - the requestor client idclientSecret - the requestor client secretaccessTokenJWTString - the access token to verifytrue if the token is active, false
otherwiseKeycloakClientException - if something goes wrong performing the
verificationboolean isAccessTokenVerified(URL introspectionURL, String clientId, String clientSecret, String accessTokenJWTString) throws KeycloakClientException
introspectionURL - the introspection endpoint URL of the
Keycloak serverclientId - the requestor client idclientSecret - the requestor client secretaccessTokenJWTString - the access token to verifytrue if the token is active, false
otherwiseKeycloakClientException - if something goes wrong performing the
verificationbyte[] getAvatarData(String context, TokenResponse tokenResponse) throws KeycloakClientException
context - the context used to compute the server endpoint in the
correct environmenttokenResponse - the token response where to get the bearer token for the
authorization header.KeycloakClientException - if something goes wrong in the requestbyte[] getAvatarData(URL avatarURL, TokenResponse tokenResponse) throws KeycloakClientException
avatarURL - the server's avatar endpoint URLtokenResponse - the token response where to get the bearer token for the
authorization header.KeycloakClientException - if something goes wrong in the requestbyte[] getAvatarData(URL avatarURL, String authorization) throws KeycloakClientException
avatarURL - the server's avatar endpoint URLauthorization - the string to user as authorization header (e.g. 'bearer xxxx')KeycloakClientException - if something goes wrong in the requestCopyright © 2026. All rights reserved.