Migrating to smartgears 4
This commit is contained in:
parent
a3ed8a3d8d
commit
8da630591d
|
@ -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
|
||||
|
|
17
pom.xml
17
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.data-publishing</groupId>
|
||||
<artifactId>storagehub-application-persistence</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<name>StorageHub Application Persistence</name>
|
||||
<description>
|
||||
This library allows any application to persist in its workspace home any
|
||||
|
@ -37,7 +37,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -54,8 +54,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-utils</artifactId>
|
||||
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
|
||||
<artifactId>common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -75,5 +74,15 @@
|
|||
<artifactId>logback-classic</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>keycloak-client</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.security</groupId>
|
||||
<artifactId>gcube-secrets</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue