Package org.gcube.common.keycloak
Class DefaultKeycloakClient
- java.lang.Object
-
- org.gcube.common.keycloak.DefaultKeycloakClient
-
- All Implemented Interfaces:
KeycloakClient
public class DefaultKeycloakClient extends Object implements KeycloakClient
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringAUTHORIZATION_HEADERstatic StringDEFAULT_BASE_URLprotected static org.slf4j.Loggerlogger-
Fields inherited from interface org.gcube.common.keycloak.KeycloakClient
AVATAR_URI_PATH, D4S_CONTEXT_HEADER_NAME, D4S_DYNAMIC_SCOPE_NAME, D4S_DYNAMIC_SCOPE_NAME_TOKEN_CLAIM, D4S_EU_EXTENDED_PROFILE_SCOPE, D4S_IDENTITY_SCOPE, DEFAULT_DYNAMIC_SCOPE_SEPARATOR, DEFAULT_REALM, JWK_URI_PATH, OPEN_ID_URI_PATH, PROD_ROOT_SCOPE, TOKEN_INTROSPECT_URI_PATH, TOKEN_URI_PATH
-
-
Constructor Summary
Constructors Constructor Description DefaultKeycloakClient()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description KeycloakClientaddDynamicScope(String dynamicScope, String value)Adds the dynamic scope to the list of scopes to use for the next OIDC token requestsKeycloakClientaddScopes(List<String> scopes)Adds the provided OIDC scopes to the list of scopes to use for the next OIDC token requestsURLcomputeIntrospectionEndpointURL(URL tokenEndpointURL)Compute the keycloakintrospectionendpointURLstarting from the provided token endpoint.protected static StringconstructBasicAuthenticationHeader(String clientId, String clientSecret)protected static StringconstructBeareAuthenticationHeader(TokenResponse oidcTokenResponse)protected static StringconstructDynamicScope(String dynamicScope, String value)protected TokenResponseexchangeToken(URL tokenURL, String oidcAccessToken, String clientId, String clientSecret, String audience, String requestedTokenType, String scope)Queries from the OIDC server an exchanged token by using provided access token, for the given audience (context), in URLEncoded form or not,TokenResponseexchangeTokenForAccessToken(String context, String oidcAccessToken, String clientId, String clientSecret, String audience)Exchanges a token for another access token for a specific client and a specific audienceTokenResponseexchangeTokenForAccessToken(URL tokenURL, String oidcAccessToken, String clientId, String clientSecret, String audience)Exchanges a token for another access token for a specific client and a specific audienceTokenResponseexchangeTokenForOfflineToken(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 theoffline_accesswithin its scopesTokenResponseexchangeTokenForOfflineToken(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 scopeoffline_accesswithin its scopesTokenResponseexchangeTokenForRefreshToken(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 audienceTokenResponseexchangeTokenForRefreshToken(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 audiencebyte[]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.URLgetAvatarEndpointURL(URL realmBaseURL)Constructs the KeycloakavatarendpointURLfrom the realm's base URL.StringgetCustomBaseURL()URLgetIntrospectionEndpointURL(URL realmBaseURL)Constructs the KeycloakintrospectionendpointURLfrom the realm's base URL.URLgetJWKEndpointURL(URL realmBaseURL)Constructs the KeycloakJWKendpointURLfrom the realm's base URL.URLgetRealmBaseURL(String context)Returns the Keycloak baseURLfor the given context and the default realm (d4science)URLgetRealmBaseURL(String context, String realm)Returns the Keycloak baseURLfor the given context and in the given realm.PublishedRealmRepresentationgetRealmInfo(URL realmURL)Gets the realm info setup (RSApublic_key,token-serviceURL,account-serviceURL andtokens-not-beforesetting)JSONWebKeySetgetRealmJSONWebKeySet(URL jwkURL)Loads the actual JWK from the Keycloak serverURLgetTokenEndpointURL(URL realmBaseURL)Constructs the KeycloaktokenendpointURLfrom the realm's base URL.TokenIntrospectionResponseintrospectAccessToken(String context, String clientId, String clientSecret, String accessTokenJWTString)Introspects an access token against the Keycloak server.TokenIntrospectionResponseintrospectAccessToken(URL introspectionURL, String clientId, String clientSecret, String accessTokenJWTString)Introspects an access token against the Keycloak server.booleanisAccessTokenVerified(String context, String clientId, String clientSecret, String accessTokenJWTString)Verifies an access token against the Keycloak server.booleanisAccessTokenVerified(URL introspectionURL, String clientId, String clientSecret, String accessTokenJWTString)Verifies an access token against the Keycloak server.protected <T> TperformRequest(Class<T> returnObjectClass, URL url, Map<String,String> headers, Map<String,List<String>> params)protected TokenResponseperformRequest(URL tokenURL, Map<String,String> headers, Map<String,List<String>> params)TokenResponsequeryOIDCToken(String context, String authorization)Queries an OIDC token from the Keycloak server, by using provided authorization.TokenResponsequeryOIDCToken(String context, String clientId, String clientSecret)Queries an OIDC token from the context's Keycloak server, by using provided clientId and client secret.TokenResponsequeryOIDCToken(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.TokenResponsequeryOIDCToken(String context, String authorization, Map<String,String> extraHeaders)Queries an OIDC token from the Keycloak server, by using provided authorization.TokenResponsequeryOIDCToken(URL tokenURL, String authorization)Queries an OIDC token from the Keycloak server, by using provided authorization.TokenResponsequeryOIDCToken(URL tokenURL, String clientId, String clientSecret)Queries an OIDC token from the Keycloak server, by using provided clientId and client secret.TokenResponsequeryOIDCToken(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.TokenResponsequeryOIDCToken(URL tokenURL, String authorization, Map<String,String> extraHeaders)Queries an OIDC token from the Keycloak server, by using provided authorization.TokenResponsequeryOIDCTokenOfUser(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.TokenResponsequeryOIDCTokenOfUser(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.TokenResponsequeryOIDCTokenOfUserWithContext(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.TokenResponsequeryOIDCTokenOfUserWithContext(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.TokenResponsequeryOIDCTokenOfUserWithContext(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.TokenResponsequeryOIDCTokenOfUserWithContext(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.TokenResponsequeryOIDCTokenOfUserWithContext(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.TokenResponsequeryOIDCTokenOfUserWithContext(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.TokenResponsequeryOIDCTokenOfUserWithContext(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.TokenResponsequeryOIDCTokenOfUserWithContext(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.TokenResponsequeryOIDCTokenWithContext(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.TokenResponsequeryOIDCTokenWithContext(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.TokenResponsequeryOIDCTokenWithContext(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.TokenResponsequeryOIDCTokenWithContext(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.TokenResponsequeryOIDCTokenWithContext(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.TokenResponsequeryOIDCTokenWithContext(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.TokenResponsequeryOIDCTokenWithContext(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.TokenResponsequeryOIDCTokenWithContext(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.TokenResponsequeryUMAToken(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.TokenResponsequeryUMAToken(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.TokenResponsequeryUMAToken(String context, TokenResponse oidcTokenResponse, String audience, List<String> permissions)Queries an UMA token from the Keycloak server, by using access-token provided by theTokenResponseobject for the given audience (context), in URLEncoded form or not, and optionally a list of permissions.TokenResponsequeryUMAToken(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.TokenResponsequeryUMAToken(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.TokenResponsequeryUMAToken(URL tokenURL, TokenResponse oidcTokenResponse, String audience, List<String> permissions)Queries an UMA token from the Keycloak server, by using access-token provided by theTokenResponseobject for the given audience (context), in URLEncoded form or not, and optionally a list of permissions.TokenResponserefreshToken(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.TokenResponserefreshToken(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.TokenResponserefreshToken(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.TokenResponserefreshToken(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.TokenResponserefreshToken(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.TokenResponserefreshToken(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.KeycloakClientremoveAllScopes()Removes all the custom OIDC scopes from the list of scopes to use the next OIDC token requestsKeycloakClientremoveScopes(List<String> scopes)Removes the provided OIDC scopes from the list of scopes to use for the next OIDC token requestsprotected voidsafeSetAsExternalCallForOldAPI(org.gcube.common.gxhttp.request.GXHTTPStringRequest request)voidsetCustomBaseURL(String customBaseURL)KeycloakClientuseDynamicScopeInsteadOfCustomHeaderForContextRestricion(boolean useDynamicScopeInsteadOfCustomHeaderForContextRestricion)Sets a flag to use dynamic scope (KeycloakClient.D4S_DYNAMIC_SCOPE_NAME= "d4s-context") instead of custom header (KeycloakClient.D4S_CONTEXT_HEADER_NAME= "x-d4science-context") when an OIDC token with context is usedKeycloakClientuseScopes(List<String> scopes)Replaces the list of the provided OIDC scopes for the next OIDC token requests
-
-
-
Field Detail
-
logger
protected static org.slf4j.Logger logger
-
AUTHORIZATION_HEADER
protected static final String AUTHORIZATION_HEADER
- See Also:
- Constant Field Values
-
DEFAULT_BASE_URL
public static final String DEFAULT_BASE_URL
- See Also:
- Constant Field Values
-
-
Method Detail
-
setCustomBaseURL
public void setCustomBaseURL(String customBaseURL)
-
useScopes
public KeycloakClient useScopes(List<String> scopes)
Description copied from interface:KeycloakClientReplaces the list of the provided OIDC scopes for the next OIDC token requests- Specified by:
useScopesin interfaceKeycloakClient- Parameters:
scopes- the list of scopes to use in the calls- Returns:
- the client itself
-
addScopes
public KeycloakClient addScopes(List<String> scopes)
Description copied from interface:KeycloakClientAdds the provided OIDC scopes to the list of scopes to use for the next OIDC token requests- Specified by:
addScopesin interfaceKeycloakClient- Parameters:
scopes- the list of scopes to add- Returns:
- the client itself
-
removeScopes
public KeycloakClient removeScopes(List<String> scopes)
Description copied from interface:KeycloakClientRemoves the provided OIDC scopes from the list of scopes to use for the next OIDC token requests- Specified by:
removeScopesin interfaceKeycloakClient- Parameters:
scopes- the list of scopes to remove- Returns:
- the client itself
-
addDynamicScope
public KeycloakClient addDynamicScope(String dynamicScope, String value)
Description copied from interface:KeycloakClientAdds the dynamic scope to the list of scopes to use for the next OIDC token requests- Specified by:
addDynamicScopein interfaceKeycloakClient- Parameters:
dynamicScope- the dynamic scope that will be the prefixvalue- the value of the dynamic scope- Returns:
- the client itself
-
constructDynamicScope
protected static String constructDynamicScope(String dynamicScope, String value)
-
removeAllScopes
public KeycloakClient removeAllScopes()
Description copied from interface:KeycloakClientRemoves all the custom OIDC scopes from the list of scopes to use the next OIDC token requests- Specified by:
removeAllScopesin interfaceKeycloakClient- Returns:
- the client itself
-
useDynamicScopeInsteadOfCustomHeaderForContextRestricion
public KeycloakClient useDynamicScopeInsteadOfCustomHeaderForContextRestricion(boolean useDynamicScopeInsteadOfCustomHeaderForContextRestricion)
Description copied from interface:KeycloakClientSets a flag to use dynamic scope (KeycloakClient.D4S_DYNAMIC_SCOPE_NAME= "d4s-context") instead of custom header (KeycloakClient.D4S_CONTEXT_HEADER_NAME= "x-d4science-context") when an OIDC token with context is used- Specified by:
useDynamicScopeInsteadOfCustomHeaderForContextRestricionin interfaceKeycloakClient- Parameters:
useDynamicScopeInsteadOfCustomHeaderForContextRestricion- use or not use dynamic scope- Returns:
- the client itself
-
getCustomBaseURL
public String getCustomBaseURL()
-
getRealmBaseURL
public URL getRealmBaseURL(String context) throws KeycloakClientException
Description copied from interface:KeycloakClientReturns the Keycloak baseURLfor the given context and the default realm (d4science)- Specified by:
getRealmBaseURLin interfaceKeycloakClient- Parameters:
context- the context where the endpoint is needed (e.g./gcubefor DEV)- Returns:
- the Keycloak
tokenendpoint URL - Throws:
KeycloakClientException- if something goes wrong discovering the endpoint URL
-
getRealmBaseURL
public URL getRealmBaseURL(String context, String realm) throws KeycloakClientException
Description copied from interface:KeycloakClientReturns the Keycloak baseURLfor the given context and in the given realm.- Specified by:
getRealmBaseURLin interfaceKeycloakClient- Parameters:
context- the context where the endpoint is needed (e.g./gcubefor DEV)realm- the realm to use to construct the base URL- Returns:
- the Keycloak
tokenendpoint URL - Throws:
KeycloakClientException- if something goes wrong discovering the endpoint URL
-
getTokenEndpointURL
public URL getTokenEndpointURL(URL realmBaseURL) throws KeycloakClientException
Description copied from interface:KeycloakClientConstructs the KeycloaktokenendpointURLfrom the realm's base URL.- Specified by:
getTokenEndpointURLin interfaceKeycloakClient- Parameters:
realmBaseURL- the realm's base URL to use- Returns:
- the Keycloak
tokenendpoint URL - Throws:
KeycloakClientException- if something goes wrong discovering the endpoint URL
-
getJWKEndpointURL
public URL getJWKEndpointURL(URL realmBaseURL) throws KeycloakClientException
Description copied from interface:KeycloakClientConstructs the KeycloakJWKendpointURLfrom the realm's base URL.- Specified by:
getJWKEndpointURLin interfaceKeycloakClient- Parameters:
realmBaseURL- the realm's base URL to use- Returns:
- the Keycloak
JWKendpoint URL - Throws:
KeycloakClientException- if something goes wrong discovering the endpoint URL
-
getIntrospectionEndpointURL
public URL getIntrospectionEndpointURL(URL realmBaseURL) throws KeycloakClientException
Description copied from interface:KeycloakClientConstructs the KeycloakintrospectionendpointURLfrom the realm's base URL.- Specified by:
getIntrospectionEndpointURLin interfaceKeycloakClient- Parameters:
realmBaseURL- the realm's base URL to use- Returns:
- the Keycloak
introspectionendpoint URL - Throws:
KeycloakClientException- if something goes wrong discovering the endpoint URL
-
getAvatarEndpointURL
public URL getAvatarEndpointURL(URL realmBaseURL) throws KeycloakClientException
Description copied from interface:KeycloakClientConstructs the KeycloakavatarendpointURLfrom the realm's base URL.- Specified by:
getAvatarEndpointURLin interfaceKeycloakClient- Parameters:
realmBaseURL- the realm's base URL to use- Returns:
- the Keycloak
avatarendpoint URL - Throws:
KeycloakClientException- if something goes wrong discovering the endpoint URL
-
computeIntrospectionEndpointURL
public URL computeIntrospectionEndpointURL(URL tokenEndpointURL) throws KeycloakClientException
Description copied from interface:KeycloakClientCompute the keycloakintrospectionendpointURLstarting from the provided token endpoint.- Specified by:
computeIntrospectionEndpointURLin interfaceKeycloakClient- Parameters:
tokenEndpointURL- the token endpoint to use in the compute- Returns:
- the keycloak
introspectionendpoint URL - Throws:
KeycloakClientException- if something goes wrong discovering the endpoint URL
-
getRealmInfo
public PublishedRealmRepresentation getRealmInfo(URL realmURL) throws KeycloakClientException
Description copied from interface:KeycloakClientGets the realm info setup (RSApublic_key,token-serviceURL,account-serviceURL andtokens-not-beforesetting)- Specified by:
getRealmInfoin interfaceKeycloakClient- Parameters:
realmURL- the realm URL- Returns:
- the configured realm info
- Throws:
KeycloakClientException- if something goes wrong getting realm info
-
getRealmJSONWebKeySet
public JSONWebKeySet getRealmJSONWebKeySet(URL jwkURL) throws KeycloakClientException
Description copied from interface:KeycloakClientLoads the actual JWK from the Keycloak server- Specified by:
getRealmJSONWebKeySetin interfaceKeycloakClient- Parameters:
jwkURL- the server's jwk URL to use- Returns:
- an object with JWK details
- Throws:
KeycloakClientException- if something goes wrong getting JWK info
-
queryOIDCToken
public TokenResponse queryOIDCToken(String context, String clientId, String clientSecret) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the context's Keycloak server, by using provided clientId and client secret.- Specified by:
queryOIDCTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)clientId- the client idclientSecret- the client secret- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCToken
public TokenResponse queryOIDCToken(String context, String clientId, String clientSecret, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the context's Keycloak server, by using provided clientId and client secret.- Specified by:
queryOIDCTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)clientId- the client idclientSecret- the client secretextraHeaders- extra HTTP headers to add to the request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCToken
public TokenResponse queryOIDCToken(URL tokenURL, String clientId, String clientSecret) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided clientId and client secret.- Specified by:
queryOIDCTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof the Keycloak serverclientId- the client idclientSecret- the client secret- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCToken
public TokenResponse queryOIDCToken(URL tokenURL, String clientId, String clientSecret, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided clientId and client secret. Optionally extra HTTP headers can be provided to be used in the call.- Specified by:
queryOIDCTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof the Keycloak serverclientId- the client idclientSecret- the client secretextraHeaders- extra HTTP headers to add to the request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCToken
public TokenResponse queryOIDCToken(String context, String authorization) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided authorization.- Specified by:
queryOIDCTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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)- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCToken
public TokenResponse queryOIDCToken(URL tokenURL, String authorization) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided authorization.- Specified by:
queryOIDCTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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)- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCToken
public TokenResponse queryOIDCToken(String context, String authorization, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided authorization. Optionally extra HTTP headers can be provided to be used in the call.- Specified by:
queryOIDCTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCToken
public TokenResponse queryOIDCToken(URL tokenURL, String authorization, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided authorization. Optionally extra HTTP headers can be provided to be used in the call.- Specified by:
queryOIDCTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenOfUser
public TokenResponse queryOIDCTokenOfUser(String context, String clientId, String clientSecret, String username, String password) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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.- Specified by:
queryOIDCTokenOfUserin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)clientId- the client idclientSecret- the client secretusername- the user's usernamepassword- the user's password- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenOfUser
public TokenResponse queryOIDCTokenOfUser(String context, String clientId, String clientSecret, String username, String password, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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. Optionally extra HTTP headers can be provided to be used in the call.- Specified by:
queryOIDCTokenOfUserin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)clientId- the client idclientSecret- the client secretusername- the user's usernamepassword- the user's passwordextraHeaders- extra HTTP headers to add to the request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenWithContext
public TokenResponse queryOIDCTokenWithContext(String context, String clientId, String clientSecret, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the context's Keycloak server, by using provided clientId and client secret, reducing the audience to the requested one. The implementation uses the customx-d4science-contextHTTP header that the proper mapper on Keycloak uses to reduce the audience- Specified by:
queryOIDCTokenWithContextin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 Keycloak- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenWithContext
public TokenResponse queryOIDCTokenWithContext(String context, String authorization, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided authorization, reducing the audience to the requested one.- Specified by:
queryOIDCTokenWithContextin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 Keycloak- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenWithContext
public TokenResponse queryOIDCTokenWithContext(URL tokenURL, String clientId, String clientSecret, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided clientId and client secret, reducing the audience to the requested one. The implementation uses the customx-d4science-contextHTTP header that the proper mapper on Keycloak uses to reduce the audience- Specified by:
queryOIDCTokenWithContextin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 Keycloak- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenWithContext
public TokenResponse queryOIDCTokenWithContext(String context, String clientId, String clientSecret, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the context's Keycloak server, by using provided clientId and client secret, reducing the audience to the requested one. Optionally extra HTTP headers can be provided to be used in the call. The implementation uses the customx-d4science-contextHTTP header that the proper mapper on Keycloak uses to reduce the audience- Specified by:
queryOIDCTokenWithContextin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenWithContext
public TokenResponse queryOIDCTokenWithContext(URL tokenURL, String clientId, String clientSecret, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided clientId and client secret, reducing the audience to the requested one. Optionally extra HTTP headers can be provided to be used in the call. The implementation uses the customx-d4science-contextHTTP header that the proper mapper on Keycloak uses to reduce the audience- Specified by:
queryOIDCTokenWithContextin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenWithContext
public TokenResponse queryOIDCTokenWithContext(String context, String authorization, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided authorization, reducing the audience to the requested one. Optionally extra HTTP headers can be provided to be used in the call.- Specified by:
queryOIDCTokenWithContextin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenWithContext
public TokenResponse queryOIDCTokenWithContext(URL tokenURL, String authorization, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided authorization, reducing the audience to the requested one.- Specified by:
queryOIDCTokenWithContextin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 Keycloak- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
constructBasicAuthenticationHeader
protected static String constructBasicAuthenticationHeader(String clientId, String clientSecret)
-
queryOIDCTokenOfUserWithContext
public TokenResponse queryOIDCTokenOfUserWithContext(String context, String clientId, String clientSecret, String username, String password, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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. The implementation uses the customx-d4science-contextHTTP header that the proper mapper on Keycloak uses to reduce the audience- Specified by:
queryOIDCTokenOfUserWithContextin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 Keycloak- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenOfUserWithContext
public TokenResponse queryOIDCTokenOfUserWithContext(String context, String clientId, String clientSecret, String username, String password, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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. Optionally extra HTTP headers can be provided to be used in the call. The implementation uses the customx-d4science-contextHTTP header that the proper mapper on Keycloak uses to reduce the audience- Specified by:
queryOIDCTokenOfUserWithContextin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenOfUserWithContext
public TokenResponse queryOIDCTokenOfUserWithContext(String context, String authorization, String username, String password, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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.- Specified by:
queryOIDCTokenOfUserWithContextin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 Keycloak- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenOfUserWithContext
public TokenResponse queryOIDCTokenOfUserWithContext(String context, String authorization, String username, String password, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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. Optionally extra HTTP headers can be provided to be used in the call.- Specified by:
queryOIDCTokenOfUserWithContextin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenOfUserWithContext
public TokenResponse queryOIDCTokenOfUserWithContext(URL tokenURL, String clientId, String clientSecret, String username, String password, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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. The implementation uses the customx-d4science-contextHTTP header that the proper mapper on Keycloak uses to reduce the audience- Specified by:
queryOIDCTokenOfUserWithContextin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 Keycloak- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenOfUserWithContext
public TokenResponse queryOIDCTokenOfUserWithContext(URL tokenURL, String clientId, String clientSecret, String username, String password, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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. Optionally extra HTTP headers can be provided to be used in the call.- Specified by:
queryOIDCTokenOfUserWithContextin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenOfUserWithContext
public TokenResponse queryOIDCTokenOfUserWithContext(URL tokenURL, String authorization, String username, String password, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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.- Specified by:
queryOIDCTokenOfUserWithContextin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 Keycloak- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenOfUserWithContext
public TokenResponse queryOIDCTokenOfUserWithContext(URL tokenURL, String authorization, String username, String password, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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. Optionally extra HTTP headers can be provided to be used in the call.- Specified by:
queryOIDCTokenOfUserWithContextin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryOIDCTokenWithContext
public TokenResponse queryOIDCTokenWithContext(URL tokenURL, String authorization, String audience, Map<String,String> extraHeaders) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an OIDC token from the Keycloak server, by using provided authorization, reducing the audience to the requested one. Optionally extra HTTP headers can be provided to be used in the call.- Specified by:
queryOIDCTokenWithContextin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 request- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryUMAToken
public TokenResponse queryUMAToken(String context, TokenResponse oidcTokenResponse, String audience, List<String> permissions) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an UMA token from the Keycloak server, by using access-token provided by theTokenResponseobject for the given audience (context), in URLEncoded form or not, and optionally a list of permissions.- Specified by:
queryUMATokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)oidcTokenResponse- the previously issued token asTokenResponseobjectaudience- the audience (context) where to request the issuing of the ticketpermissions- a list of permissions, can benull- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryUMAToken
public TokenResponse queryUMAToken(URL tokenURL, TokenResponse oidcTokenResponse, String audience, List<String> permissions) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries an UMA token from the Keycloak server, by using access-token provided by theTokenResponseobject for the given audience (context), in URLEncoded form or not, and optionally a list of permissions.- Specified by:
queryUMATokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof the OIDC serveroidcTokenResponse- the previously issued token asTokenResponseobjectaudience- the audience (context) where to request the issuing of the ticketpermissions- a list of permissions, can benull- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
constructBeareAuthenticationHeader
protected static String constructBeareAuthenticationHeader(TokenResponse oidcTokenResponse)
-
queryUMAToken
public TokenResponse queryUMAToken(String context, String clientId, String clientSecret, String audience, List<String> permissions) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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.- Specified by:
queryUMATokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)clientId- the client idclientSecret- the client secretaudience- the audience (context) where to request the issuing of the ticketpermissions- a list of permissions, can benull- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryUMAToken
public TokenResponse queryUMAToken(URL tokenURL, String clientId, String clientSecret, String audience, List<String> permissions) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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.- Specified by:
queryUMATokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 benull- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryUMAToken
public TokenResponse queryUMAToken(String context, String authorization, String audience, List<String> permissions) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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.- Specified by:
queryUMATokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor 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 benull- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
queryUMAToken
public TokenResponse queryUMAToken(URL tokenURL, String authorization, String audience, List<String> permissions) throws KeycloakClientException
Description copied from interface:KeycloakClientQueries 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.- Specified by:
queryUMATokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof 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 benull- Returns:
- the issued token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the query
-
performRequest
protected TokenResponse performRequest(URL tokenURL, Map<String,String> headers, Map<String,List<String>> params) throws KeycloakClientException
- Throws:
KeycloakClientException
-
performRequest
protected <T> T performRequest(Class<T> returnObjectClass, URL url, Map<String,String> headers, Map<String,List<String>> params) throws KeycloakClientException
- Throws:
KeycloakClientException
-
refreshToken
public TokenResponse refreshToken(String context, TokenResponse tokenResponse) throws KeycloakClientException
Description copied from interface:KeycloakClientRefreshes a previously issued token from the Keycloak server using the refresh token JWT encoded string in the token response object. Client id will be read from "issued for" access token's claim and client secret will be not sent.
NOTE: Forpublicclients types only.- Specified by:
refreshTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)tokenResponse- the previously issued token asTokenResponseobject- Returns:
- the refreshed token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the refresh query
-
refreshToken
public TokenResponse refreshToken(URL tokenURL, TokenResponse tokenResponse) throws KeycloakClientException
Description copied from interface:KeycloakClientRefreshes a previously issued token from the Keycloak server using the refresh token JWT encoded string in the token response object. Client id will be read from "issued for" access token's claim and client secret will be not sent.
NOTE: Forpublicclients types only.- Specified by:
refreshTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof the OIDC servertokenResponse- the previously issued token asTokenResponseobject- Returns:
- the refreshed token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the refresh query
-
refreshToken
public TokenResponse refreshToken(String context, String clientId, String clientSecret, TokenResponse tokenResponse) throws KeycloakClientException
Description copied from interface:KeycloakClientRefreshes 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.- Specified by:
refreshTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)clientId- the requestor client id, may benulland in this case will be take from the access token "issued for" claimclientSecret- the requestor client secret, may benullfor non-confidential clientstokenResponse- the previously issued token asTokenResponseobject- Returns:
- the refreshed token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the refresh query
-
refreshToken
public TokenResponse refreshToken(URL tokenURL, String clientId, String clientSecret, TokenResponse tokenResponse) throws KeycloakClientException
Description copied from interface:KeycloakClientRefreshes 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.- Specified by:
refreshTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof the OIDC serverclientId- the requestor client id, may benulland in this case will be take from the access token "issued for" claimclientSecret- the requestor client secret, may benullfor non-confidential clientstokenResponse- the previously issued token asTokenResponseobject- Returns:
- the refreshed token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the refresh query
-
refreshToken
public TokenResponse refreshToken(String context, String clientId, String clientSecret, String refreshTokenJWTString) throws KeycloakClientException
Description copied from interface:KeycloakClientRefreshes 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.- Specified by:
refreshTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)clientId- the requestor client idclientSecret- the requestor client secret, may benullfor non-confidential clientsrefreshTokenJWTString- the previously issued refresh token JWT string- Returns:
- the refreshed token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the refresh query
-
refreshToken
public TokenResponse refreshToken(URL tokenURL, String clientId, String clientSecret, String refreshTokenJWTString) throws KeycloakClientException
Description copied from interface:KeycloakClientRefreshes 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.- Specified by:
refreshTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpointURLof the OIDC serverclientId- the requestor client idclientSecret- the requestor client secret, may benullfor non-confidential clientsrefreshTokenJWTString- the previously issued refresh token JWT string- Returns:
- the refreshed token as
TokenResponseobject - Throws:
KeycloakClientException- if something goes wrong performing the refresh query
-
exchangeTokenForAccessToken
public TokenResponse exchangeTokenForAccessToken(String context, String oidcAccessToken, String clientId, String clientSecret, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientExchanges a token for another access token for a specific client and a specific audience- Specified by:
exchangeTokenForAccessTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)oidcAccessToken- the original access token to exchangeclientId- the authorized client's idclientSecret- the authorized client's secretaudience- the requested token audience- Returns:
- the exchanged token response
- Throws:
KeycloakClientException- if an error occurs during the exchange
-
exchangeTokenForAccessToken
public TokenResponse exchangeTokenForAccessToken(URL tokenURL, String oidcAccessToken, String clientId, String clientSecret, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientExchanges a token for another access token for a specific client and a specific audience- Specified by:
exchangeTokenForAccessTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpoint URLoidcAccessToken- the original access token to exchangeclientId- the authorized client's idclientSecret- the authorized client's secretaudience- the requested token audience- Returns:
- the exchanged token response
- Throws:
KeycloakClientException- if an error occurs during the exchange
-
exchangeTokenForRefreshToken
public TokenResponse exchangeTokenForRefreshToken(String context, String oidcAccessToken, String clientId, String clientSecret, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientExchanges a token for another access and a refresh tokens for a specific client and a specific audience- Specified by:
exchangeTokenForRefreshTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)oidcAccessToken- the original access token to exchangeclientId- the authorized client's idclientSecret- the authorized client's secretaudience- the requested token audience- Returns:
- the exchanged token response
- Throws:
KeycloakClientException- if an error occurs during the exchange
-
exchangeTokenForRefreshToken
public TokenResponse exchangeTokenForRefreshToken(URL tokenURL, String oidcAccessToken, String clientId, String clientSecret, String audience) throws KeycloakClientException
Description copied from interface:KeycloakClientExchanges a token for another access and a refresh tokens for a specific client and a specific audience- Specified by:
exchangeTokenForRefreshTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpoint URLoidcAccessToken- the original access token to exchangeclientId- the authorized client's idclientSecret- the authorized client's secretaudience- the requested token audience- Returns:
- the exchanged token response
- Throws:
KeycloakClientException- if an error occurs during the exchange
-
exchangeTokenForOfflineToken
public TokenResponse exchangeTokenForOfflineToken(String context, String oidcAccessToken, String clientId, String clientSecret, String audience) throws IllegalArgumentException, KeycloakClientException
Description copied from interface:KeycloakClientExchanges 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 theoffline_accesswithin its scopes- Specified by:
exchangeTokenForOfflineTokenin interfaceKeycloakClient- Parameters:
context- the token endpoint URLoidcAccessToken- the original access token to exchangeclientId- the authorized client's idclientSecret- the authorized client's secretaudience- the requested token audience- Returns:
- the exchanged token response
- Throws:
IllegalArgumentException- if the original token does'nt contains theoffline_accessscope within its scopes or if is impossible to parse the access token as JSONKeycloakClientException- if an error occurs during the exchange
-
exchangeTokenForOfflineToken
public TokenResponse exchangeTokenForOfflineToken(URL tokenURL, String oidcAccessToken, String clientId, String clientSecret, String audience) throws IllegalArgumentException, KeycloakClientException
Description copied from interface:KeycloakClientExchanges 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 scopeoffline_accesswithin its scopes- Specified by:
exchangeTokenForOfflineTokenin interfaceKeycloakClient- Parameters:
tokenURL- the token endpoint URLoidcAccessToken- the original access token to exchangeclientId- the authorized client's idclientSecret- the authorized client's secretaudience- the requested token audience- Returns:
- the exchanged token response
- Throws:
IllegalArgumentException- if the original token does'nt contains theoffline_accessscope within its scopes or if is impossible to parse the access token as JSONKeycloakClientException- if an error occurs during the exchange
-
exchangeToken
protected TokenResponse exchangeToken(URL tokenURL, String oidcAccessToken, String clientId, String clientSecret, String audience, String requestedTokenType, String scope) throws KeycloakClientException
Queries from the OIDC server an exchanged token by using provided access token, for the given audience (context), in URLEncoded form or not,- Parameters:
tokenURL- the token endpointURLof the OIDC serveroidcAccessToken- the auth token (the access token URLEncoded by the "Bearer " string)clientId- the client idclientSecret- the client secretaudience- the audience (context) where to request the issuing of the ticket (URLEncoded)requestedTokenType- the token type (e.g.refresh)scope- the scope, optional can benull- Returns:
- the issued exchanged token
- Throws:
KeycloakClientException- if an error occurs, inspect the exception for details
-
introspectAccessToken
public TokenIntrospectionResponse introspectAccessToken(String context, String clientId, String clientSecret, String accessTokenJWTString) throws KeycloakClientException
Description copied from interface:KeycloakClientIntrospects an access token against the Keycloak server.- Specified by:
introspectAccessTokenin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)clientId- the requestor client idclientSecret- the requestor client secretaccessTokenJWTString- the access token to verify- Returns:
- a
TokenIntrospectionResponseobject with the introspection results; in particular, theactivefield represents the token validity - Throws:
KeycloakClientException- if something goes wrong performing the verification
-
introspectAccessToken
public TokenIntrospectionResponse introspectAccessToken(URL introspectionURL, String clientId, String clientSecret, String accessTokenJWTString) throws KeycloakClientException
Description copied from interface:KeycloakClientIntrospects an access token against the Keycloak server.- Specified by:
introspectAccessTokenin interfaceKeycloakClient- Parameters:
introspectionURL- the introspection endpointURLof the Keycloak serverclientId- the requestor client idclientSecret- the requestor client secretaccessTokenJWTString- the access token to verify- Returns:
- a
TokenIntrospectionResponseobject with the introspection results; in particular, theactivefield represents the token validity - Throws:
KeycloakClientException- if something goes wrong performing the verification
-
isAccessTokenVerified
public boolean isAccessTokenVerified(String context, String clientId, String clientSecret, String accessTokenJWTString) throws KeycloakClientException
Description copied from interface:KeycloakClientVerifies an access token against the Keycloak server.- Specified by:
isAccessTokenVerifiedin interfaceKeycloakClient- Parameters:
context- the context where the Keycloak's is needed (e.g./gcubefor DEV)clientId- the requestor client idclientSecret- the requestor client secretaccessTokenJWTString- the access token to verify- Returns:
trueif the token is active,falseotherwise- Throws:
KeycloakClientException- if something goes wrong performing the verification
-
isAccessTokenVerified
public boolean isAccessTokenVerified(URL introspectionURL, String clientId, String clientSecret, String accessTokenJWTString) throws KeycloakClientException
Description copied from interface:KeycloakClientVerifies an access token against the Keycloak server.- Specified by:
isAccessTokenVerifiedin interfaceKeycloakClient- Parameters:
introspectionURL- the introspection endpointURLof the Keycloak serverclientId- the requestor client idclientSecret- the requestor client secretaccessTokenJWTString- the access token to verify- Returns:
trueif the token is active,falseotherwise- Throws:
KeycloakClientException- if something goes wrong performing the verification
-
safeSetAsExternalCallForOldAPI
protected void safeSetAsExternalCallForOldAPI(org.gcube.common.gxhttp.request.GXHTTPStringRequest request)
-
getAvatarData
public byte[] getAvatarData(String context, TokenResponse tokenResponse) throws KeycloakClientException
Description copied from interface:KeycloakClientRetrieves the user's avatar image data from Keycloak server.- Specified by:
getAvatarDatain interfaceKeycloakClient- Parameters:
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.- Returns:
- the avatar's data bytes
- Throws:
KeycloakClientException- if something goes wrong in the request
-
getAvatarData
public byte[] getAvatarData(URL avatarURL, TokenResponse tokenResponse) throws KeycloakClientException
Description copied from interface:KeycloakClientRetrieves the user's avatar image data from Keycloak server.- Specified by:
getAvatarDatain interfaceKeycloakClient- Parameters:
avatarURL- the server's avatar endpoint URLtokenResponse- the token response where to get the bearer token for the authorization header.- Returns:
- the avatar's data bytes
- Throws:
KeycloakClientException- if something goes wrong in the request
-
getAvatarData
public byte[] getAvatarData(URL avatarURL, String authorization) throws KeycloakClientException
Description copied from interface:KeycloakClientRetrieves the user's avatar image data from Keycloak server.- Specified by:
getAvatarDatain interfaceKeycloakClient- Parameters:
avatarURL- the server's avatar endpoint URLauthorization- the string to user as authorization header (e.g. 'bearer xxxx')- Returns:
- the avatar's data bytes
- Throws:
KeycloakClientException- if something goes wrong in the request
-
-