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
## [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]

View File

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

View File

@ -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<String,String> 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<String,String> 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();
}
}

View File

@ -2,3 +2,4 @@
/*.properties
/*_zuliprc
/clientSecret
/config.properties.old-authz