Switching gcat credentials to new IAM authz

This commit is contained in:
Luca Frosini 2022-01-28 17:37:33 +01:00
parent 5ac1039d60
commit fab1cb240a
4 changed files with 45 additions and 42 deletions

View File

@ -2,6 +2,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for gCube Catalogue (gCat) Service # Changelog for gCube Catalogue (gCat) Service
## [v2.2.0-SNAPSHOT]
- Switched gcat credentials to new IAM authz [#21628][#22727]
## [v2.1.0] ## [v2.1.0]
- Added query parameter social_post_notification to override default VRE behaviour [#21345] - Added query parameter social_post_notification to override default VRE behaviour [#21345]

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.data-catalogue</groupId> <groupId>org.gcube.data-catalogue</groupId>
<artifactId>gcat</artifactId> <artifactId>gcat</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>2.1.0</version> <version>2.2.0-SNAPSHOT</version>
<name>gCube Catalogue (gCat) Service</name> <name>gCube Catalogue (gCat) Service</name>
<description> <description>
This service allows any client to publish on the gCube Catalogue. This service allows any client to publish on the gCube Catalogue.

View File

@ -1,13 +1,9 @@
package org.gcube.gcat.utils; package org.gcube.gcat.utils;
import java.io.InputStream; import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.ws.rs.InternalServerErrorException; import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.WebApplicationException;
import org.gcube.common.authorization.utils.manager.SecretManager; import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.secret.Secret; import org.gcube.common.authorization.utils.secret.Secret;
@ -22,43 +18,44 @@ public class Constants {
public static final String CATALOGUE_NAME = "gCat"; public static final String CATALOGUE_NAME = "gCat";
private static final String PROPERTY_FILENAME = "config.properties";
/*
* Key : Context
* Value : Application Token
*/
protected static final Map<String,String> applicationTokens;
static { // private static final String PROPERTY_FILENAME = "config.properties";
try { // /*
applicationTokens = new HashMap<>(); // * Key : Context
Properties properties = new Properties(); // * Value : Application Token
InputStream input = Constants.class.getClassLoader().getResourceAsStream(PROPERTY_FILENAME); // */
// load a properties file // protected static final Map<String,String> applicationTokens;
properties.load(input); //
Enumeration<?> enumeration = properties.propertyNames(); // static {
while(enumeration.hasMoreElements()) { // try {
String context = (String) enumeration.nextElement(); // applicationTokens = new HashMap<>();
String applicationToken = properties.getProperty(context); // Properties properties = new Properties();
applicationTokens.put(context, applicationToken); // InputStream input = Constants.class.getClassLoader().getResourceAsStream(PROPERTY_FILENAME);
} // // load a properties file
} catch(Exception e) { // properties.load(input);
throw new WebApplicationException(e); // 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 final String CLIENT_SECRET_FILENAME = "config.properties";
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_ID = "gcat"; private static final String CLIENT_ID = "gcat";
protected static String clientSecret; protected static String clientSecret;
@ -88,7 +85,8 @@ public class Constants {
try { try {
return getJWTAccessToken(); return getJWTAccessToken();
}catch (Exception e) { }catch (Exception e) {
return getCatalogueApplicationToken(); throw e;
// return getCatalogueApplicationToken();
} }
} }

View File

@ -1,4 +1,5 @@
/*.gcubekey /*.gcubekey
/*.properties /*.properties
/*_zuliprc /*_zuliprc
/clientSecret /clientSecret
/config.properties.old-authz