Porting library to SG4
This commit is contained in:
parent
18b77a179a
commit
deabc4a4fc
|
@ -2,6 +2,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
|
|
||||||
# Changelog for Resource Registry API
|
# Changelog for Resource Registry API
|
||||||
|
|
||||||
|
# [v6.0.0-SNAPSHOT]
|
||||||
|
|
||||||
|
- Migrating code to comply with Smartgears 4
|
||||||
|
|
||||||
|
|
||||||
# [v5.1.0-SNAPSHOT]
|
# [v5.1.0-SNAPSHOT]
|
||||||
|
|
||||||
- Added Contexts as Teee in ContextCache [#24555]
|
- Added Contexts as Teee in ContextCache [#24555]
|
||||||
|
|
18
pom.xml
18
pom.xml
|
@ -5,12 +5,12 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.gcube.tools</groupId>
|
<groupId>org.gcube.tools</groupId>
|
||||||
<artifactId>maven-parent</artifactId>
|
<artifactId>maven-parent</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.2.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>org.gcube.information-system</groupId>
|
<groupId>org.gcube.information-system</groupId>
|
||||||
<artifactId>resource-registry-api</artifactId>
|
<artifactId>resource-registry-api</artifactId>
|
||||||
<version>5.1.0-SNAPSHOT</version>
|
<version>6.0.0-SNAPSHOT</version>
|
||||||
<name>Resource Registry API</name>
|
<name>Resource Registry API</name>
|
||||||
<description>Resource Registry API is a library containing classes shared across resource-registry-* components</description>
|
<description>Resource Registry API is a library containing classes shared across resource-registry-* components</description>
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.distribution</groupId>
|
<groupId>org.gcube.distribution</groupId>
|
||||||
<artifactId>gcube-bom</artifactId>
|
<artifactId>gcube-bom</artifactId>
|
||||||
<version>2.4.0</version>
|
<version>3.0.1-SNAPSHOT</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -44,7 +44,11 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>common-utility-sg3</artifactId>
|
<artifactId>common-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common.security</groupId>
|
||||||
|
<artifactId>gcube-secrets</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
|
@ -62,11 +66,5 @@
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.common</groupId>
|
|
||||||
<artifactId>authorization-utils</artifactId>
|
|
||||||
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -1,6 +1,6 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.api.rest;
|
package org.gcube.informationsystem.resourceregistry.api.rest;
|
||||||
|
|
||||||
import org.gcube.common.context.ContextUtility;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
@ -12,7 +12,7 @@ public abstract class ServiceInstance {
|
||||||
public static final String BASE_URL = "https://url.d4science.org";
|
public static final String BASE_URL = "https://url.d4science.org";
|
||||||
|
|
||||||
public static String getServiceURL() {
|
public static String getServiceURL() {
|
||||||
String context = ContextUtility.getCurrentContextFullName();
|
String context = SecretManagerProvider.get().getContext();
|
||||||
return getServiceURL(context);
|
return getServiceURL(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,11 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
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.KeycloakClientFactory;
|
||||||
import org.gcube.common.keycloak.model.TokenResponse;
|
import org.gcube.common.keycloak.model.TokenResponse;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||||
|
import org.gcube.common.security.secrets.AccessTokenSecret;
|
||||||
|
import org.gcube.common.security.secrets.Secret;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -24,7 +21,6 @@ import org.slf4j.LoggerFactory;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class ContextTest {
|
public class ContextTest {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||||
|
@ -76,11 +72,8 @@ public class ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void set(Secret secret) throws Exception {
|
public static void set(Secret secret) throws Exception {
|
||||||
SecretManagerProvider.instance.reset();
|
SecretManagerProvider.reset();
|
||||||
SecretManager secretManager = new SecretManager();
|
SecretManagerProvider.set(secret);
|
||||||
secretManager.addSecret(secret);
|
|
||||||
SecretManagerProvider.instance.set(secretManager);
|
|
||||||
SecretManagerProvider.instance.get().set();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setContextByName(String fullContextName) throws Exception {
|
public static void setContextByName(String fullContextName) throws Exception {
|
||||||
|
@ -88,33 +81,21 @@ public class ContextTest {
|
||||||
set(secret);
|
set(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
||||||
ScopeProvider.instance.set(context);
|
|
||||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
|
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Secret getSecretByContextName(String context) throws Exception {
|
public static Secret getSecretByContextName(String context) throws Exception {
|
||||||
TokenResponse tr = getJWTAccessToken(context);
|
TokenResponse tr = getJWTAccessToken(context);
|
||||||
Secret secret = new JWTSecret(tr.getAccessToken());
|
Secret secret = new AccessTokenSecret(tr.getAccessToken(), context);
|
||||||
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;
|
return secret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUser() {
|
public static String getUser() {
|
||||||
String user = Metadata.UNKNOWN_USER;
|
String user = Metadata.UNKNOWN_USER;
|
||||||
try {
|
try {
|
||||||
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
user = SecretManagerProvider.get().getOwner().getId();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Unable to retrieve user. {} will be used", user);
|
logger.error("Unable to retrieve user. {} will be used", user);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +109,7 @@ public class ContextTest {
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClass() throws Exception {
|
public static void afterClass() throws Exception {
|
||||||
SecretManagerProvider.instance.reset();
|
SecretManagerProvider.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue