Package org.gcube.common.iam
Class D4ScienceIAMClient
java.lang.Object
org.gcube.common.iam.D4ScienceIAMClient
Helper class that acts as IAM client providing authentication and authorization using the IAM hiding the underlying implementation
- Author:
- Mauro Mugnaini (Nubisware S.r.l.)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static org.slf4j.LoggerLogger instance for this classstatic booleanFlag to enable/disable dynamic scopes functionality -
Method Summary
Modifier and TypeMethodDescriptionauthenticate(String clientId, String clientSecret) Authenticates the client with provided id and secretauthenticate(String clientId, String clientSecret, String context) Authenticates the client with provided credentials, reducing the token audience to the requested `context`authenticateUser(String username, String password) Deprecated.this authn method is deprecated in the oauth2 specifications (see https://oauth.net/2/grant-types/password/)authenticateUser(String username, String password, String context) Deprecated.this authn method is deprecated in the oauth2 specifications (see https://oauth.net/2/grant-types/password/)authenticateUser(String clientId, String clientSecret, String username, String password) Deprecated.this authn method is deprecated in the oauth2 specifications (see https://oauth.net/2/grant-types/password/)authenticateUser(String clientId, String clientSecret, String username, String password, String context) Deprecated.this authn method is deprecated in the oauth2 specifications (see https://oauth.net/2/grant-types/password/)Directly authorizes the client by using the provided credentials, for the specific context audience and with no optional permissionsDirectly authorizes the client by using the provided credentials, for the specific context audience and with optional permissionsprotected org.gcube.common.keycloak.KeycloakClientReturns the underlying Keycloak client instance.Returns the base URL of the realm.static D4ScienceIAMClientnewInstance(String contextInfra) Creates a new client for the specific context, in the default IAM realm.static D4ScienceIAMClientnewInstance(String contextInfra, String realm) Creates a new client for the specific context, in the default realm.static D4ScienceIAMClientnewInstance(URL realmBaseURL) Creates a new client with the provided base URL.static voidsetDefaultGatewayClientID(String gatewayClientId) Sets the new default GWclientIdused for all the queries to the IAM server.voidverifyToken(String token) Verifies the token signature and expiration
-
Field Details
-
logger
protected static org.slf4j.Logger loggerLogger instance for this class -
USE_DYNAMIC_SCOPES
public static boolean USE_DYNAMIC_SCOPESFlag to enable/disable dynamic scopes functionality
-
-
Method Details
-
setDefaultGatewayClientID
Sets the new default GWclientIdused for all the queries to the IAM server. Note: The operation will logged as WARN to be visible.- Parameters:
gatewayClientId- the new GWclientId
-
newInstance
public static D4ScienceIAMClient newInstance(String contextInfra) throws D4ScienceIAMClientException Creates a new client for the specific context, in the default IAM realm.- Parameters:
contextInfra- the context to be used to obtain the base URL of the infrastructure- Returns:
- the client to be used for authn and authz requests
- Throws:
D4ScienceIAMClientException- if an error occurs obtaining the base URL
-
newInstance
public static D4ScienceIAMClient newInstance(String contextInfra, String realm) throws D4ScienceIAMClientException Creates a new client for the specific context, in the default realm.- Parameters:
contextInfra- the context to be used to obtain the base URL of the infrastructurerealm- the IAM realm- Returns:
- the client to be used for authn and authz requests
- Throws:
D4ScienceIAMClientException- if an error occurs obtaining the base URL
-
newInstance
Creates a new client with the provided base URL.- Parameters:
realmBaseURL- the realm base URL- Returns:
- the client to be used for authn and authz requests
-
getKeycloakClient
protected org.gcube.common.keycloak.KeycloakClient getKeycloakClient()Returns the underlying Keycloak client instance.- Returns:
- the Keycloak client
-
getRealmBaseURL
Returns the base URL of the realm.- Returns:
- the realm base URL
-
authenticate
public D4ScienceIAMClientAuthn authenticate(String clientId, String clientSecret) throws D4ScienceIAMClientException Authenticates the client with provided id and secret- Parameters:
clientId- the client idclientSecret- the client secret- Returns:
- the authn object
- Throws:
D4ScienceIAMClientException- if an error occurs during authn process
-
authenticate
public D4ScienceIAMClientAuthn authenticate(String clientId, String clientSecret, String context) throws D4ScienceIAMClientException Authenticates the client with provided credentials, reducing the token audience to the requested `context`- Parameters:
clientId- the client idclientSecret- the client secretcontext- the requested token context audience (e.g. a specific context or another client)- Returns:
- the authn object
- Throws:
D4ScienceIAMClientException- if an error occurs during authn process
-
authenticateUser
public D4ScienceIAMClientAuthn authenticateUser(String username, String password) throws D4ScienceIAMClientException Deprecated.this authn method is deprecated in the oauth2 specifications (see https://oauth.net/2/grant-types/password/)Authenticates the user with provided username and password by using the defaultclientId.- Parameters:
username- the user's usernamepassword- the user's password- Returns:
- the authn object
- Throws:
D4ScienceIAMClientException- if an error occurs during authn process
-
authenticateUser
public D4ScienceIAMClientAuthn authenticateUser(String username, String password, String context) throws D4ScienceIAMClientException Deprecated.this authn method is deprecated in the oauth2 specifications (see https://oauth.net/2/grant-types/password/)Authenticates the user with provided username and password by using the defaultclientId.- Parameters:
username- the user's usernamepassword- the user's passwordcontext- the requested token context audience (e.g. a specific context or another client)- Returns:
- the authn object
- Throws:
D4ScienceIAMClientException- if an error occurs during authn process
-
authenticateUser
public D4ScienceIAMClientAuthn authenticateUser(String clientId, String clientSecret, String username, String password) throws D4ScienceIAMClientException Deprecated.this authn method is deprecated in the oauth2 specifications (see https://oauth.net/2/grant-types/password/)Authenticates the user with provided username and password- Parameters:
clientId- the client idclientSecret- the client secretusername- the user's usernamepassword- the user's password- Returns:
- the authn object
- Throws:
D4ScienceIAMClientException- if an error occurs during authn process
-
authenticateUser
public D4ScienceIAMClientAuthn authenticateUser(String clientId, String clientSecret, String username, String password, String context) throws D4ScienceIAMClientException Deprecated.this authn method is deprecated in the oauth2 specifications (see https://oauth.net/2/grant-types/password/)Authenticates the user with provided credentials, reducing the token audience to the requested `context`.- Parameters:
clientId- the client idclientSecret- the client secretusername- the user's usernamepassword- the user's passwordcontext- the requested token context audience (e.g. a specific context or another client)- Returns:
- the authn object
- Throws:
D4ScienceIAMClientException- if an error occurs during authn process
-
authorize
public D4ScienceIAMClientAuthz authorize(String clientId, String clientSecret, String context) throws D4ScienceIAMClientException Directly authorizes the client by using the provided credentials, for the specific context audience and with no optional permissions- Parameters:
clientId- the client idclientSecret- the client secretcontext- the requested token context audience (e.g. a specific context or another client)- Returns:
- the authz object
- Throws:
D4ScienceIAMClientException- if an error occurs during authz process
-
authorize
public D4ScienceIAMClientAuthz authorize(String clientId, String clientSecret, String context, List<String> permissions) throws D4ScienceIAMClientException Directly authorizes the client by using the provided credentials, for the specific context audience and with optional permissions- Parameters:
clientId- the client idclientSecret- the client secretcontext- the requested token context audience (e.g. a specific context or another client)permissions- the optional permissions- Returns:
- the authz object
- Throws:
D4ScienceIAMClientException- if an error occurs during authz process
-
verifyToken
public void verifyToken(String token) throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, org.gcube.io.jsonwebtoken.JwtException, Exception Verifies the token signature and expiration- Parameters:
token- the base64 JWT token string- Throws:
org.gcube.io.jsonwebtoken.security.SignatureException- if the token signature is invalidorg.gcube.io.jsonwebtoken.ExpiredJwtException- if the token is expiredorg.gcube.io.jsonwebtoken.JwtException- if another JWT related problem is foundException- if an unexpected error occurs (e.g. constructing the verifier)
-