Update changelog for version 5.0.0 and refactor context handling in code
This commit is contained in:
parent
c8eeec2a90
commit
db84e9e61f
|
|
@ -2,7 +2,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for Resource Registry Context Client
|
||||
|
||||
## [v4.2.0-SNAPSHOT]
|
||||
# [v5.0.0-SNAPSHOT]
|
||||
|
||||
- Upgraded to Java17 [#29533]
|
||||
- Migrated to Smartgears 4 [#29533]
|
||||
|
||||
|
||||
## [v4.2.0]
|
||||
|
||||
- Added support for paginated results [#24648]
|
||||
- Removed usage of shared context cache
|
||||
|
|
|
|||
52
pom.xml
52
pom.xml
|
|
@ -5,18 +5,41 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.2.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry-context-client</artifactId>
|
||||
<version>4.2.0-SNAPSHOT</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<name>Resource Registry Context Client</name>
|
||||
<description>Resource Registry Context Client is a library designed to interact with Resource Registry Context APIs</description>
|
||||
|
||||
<organization>
|
||||
<name>gCube System</name>
|
||||
<url>https://www.gcube-system.org/</url>
|
||||
</organization>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>luca.frosini</id>
|
||||
<name>Luca Frosini</name>
|
||||
<email>luca.frosini@isti.cnr.it</email>
|
||||
<url>https://www.isti.cnr.it/en/about/people-detail/141/Frosini_Luca</url>
|
||||
<organization>ISTI-CNR</organization>
|
||||
<organizationUrl>https://www.isti.cnr.it/</organizationUrl>
|
||||
<roles>
|
||||
<role>researcher</role>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
<timezone>Europe/Rome</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<serviceClass>InformationSystem</serviceClass>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
|
|
@ -30,7 +53,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>4.0.1-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
|
@ -46,6 +69,10 @@
|
|||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>information-system-model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>gxHTTP</artifactId>
|
||||
|
|
@ -56,6 +83,17 @@
|
|||
</dependency>
|
||||
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>d4science-iam-client</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.security</groupId>
|
||||
<artifactId>gcube-secrets</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
@ -67,11 +105,5 @@
|
|||
<artifactId>logback-classic</artifactId>
|
||||
<scope>test</scope>
|
||||
</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>
|
||||
</project>
|
||||
|
|
@ -9,10 +9,9 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.common.context.ContextUtility;
|
||||
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
import org.gcube.common.http.GXHTTPUtility;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
|
||||
|
|
@ -110,7 +109,7 @@ public class ResourceRegistryContextClientImpl extends BaseRequestInfo implement
|
|||
}
|
||||
|
||||
protected GXHTTPStringRequest getGXHTTPStringRequest() {
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||
gxHTTPStringRequest.from(this.getClass().getSimpleName());
|
||||
for(String name : headers.keySet()) {
|
||||
gxHTTPStringRequest.header(name, headers.get(name));
|
||||
|
|
@ -312,7 +311,7 @@ public class ResourceRegistryContextClientImpl extends BaseRequestInfo implement
|
|||
|
||||
@Override
|
||||
public Context readCurrentContext() throws ContextNotFoundException, ResourceRegistryException {
|
||||
String contextFullName = ContextUtility.getCurrentContextFullName();
|
||||
String contextFullName = SecretManagerProvider.get().getContext();
|
||||
UUID uuid = contextCache.getUUIDByFullName(contextFullName);
|
||||
return read(uuid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,11 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
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.KeycloakClientHelper;
|
||||
import org.gcube.common.keycloak.model.TokenResponse;
|
||||
import org.gcube.common.iam.D4ScienceIAMClient;
|
||||
import org.gcube.common.iam.D4ScienceIAMClientAuthn;
|
||||
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.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
|
@ -30,9 +27,9 @@ public class ContextTest {
|
|||
|
||||
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 PARENT_DEFAULT_TEST_CONTEXT;
|
||||
public static final String DEFAULT_TEST_CONTEXT;
|
||||
public static final String ALTERNATIVE_TEST_CONTEXT;
|
||||
|
||||
public static final String GCUBE;
|
||||
public static final String DEVNEXT;
|
||||
|
|
@ -57,21 +54,22 @@ public class ContextTest {
|
|||
DEVSEC = GCUBE + "/devsec";
|
||||
DEVVRE = DEVSEC + "/devVRE";
|
||||
|
||||
PARENT_DEFAULT_TEST_SCOPE = GCUBE;
|
||||
DEFAULT_TEST_SCOPE = DEVNEXT;
|
||||
ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
|
||||
PARENT_DEFAULT_TEST_CONTEXT = GCUBE;
|
||||
DEFAULT_TEST_CONTEXT = DEVSEC;
|
||||
ALTERNATIVE_TEST_CONTEXT = DEVVRE;
|
||||
|
||||
properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
|
||||
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
}
|
||||
|
||||
private enum Type{
|
||||
|
|
@ -79,34 +77,34 @@ public class ContextTest {
|
|||
};
|
||||
|
||||
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();
|
||||
SecretManagerProvider.reset();
|
||||
SecretManagerProvider.set(secret);
|
||||
}
|
||||
|
||||
public static void setContextByName(String fullContextName) throws Exception {
|
||||
logger.debug("Going to set credentials for context {}", fullContextName);
|
||||
Secret secret = getSecretByContextName(fullContextName);
|
||||
Secret secret = getSecret(fullContextName);
|
||||
// Secret secret = FakeSecretUtility.getSecret("is-manager.json", fullContextName);
|
||||
set(secret);
|
||||
}
|
||||
|
||||
|
||||
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
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:
|
||||
|
|
@ -114,34 +112,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());
|
||||
public static Secret getSecret(String context) throws Exception {
|
||||
String accessToken = getJWTAccessToken(context);
|
||||
Secret secret = new AccessTokenSecret(accessToken, context);
|
||||
return secret;
|
||||
}
|
||||
|
||||
|
|
@ -150,15 +134,10 @@ public class ContextTest {
|
|||
set(secret);
|
||||
}
|
||||
|
||||
private static Secret getSecret(String token) throws Exception {
|
||||
Secret secret = SecretUtility.getSecretByTokenString(token);
|
||||
return secret;
|
||||
}
|
||||
|
||||
public static String getUser() {
|
||||
String user = Metadata.UNKNOWN_USER;
|
||||
try {
|
||||
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
||||
user = SecretManagerProvider.get().getOwner().getId();
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to retrieve user. {} will be used", user);
|
||||
}
|
||||
|
|
@ -167,12 +146,12 @@ public class ContextTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
setContextByName(DEFAULT_TEST_SCOPE);
|
||||
setContextByName(DEFAULT_TEST_CONTEXT);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
SecretManagerProvider.instance.reset();
|
||||
SecretManagerProvider.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue