diff --git a/CHANGELOG.md b/CHANGELOG.md
index c927ce4..9389296 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for StorageHub Application Persistence
+## [v4.0.0-SNAPSHOT]
+
+- Library migrated to Smartgears 4
+
## [v3.2.0]
- Added dependency to be able to compile with JDK 11
diff --git a/pom.xml b/pom.xml
index 5bf2401..cd0a6b3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.gcube.data-publishing
storagehub-application-persistence
- 3.2.0
+ 4.0.0-SNAPSHOT
StorageHub Application Persistence
This library allows any application to persist in its workspace home any
@@ -37,7 +37,7 @@
org.gcube.distribution
gcube-bom
- 2.1.0
+ 3.0.0-SNAPSHOT
pom
import
@@ -54,8 +54,7 @@
org.gcube.common
- authorization-utils
- [2.0.0, 3.0.0-SNAPSHOT)
+ common-security
org.projectlombok
@@ -75,5 +74,15 @@
logback-classic
test
+
+ org.gcube.common
+ keycloak-client
+ test
+
+
+ org.gcube.common.security
+ gcube-secrets
+ test
+
diff --git a/src/main/java/org/gcube/storagehub/StorageHubManagement.java b/src/main/java/org/gcube/storagehub/StorageHubManagement.java
index 3181fbf..16e57f3 100644
--- a/src/main/java/org/gcube/storagehub/StorageHubManagement.java
+++ b/src/main/java/org/gcube/storagehub/StorageHubManagement.java
@@ -5,10 +5,10 @@ import java.io.StringWriter;
import java.net.URL;
import java.util.List;
-import org.gcube.common.authorization.utils.manager.SecretManager;
-import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
-import org.gcube.common.scope.impl.ScopeBean;
-import org.gcube.common.scope.impl.ScopeBean.Type;
+import org.gcube.common.security.ContextBean;
+import org.gcube.common.security.ContextBean.Type;
+import org.gcube.common.security.providers.SecretManagerProvider;
+import org.gcube.common.security.secrets.Secret;
import org.gcube.common.storagehub.client.dsl.ContainerType;
import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
@@ -108,8 +108,8 @@ public class StorageHubManagement {
protected FolderContainer getContextFolder() throws Exception {
FolderContainer destinationFolder = getWorkspaceRoot();
String currentContext = SecretManagerProvider.instance.get().getContext();
- ScopeBean scopeBean = new ScopeBean(currentContext);
- switch(scopeBean.type()) {
+ ContextBean contextBean = new ContextBean(currentContext);
+ switch(contextBean.type()) {
case INFRASTRUCTURE:
case VO:
String folderName = currentContext.replaceFirst("/", "").replace("/", "_");
@@ -129,11 +129,11 @@ public class StorageHubManagement {
public FolderContainer getApplicationFolder() throws Exception {
FolderContainer destinationFolder = getContextFolder();
- SecretManager secretManager = SecretManagerProvider.instance.get();
- String currentContext = secretManager.getContext();
- ScopeBean scopeBean = new ScopeBean(currentContext);
- if(scopeBean.is(Type.VRE)) {
- String username = secretManager.getUser().getUsername();
+ Secret secret = SecretManagerProvider.instance.get();
+ String currentContext = secret.getContext();
+ ContextBean contextBean = new ContextBean(currentContext);
+ if(contextBean.is(Type.VRE)) {
+ String username = secret.getOwner().getId();
destinationFolder = getOrCreateFolder(destinationFolder, username, "Folder Created for user/application", true);
}
return destinationFolder;
diff --git a/src/test/java/org/gcube/storagehub/ContextTest.java b/src/test/java/org/gcube/storagehub/ContextTest.java
index 9e16b4d..fde659f 100644
--- a/src/test/java/org/gcube/storagehub/ContextTest.java
+++ b/src/test/java/org/gcube/storagehub/ContextTest.java
@@ -7,31 +7,25 @@ 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.scope.api.ScopeProvider;
+import org.gcube.common.keycloak.KeycloakClientFactory;
+import org.gcube.common.keycloak.model.TokenResponse;
+import org.gcube.common.security.providers.SecretManagerProvider;
+import org.gcube.common.security.secrets.AccessTokenSecret;
+import org.gcube.common.security.secrets.Secret;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
- *
*/
public class ContextTest {
- private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
-
protected static Properties properties;
protected static final String PROPERTIES_FILENAME = "token.properties";
- public static final String DEFAULT_TEST_SCOPE_NAME;
+ public static final String ROOT;
+ public static final String VO;
+ public static final String VRE;
static {
properties = new Properties();
@@ -44,42 +38,41 @@ public class ContextTest {
throw new RuntimeException(e);
}
- //DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
- DEFAULT_TEST_SCOPE_NAME = "/gcube/devNext/NextNext";
+ // DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
+ // DEFAULT_TEST_SCOPE_NAME = "/gcube/devsec/devVRE";
+
+ ROOT = "/gcube";
+ VO = ROOT + "/devsec";
+ VRE = VO + "/devVRE";
+ // VO = ROOT + "/devNext";
+ // VRE = VO + "/NextNext";
+
}
- 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 setContextBySecret(Secret secret) throws Exception {
+ SecretManagerProvider.instance.set(secret);
}
- public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
- String token = ContextTest.properties.getProperty(fullContextName);
- setContext(token);
+ public static void setContextByName(String fullContextName) throws Exception {
+ Secret secret = getSecretByContextName(fullContextName);
+ setContextBySecret(secret);
}
- public 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));
+ private static Secret getSecretByContextName(String fullContextName) throws Exception {
+ String clientID = "";
+ String clientSecret = ContextTest.properties.getProperty(fullContextName);
+ TokenResponse tokenResponse = KeycloakClientFactory.newInstance().queryUMAToken(fullContextName, clientID, clientSecret, fullContextName, null);
+ return new AccessTokenSecret(tokenResponse.getAccessToken());
}
@BeforeClass
public static void beforeClass() throws Exception {
- setContextByName(DEFAULT_TEST_SCOPE_NAME);
+ setContextByName(VRE);
}
@AfterClass
public static void afterClass() throws Exception {
- SecurityTokenProvider.instance.reset();
- ScopeProvider.instance.reset();
+ SecretManagerProvider.instance.reset();
}
}
diff --git a/src/test/java/org/gcube/storagehub/StorageHubManagementTest.java b/src/test/java/org/gcube/storagehub/StorageHubManagementTest.java
index 42590be..4ec0efc 100644
--- a/src/test/java/org/gcube/storagehub/StorageHubManagementTest.java
+++ b/src/test/java/org/gcube/storagehub/StorageHubManagementTest.java
@@ -3,9 +3,6 @@ package org.gcube.storagehub;
import java.util.List;
import java.util.Map;
-import org.gcube.common.authorization.utils.manager.SecretManager;
-import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
-import org.gcube.common.authorization.utils.secret.GCubeSecret;
import org.gcube.common.storagehub.client.dsl.ContainerType;
import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
@@ -26,20 +23,13 @@ public class StorageHubManagementTest extends ContextTest {
@Test
public void myTest() throws Exception {
- SecretManager secretManager = SecretManagerProvider.instance.get();
- GCubeSecret gCubeSecret = new GCubeSecret(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
- secretManager.startSession(gCubeSecret);
StorageHubManagement storageHubManagement = new StorageHubManagement();
FolderContainer contextFolder = storageHubManagement.getContextFolder();
logger.debug("Context Folder ID : {} - Name : {}", contextFolder.getId(), contextFolder.get().getName());
- secretManager.endSession();
}
@Test
public void test() throws Exception {
- SecretManager secretManager = SecretManagerProvider.instance.get();
- GCubeSecret gCubeSecret = new GCubeSecret(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
- secretManager.startSession(gCubeSecret);
StorageHubManagement storageHubManagement = new StorageHubManagement();
@SuppressWarnings("unused")
OpenResolver openResolver = storageHubManagement.storageHubClient.open("");
@@ -50,14 +40,10 @@ public class StorageHubManagementTest extends ContextTest {
openResolver = storageHubManagement.storageHubClient.open("bd44d81e-0e2f-4527-b634-2e26e8908f36");
openResolver.asItem().delete();
*/
- secretManager.endSession();
}
@Test
public void listFolders() throws Exception {
- SecretManager secretManager = SecretManagerProvider.instance.get();
- GCubeSecret gCubeSecret = new GCubeSecret(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
- secretManager.startSession(gCubeSecret);
StorageHubManagement storageHubManagement = new StorageHubManagement();
@SuppressWarnings("unused")
FolderContainer root = storageHubManagement.getWorkspaceRoot();
@@ -76,14 +62,10 @@ public class StorageHubManagementTest extends ContextTest {
// storageHubManagement.tree(root);
// storageHubManagement.tree(contextFolder);
// storageHubManagement.tree(dstFolder);
- secretManager.endSession();
}
@Test
public void getFileInfo() throws Exception {
- SecretManager secretManager = SecretManagerProvider.instance.get();
- GCubeSecret gCubeSecret = new GCubeSecret(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
- secretManager.startSession(gCubeSecret);
StorageHubManagement storageHubManagement = new StorageHubManagement();
String id = "3daf465b-b84e-4d1c-9786-a388a267382c";
OpenResolver openResolver = storageHubManagement.storageHubClient.open(id);
@@ -106,14 +88,10 @@ public class StorageHubManagementTest extends ContextTest {
for(Version version : versions){
logger.debug("Version {} {}", version.getId(), version.getName());
}
- secretManager.endSession();
}
@Test
public void getFileInfoViaDirectoryListing() throws Exception {
- SecretManager secretManager = SecretManagerProvider.instance.get();
- GCubeSecret gCubeSecret = new GCubeSecret(ContextTest.properties.getProperty(DEFAULT_TEST_SCOPE_NAME));
- secretManager.startSession(gCubeSecret);
StorageHubManagement storageHubManagement = new StorageHubManagement();
String id = "22bd9034-1da0-45ac-868f-91d1e5438344";
OpenResolver openResolver = storageHubManagement.storageHubClient.open(id);
@@ -145,7 +123,6 @@ public class StorageHubManagementTest extends ContextTest {
logger.debug("Version {} {}", version.getId(), version.getName());
}
}
- secretManager.endSession();
}
}