public class D4ScienceIAMClient extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
logger
Logger instance for this class
|
static boolean |
USE_DYNAMIC_SCOPES
Flag to enable/disable dynamic scopes functionality
|
| Modifier and Type | Method and Description |
|---|---|
D4ScienceIAMClientAuthn |
authenticate(String clientId,
String clientSecret)
Authenticates the client with provided id and secret
|
D4ScienceIAMClientAuthn |
authenticate(String clientId,
String clientSecret,
String context)
Authenticates the client with provided credentials, reducing the token audience to the requested `context`
|
D4ScienceIAMClientAuthn |
authenticateUser(String username,
String password)
Deprecated.
this authn method is deprecated in the oauth2 specifications (see https://oauth.net/2/grant-types/password/)
|
D4ScienceIAMClientAuthn |
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/)
|
D4ScienceIAMClientAuthn |
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/)
|
D4ScienceIAMClientAuthn |
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/)
|
D4ScienceIAMClientAuthz |
authorize(String clientId,
String clientSecret,
String context)
Directly authorizes the client by using the provided credentials, for the specific context audience and with no optional permissions
|
D4ScienceIAMClientAuthz |
authorize(String clientId,
String clientSecret,
String context,
List<String> permissions)
Directly authorizes the client by using the provided credentials, for the specific context audience and with optional permissions
|
protected org.gcube.common.keycloak.KeycloakClient |
getKeycloakClient()
Returns the underlying Keycloak client instance.
|
URL |
getRealmBaseURL()
Returns the base URL of the realm.
|
boolean |
isTokenValid(String token)
Checks if the token is valid (signature and expiration).
|
boolean |
isTokenValid(String token,
boolean checkExpiration)
Checks if the token is valid and optionally checks for expiration.
|
static D4ScienceIAMClient |
newInstance(String contextInfra)
Creates a new client for the specific context, in the default IAM realm.
|
static D4ScienceIAMClient |
newInstance(String contextInfra,
String realm)
Creates a new client for the specific context, in the default realm.
|
static D4ScienceIAMClient |
newInstance(URL realmBaseURL)
Creates a new client with the provided base URL.
|
static void |
setDefaultGatewayClientID(String gatewayClientId)
Sets the new default GW
clientId used for all the queries to the IAM server. |
void |
verifyToken(String token)
Verifies the token signature and also checks the expiration.
|
void |
verifyToken(String token,
boolean checkExpiration)
Verifies the token signature and optionally checks for expiration.
|
protected static org.slf4j.Logger logger
public static boolean USE_DYNAMIC_SCOPES
public static void setDefaultGatewayClientID(String gatewayClientId)
clientId used for all the queries to the IAM server.
Note: The operation will logged as WARN to be visible.gatewayClientId - the new GW clientIdpublic static D4ScienceIAMClient newInstance(String contextInfra) throws D4ScienceIAMClientException
contextInfra - the context to be used to obtain the base URL of the infrastructureD4ScienceIAMClientException - if an error occurs obtaining the base URLpublic static D4ScienceIAMClient newInstance(String contextInfra, String realm) throws D4ScienceIAMClientException
contextInfra - the context to be used to obtain the base URL of the infrastructurerealm - the IAM realmD4ScienceIAMClientException - if an error occurs obtaining the base URLpublic static D4ScienceIAMClient newInstance(URL realmBaseURL)
realmBaseURL - the realm base URLprotected org.gcube.common.keycloak.KeycloakClient getKeycloakClient()
public URL getRealmBaseURL()
public D4ScienceIAMClientAuthn authenticate(String clientId, String clientSecret) throws D4ScienceIAMClientException
clientId - the client idclientSecret - the client secretD4ScienceIAMClientException - if an error occurs during authn processpublic D4ScienceIAMClientAuthn authenticate(String clientId, String clientSecret, String context) throws D4ScienceIAMClientException
clientId - the client idclientSecret - the client secretcontext - the requested token context audience (e.g. a specific context or another client)D4ScienceIAMClientException - if an error occurs during authn processpublic D4ScienceIAMClientAuthn authenticateUser(String username, String password) throws D4ScienceIAMClientException
clientId.username - the user's usernamepassword - the user's passwordD4ScienceIAMClientException - if an error occurs during authn processpublic D4ScienceIAMClientAuthn authenticateUser(String username, String password, String context) throws D4ScienceIAMClientException
clientId.username - the user's usernamepassword - the user's passwordcontext - the requested token context audience (e.g. a specific context or another client)D4ScienceIAMClientException - if an error occurs during authn processpublic D4ScienceIAMClientAuthn authenticateUser(String clientId, String clientSecret, String username, String password) throws D4ScienceIAMClientException
clientId - the client idclientSecret - the client secretusername - the user's usernamepassword - the user's passwordD4ScienceIAMClientException - if an error occurs during authn processpublic D4ScienceIAMClientAuthn authenticateUser(String clientId, String clientSecret, String username, String password, String context) throws D4ScienceIAMClientException
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)D4ScienceIAMClientException - if an error occurs during authn processpublic D4ScienceIAMClientAuthz authorize(String clientId, String clientSecret, String context) throws D4ScienceIAMClientException
clientId - the client idclientSecret - the client secretcontext - the requested token context audience (e.g. a specific context or another client)D4ScienceIAMClientException - if an error occurs during authz processpublic D4ScienceIAMClientAuthz authorize(String clientId, String clientSecret, String context, List<String> permissions) throws D4ScienceIAMClientException
clientId - the client idclientSecret - the client secretcontext - the requested token context audience (e.g. a specific context or another client)permissions - the optional permissionsD4ScienceIAMClientException - if an error occurs during authz processpublic void verifyToken(String token) throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, org.gcube.io.jsonwebtoken.JwtException, Exception
token - the base64 JWT token stringorg.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)public void verifyToken(String token, boolean checkExpiration) throws org.gcube.io.jsonwebtoken.security.SignatureException, org.gcube.io.jsonwebtoken.ExpiredJwtException, org.gcube.io.jsonwebtoken.JwtException, Exception
token - the base64 JWT token stringcheckExpiration - flag to enable/disable expiration checkorg.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)public boolean isTokenValid(String token) throws D4ScienceIAMClientException
token - the base64 JWT token stringtrue if the token is valid, false otherwiseD4ScienceIAMClientException - if an error occurs during the verification processpublic boolean isTokenValid(String token, boolean checkExpiration) throws D4ScienceIAMClientException
token - the base64 JWT token stringcheckExpiration - true if the token is valid, false otherwiseD4ScienceIAMClientException - if an error occurs during the verification processCopyright © 2026. All rights reserved.