From fab1cb240a6c4b5d9b7f8caed493254b497d61f1 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 28 Jan 2022 17:37:33 +0100 Subject: [PATCH] Switching gcat credentials to new IAM authz --- CHANGELOG.md | 4 + pom.xml | 2 +- .../java/org/gcube/gcat/utils/Constants.java | 78 +++++++++---------- src/test/resources/.gitignore | 3 +- 4 files changed, 45 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e02368..247e474 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 gCube Catalogue (gCat) Service +## [v2.2.0-SNAPSHOT] + +- Switched gcat credentials to new IAM authz [#21628][#22727] + ## [v2.1.0] - Added query parameter social_post_notification to override default VRE behaviour [#21345] diff --git a/pom.xml b/pom.xml index 53612b8..8d07c60 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.data-catalogue gcat war - 2.1.0 + 2.2.0-SNAPSHOT gCube Catalogue (gCat) Service This service allows any client to publish on the gCube Catalogue. diff --git a/src/main/java/org/gcube/gcat/utils/Constants.java b/src/main/java/org/gcube/gcat/utils/Constants.java index 507a3fa..94342ce 100644 --- a/src/main/java/org/gcube/gcat/utils/Constants.java +++ b/src/main/java/org/gcube/gcat/utils/Constants.java @@ -1,13 +1,9 @@ package org.gcube.gcat.utils; import java.io.InputStream; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; import java.util.Properties; import javax.ws.rs.InternalServerErrorException; -import javax.ws.rs.WebApplicationException; import org.gcube.common.authorization.utils.manager.SecretManager; import org.gcube.common.authorization.utils.secret.Secret; @@ -22,43 +18,44 @@ public class Constants { public static final String CATALOGUE_NAME = "gCat"; - private static final String PROPERTY_FILENAME = "config.properties"; - /* - * Key : Context - * Value : Application Token - */ - protected static final Map applicationTokens; - static { - try { - applicationTokens = new HashMap<>(); - Properties properties = new Properties(); - InputStream input = Constants.class.getClassLoader().getResourceAsStream(PROPERTY_FILENAME); - // load a properties file - properties.load(input); - Enumeration enumeration = properties.propertyNames(); - while(enumeration.hasMoreElements()) { - String context = (String) enumeration.nextElement(); - String applicationToken = properties.getProperty(context); - applicationTokens.put(context, applicationToken); - } - } catch(Exception e) { - throw new WebApplicationException(e); - } - } +// private static final String PROPERTY_FILENAME = "config.properties"; +// /* +// * Key : Context +// * Value : Application Token +// */ +// protected static final Map applicationTokens; +// +// static { +// try { +// applicationTokens = new HashMap<>(); +// Properties properties = new Properties(); +// InputStream input = Constants.class.getClassLoader().getResourceAsStream(PROPERTY_FILENAME); +// // load a properties file +// properties.load(input); +// Enumeration enumeration = properties.propertyNames(); +// while(enumeration.hasMoreElements()) { +// String context = (String) enumeration.nextElement(); +// String applicationToken = properties.getProperty(context); +// applicationTokens.put(context, applicationToken); +// } +// } catch(Exception e) { +// throw new WebApplicationException(e); +// } +// } +// +// @Deprecated +// private static String getCatalogueApplicationToken() { +// String context = SecretManager.instance.get().getContext(); +// try { +// return applicationTokens.get(context); +// } catch(Exception e) { +// throw new InternalServerErrorException( +// "Unable to retrieve Application Token for context " + context, e); +// } +// } - @Deprecated - private static String getCatalogueApplicationToken() { - String context = SecretManager.instance.get().getContext(); - try { - return applicationTokens.get(context); - } catch(Exception e) { - throw new InternalServerErrorException( - "Unable to retrieve Application Token for context " + context, e); - } - } - - private static final String CLIENT_SECRET_FILENAME = "clientSecret"; + private static final String CLIENT_SECRET_FILENAME = "config.properties"; private static final String CLIENT_ID = "gcat"; protected static String clientSecret; @@ -88,7 +85,8 @@ public class Constants { try { return getJWTAccessToken(); }catch (Exception e) { - return getCatalogueApplicationToken(); + throw e; +// return getCatalogueApplicationToken(); } } diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore index 94a4d23..4c654e4 100644 --- a/src/test/resources/.gitignore +++ b/src/test/resources/.gitignore @@ -1,4 +1,5 @@ /*.gcubekey /*.properties /*_zuliprc -/clientSecret \ No newline at end of file +/clientSecret +/config.properties.old-authz