diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/ContextTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/ContextTest.java index faedde6..fcdabad 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/ContextTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/ContextTest.java @@ -12,6 +12,8 @@ import org.gcube.common.authorization.utils.manager.SecretManagerProvider; import org.gcube.common.authorization.utils.secret.JWTSecret; import org.gcube.common.authorization.utils.secret.Secret; import org.gcube.common.authorization.utils.secret.SecretUtility; +import org.gcube.common.iam.D4ScienceIAMClient; +import org.gcube.common.iam.D4ScienceIAMClientAuthn; import org.gcube.common.keycloak.KeycloakClientFactory; import org.gcube.common.keycloak.KeycloakClientHelper; import org.gcube.common.keycloak.model.TokenResponse; @@ -90,20 +92,22 @@ public class ContextTest { } - private static TokenResponse getJWTAccessToken(String context) throws Exception { + protected static String getJWTAccessToken(String context) throws Exception { Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString()); - TokenResponse tr = null; + String accessToken = null; int index = context.indexOf('/', 1); String root = context.substring(0, index == -1 ? context.length() : index); + D4ScienceIAMClient iamClient = D4ScienceIAMClient.newInstance(root); + D4ScienceIAMClientAuthn d4ScienceIAMClientAuthn = null; switch (type) { case CLIENT_ID: String clientId = properties.getProperty(CLIENT_ID_PROPERTY_KEY); String clientSecret = properties.getProperty(root); - tr = KeycloakClientFactory.newInstance().queryUMAToken(context, clientId, clientSecret, context, null); + d4ScienceIAMClientAuthn = iamClient.authenticate(clientId, clientSecret, context); break; case USER: @@ -111,34 +115,20 @@ public class ContextTest { String username = properties.getProperty(USERNAME_PROPERTY_KEY); String password = properties.getProperty(PASSWORD_PROPERTY_KEY); - switch (root) { - case "/gcube": - default: - clientId = "next.d4science.org"; - break; - - case "/pred4s": - clientId = "pre.d4science.org"; - break; - - case "/d4science.research-infrastructures.eu": - clientId = "services.d4science.org"; - break; - } - clientSecret = null; - - tr = KeycloakClientHelper.getTokenForUser(context, username, password); + d4ScienceIAMClientAuthn = iamClient.authenticateUser(username, password, context); break; } - - return tr; + accessToken = d4ScienceIAMClientAuthn.getAccessTokenString(); + + logger.trace("Generated Access Token is {}", accessToken); + return accessToken; } public static Secret getSecretByContextName(String context) throws Exception { - TokenResponse tr = getJWTAccessToken(context); - Secret secret = new JWTSecret(tr.getAccessToken()); + String accessToken = getJWTAccessToken(context); + Secret secret = new JWTSecret(accessToken); return secret; }