diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f92992..69b6b5f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Resource Registry Schema Client
+## [v4.2.0-SNAPSHOT]
+
+- Enhanced gcube-bom version
+
+
## [v4.1.0]
- Restrict the interface to accept ERElement classes and not all the Element classes [#21973]
diff --git a/pom.xml b/pom.xml
index 7952fb9..cae706c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
org.gcube.information-system
resource-registry-schema-client
- 4.1.0
+ 4.2.0-SNAPSHOT
Resource Registry Schema Client
Contains Non Idempotent API to manage Schemas in Resource Registry
@@ -29,7 +29,7 @@
org.gcube.distribution
gcube-bom
- 2.1.0
+ 2.2.0-SNAPSHOT
pom
import
@@ -37,14 +37,6 @@
-
- org.gcube.common
- authorization-client
-
-
- org.gcube.resources.discovery
- ic-client
-
org.gcube.information-system
resource-registry-api
diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientFactory.java b/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientFactory.java
index 4609936..3278cbc 100644
--- a/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientFactory.java
+++ b/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientFactory.java
@@ -1,8 +1,5 @@
package org.gcube.informationsystem.resourceregistry.schema;
-import org.gcube.common.authorization.library.AuthorizationEntry;
-import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
-import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.resourceregistry.api.Constants;
import org.gcube.informationsystem.resourceregistry.api.rest.ServiceInstance;
import org.slf4j.Logger;
@@ -14,18 +11,7 @@ import org.slf4j.LoggerFactory;
public class ResourceRegistrySchemaClientFactory {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientFactory.class);
-
- public static String getCurrentContextFullName() {
- String token = SecurityTokenProvider.instance.get();
- AuthorizationEntry authorizationEntry = null;
- try {
- authorizationEntry = org.gcube.common.authorization.client.Constants.authorizationService().get(token);
- } catch(Exception e) {
- return ScopeProvider.instance.get();
- }
- return authorizationEntry.getContext();
- }
-
+
public static ResourceRegistrySchemaClient create() {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ContextTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ContextTest.java
index eb4b99f..b9b61ad 100644
--- a/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ContextTest.java
+++ b/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ContextTest.java
@@ -7,14 +7,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
-import org.gcube.common.authorization.client.Constants;
-import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
-import org.gcube.common.authorization.library.AuthorizationEntry;
-import org.gcube.common.authorization.library.provider.AuthorizationProvider;
-import org.gcube.common.authorization.library.provider.ClientInfo;
-import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
-import org.gcube.common.authorization.library.utils.Caller;
+import org.gcube.common.authorization.utils.manager.SecretManager;
+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.keycloak.KeycloakClientFactory;
+import org.gcube.common.keycloak.model.TokenResponse;
import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.informationsystem.model.reference.properties.Header;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
@@ -22,78 +23,107 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
- *
*/
+@SuppressWarnings("deprecation")
public class ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
- protected static Properties properties;
- protected static final String PROPERTIES_FILENAME = "token.properties";
+ protected static final String CONFIG_INI_FILENAME = "config.ini";
public static final String PARENT_DEFAULT_TEST_SCOPE;
public static final String DEFAULT_TEST_SCOPE;
public static final String ALTERNATIVE_TEST_SCOPE;
- public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
+ public static final String GCUBE;
+ public static final String DEVNEXT;
+ public static final String NEXTNEXT;
+ public static final String DEVSEC;
+ public static final String DEVVRE;
+
+ protected static final Properties properties;
+
+ protected static final String CLIENT_ID_PROPERTY_KEY = "client_id";
+ protected static final String CLIENT_SECRET_PROPERTY_KEY = "client_secret";
+
+ protected static final String clientID;
+ protected static final String clientSecret;
- protected static final String REGISTRY_PROPERTIES_FILENAME = "registry.properties";
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
public static final String RESOURCE_REGISTRY_URL;
static {
- properties = new Properties();
- InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
+ GCUBE = "/gcube";
+ DEVNEXT = GCUBE + "/devNext";
+ NEXTNEXT = DEVNEXT + "/NextNext";
+ DEVSEC = GCUBE + "/devsec";
+ DEVVRE = DEVSEC + "/devVRE";
+ PARENT_DEFAULT_TEST_SCOPE = "/gcube";
+ DEFAULT_TEST_SCOPE = DEVNEXT;
+ ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
+
+ properties = new Properties();
+ InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
try {
// load the properties file
properties.load(input);
- } catch(IOException e) {
+
+ clientID = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
+ clientSecret = properties.getProperty(CLIENT_SECRET_PROPERTY_KEY);
+
+ RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
+
+ } catch (IOException e) {
throw new RuntimeException(e);
}
- // PARENT_DEFAULT_TEST_SCOPE = "/pred4s"
- // DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "/preprod";
- // ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
-
-
- PARENT_DEFAULT_TEST_SCOPE = "/gcube";
- DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
- ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
-
- DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
-
+ }
+
+ public static void set(Secret secret) throws Exception {
+ SecretManagerProvider.instance.reset();
+ SecretManager secretManager = new SecretManager();
+ secretManager.addSecret(secret);
+ SecretManagerProvider.instance.set(secretManager);
+ SecretManagerProvider.instance.get().set();
+ }
+
+ public static void setContextByName(String fullContextName) throws Exception {
+ Secret secret = getSecretByContextName(fullContextName);
+ set(secret);
+ }
+
+
+ private static TokenResponse getJWTAccessToken(String context) throws Exception {
+ ScopeProvider.instance.set(context);
+ TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
+ return tr;
+ }
+
+ public static Secret getSecretByContextName(String context) throws Exception {
+ TokenResponse tr = getJWTAccessToken(context);
+ Secret secret = new JWTSecret(tr.getAccessToken());
+ return secret;
+ }
+
+ public static void setContext(String token) throws Exception {
+ Secret secret = getSecret(token);
+ set(secret);
+ }
+
+ private static Secret getSecret(String token) throws Exception {
+ Secret secret = SecretUtility.getSecretByTokenString(token);
+ return secret;
+ }
+
+ public static String getUser() {
+ String user = Header.UNKNOWN_USER;
try {
- setContextByName(DEFAULT_TEST_SCOPE);
+ user = SecretManagerProvider.instance.get().getUser().getUsername();
} catch(Exception e) {
- throw new RuntimeException(e);
+ logger.error("Unable to retrieve user. {} will be used", user);
}
-
- RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
-
- }
-
- public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
- AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
- String context = authorizationEntry.getContext();
- logger.info("Context of token {} is {}", token, context);
- return context;
- }
-
- public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
- String token = ContextTest.properties.getProperty(fullContextName);
- setContext(token);
- }
-
- private static void setContext(String token) throws ObjectNotFound, Exception {
- SecurityTokenProvider.instance.set(token);
- AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
- ClientInfo clientInfo = authorizationEntry.getClientInfo();
- logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
- String qualifier = authorizationEntry.getQualifier();
- Caller caller = new Caller(clientInfo, qualifier);
- AuthorizationProvider.instance.set(caller);
- ScopeProvider.instance.set(getCurrentScope(token));
+ return user;
}
@BeforeClass
@@ -103,8 +133,7 @@ public class ContextTest {
@AfterClass
public static void afterClass() throws Exception {
- SecurityTokenProvider.instance.reset();
- ScopeProvider.instance.reset();
+ SecretManagerProvider.instance.reset();
}
}