Removed ContextUtility class and started using authorization-utils lib
This commit is contained in:
parent
e1423021d9
commit
f845e52a5a
10
pom.xml
10
pom.xml
|
@ -52,6 +52,16 @@
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.data-catalogue</groupId>
|
||||||
|
<artifactId>gcat-api</artifactId>
|
||||||
|
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>authorization-utils</artifactId>
|
||||||
|
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.information-system</groupId>
|
<groupId>org.gcube.information-system</groupId>
|
||||||
<artifactId>information-system-model</artifactId>
|
<artifactId>information-system-model</artifactId>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.gcube.gcat.moderation.thread;
|
package org.gcube.gcat.moderation.thread;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.gcat.api.CMItemStatus;
|
import org.gcube.gcat.api.CMItemStatus;
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ public class FakeModerationThread extends ModerationThread {
|
||||||
@Override
|
@Override
|
||||||
public void postUserMessage(CMItemStatus cmItemStatus, String userMessage) throws Exception {
|
public void postUserMessage(CMItemStatus cmItemStatus, String userMessage) throws Exception {
|
||||||
logger.info("{} is sending a message to the {} for item '{}' (id={}). ItemStatus={}, Message=\"{}\"",
|
logger.info("{} is sending a message to the {} for item '{}' (id={}). ItemStatus={}, Message=\"{}\"",
|
||||||
ContextUtility.getUsername(), ModerationThread.class.getSimpleName(), itemName, itemID, cmItemStatus, userMessage);
|
SecretManager.instance.get().getUsername(),
|
||||||
|
ModerationThread.class.getSimpleName(), itemName, itemID, cmItemStatus, userMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,13 +7,13 @@ import javax.ws.rs.InternalServerErrorException;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.gcat.api.CMItemStatus;
|
import org.gcube.gcat.api.CMItemStatus;
|
||||||
import org.gcube.gcat.api.GCatConstants;
|
import org.gcube.gcat.api.GCatConstants;
|
||||||
import org.gcube.gcat.moderation.thread.ModerationThread;
|
import org.gcube.gcat.moderation.thread.ModerationThread;
|
||||||
import org.gcube.gcat.moderation.thread.zulip.ZulipResponse.Result;
|
import org.gcube.gcat.moderation.thread.zulip.ZulipResponse.Result;
|
||||||
import org.gcube.gcat.social.SocialUsers;
|
import org.gcube.gcat.social.SocialUsers;
|
||||||
import org.gcube.gcat.utils.Constants;
|
import org.gcube.gcat.utils.Constants;
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
|
||||||
import org.gcube.storagehub.ApplicationMode;
|
import org.gcube.storagehub.ApplicationMode;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -47,7 +47,7 @@ public class ZulipStream extends ModerationThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ZulipRestExecutor getZulipRestExecutor() {
|
protected ZulipRestExecutor getZulipRestExecutor() {
|
||||||
ZulipAuth zulipAuth = new ZulipAuth(ContextUtility.getUsername());
|
ZulipAuth zulipAuth = new ZulipAuth(SecretManager.instance.get().getUsername());
|
||||||
return new ZulipRestExecutor(zulipAuth.getEmail(), zulipAuth.getAPIKey(), zulipAuth.getSite());
|
return new ZulipRestExecutor(zulipAuth.getEmail(), zulipAuth.getAPIKey(), zulipAuth.getSite());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,13 @@ import java.util.Set;
|
||||||
import javax.ws.rs.InternalServerErrorException;
|
import javax.ws.rs.InternalServerErrorException;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||||
import org.gcube.common.resources.gcore.GenericResource;
|
import org.gcube.common.resources.gcore.GenericResource;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.gcube.resources.discovery.icclient.ICFactory;
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||||
|
@ -69,18 +69,19 @@ public class CKANInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CKANInstance getInstance() {
|
public static CKANInstance getInstance() {
|
||||||
CKANInstance ckanInstance = ckanInstancePerScope.get(ContextUtility.getCurrentContext());
|
String context = SecretManager.instance.get().getContext();
|
||||||
|
CKANInstance ckanInstance = ckanInstancePerScope.get(context);
|
||||||
if(ckanInstance == null) {
|
if(ckanInstance == null) {
|
||||||
ckanInstance = new CKANInstance();
|
ckanInstance = new CKANInstance();
|
||||||
ckanInstance.getConfigurationFromIS();
|
ckanInstance.getConfigurationFromIS();
|
||||||
ckanInstancePerScope.put(ContextUtility.getCurrentContext(), ckanInstance);
|
ckanInstancePerScope.put(context, ckanInstance);
|
||||||
}
|
}
|
||||||
return ckanInstance;
|
return ckanInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private CKANInstance() {
|
private CKANInstance() {
|
||||||
currentContext = ContextUtility.getCurrentContext();
|
currentContext = SecretManager.instance.get().getContext();
|
||||||
currentScopeBean = new ScopeBean(currentContext);
|
currentScopeBean = new ScopeBean(currentContext);
|
||||||
currentOrganizationName = CKANPackage.getOrganizationName(currentScopeBean);
|
currentOrganizationName = CKANPackage.getOrganizationName(currentScopeBean);
|
||||||
supportedOrganizations = getSupportedOrganizationsFromIS();
|
supportedOrganizations = getSupportedOrganizationsFromIS();
|
||||||
|
|
|
@ -2,8 +2,8 @@ package org.gcube.gcat.persistence.ckan;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public class CKANOrganization extends CKAN {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCKANOrganizationName() {
|
public static String getCKANOrganizationName() {
|
||||||
String context = ContextUtility.getCurrentContext();
|
String context = SecretManager.instance.get().getContext();
|
||||||
return getCKANOrganizationName(context);
|
return getCKANOrganizationName(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,17 +18,16 @@ import javax.ws.rs.WebApplicationException;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.tika.mime.MimeType;
|
import org.apache.tika.mime.MimeType;
|
||||||
import org.apache.tika.mime.MimeTypes;
|
import org.apache.tika.mime.MimeTypes;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||||
import org.gcube.gcat.utils.Constants;
|
import org.gcube.gcat.utils.Constants;
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
|
||||||
import org.gcube.gcat.utils.HTTPCall;
|
import org.gcube.gcat.utils.HTTPCall;
|
||||||
import org.gcube.gcat.workspace.CatalogueStorageHubManagement;
|
import org.gcube.gcat.workspace.CatalogueStorageHubManagement;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
|
@ -70,7 +69,7 @@ public class CKANResource extends CKAN {
|
||||||
public static final String URI_RESOLVER_STORAGE_HUB_PATH = "/shub/";
|
public static final String URI_RESOLVER_STORAGE_HUB_PATH = "/shub/";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String context = ContextUtility.getCurrentContext();
|
String context = SecretManager.instance.get().getContext();
|
||||||
if(context.startsWith("/gcube")) {
|
if(context.startsWith("/gcube")) {
|
||||||
URI_RESOLVER_STORAGE_HUB_HOST = URI_RESOLVER_STORAGE_HUB_HOST_DEV;
|
URI_RESOLVER_STORAGE_HUB_HOST = URI_RESOLVER_STORAGE_HUB_HOST_DEV;
|
||||||
} else if(context.startsWith("/pred4s")){
|
} else if(context.startsWith("/pred4s")){
|
||||||
|
|
|
@ -6,15 +6,14 @@ import javax.ws.rs.InternalServerErrorException;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.gcat.api.Role;
|
import org.gcube.gcat.api.Role;
|
||||||
import org.gcube.gcat.social.PortalUser;
|
import org.gcube.gcat.social.PortalUser;
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
|
||||||
import org.gcube.gcat.utils.RandomString;
|
import org.gcube.gcat.utils.RandomString;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
|
@ -193,7 +192,8 @@ public class CKANUser extends CKAN {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCKANUsername() {
|
public static String getCKANUsername() {
|
||||||
return getCKANUsername(ContextUtility.getUsername());
|
String username = SecretManager.instance.get().getUsername();
|
||||||
|
return getCKANUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String read() {
|
public String read() {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import javax.cache.expiry.CreatedExpiryPolicy;
|
||||||
import javax.cache.expiry.Duration;
|
import javax.cache.expiry.Duration;
|
||||||
import javax.cache.spi.CachingProvider;
|
import javax.cache.spi.CachingProvider;
|
||||||
|
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
|
|
||||||
public abstract class CKANUserCache {
|
public abstract class CKANUserCache {
|
||||||
|
|
||||||
|
@ -37,14 +37,14 @@ public abstract class CKANUserCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CKANUser getCurrrentCKANUser() {
|
public static CKANUser getCurrrentCKANUser() {
|
||||||
String context = ContextUtility.getCurrentContext();
|
String context = SecretManager.instance.get().getContext();
|
||||||
Cache<String,CKANUser> userCache = userCachePerContext.get(context);
|
Cache<String,CKANUser> userCache = userCachePerContext.get(context);
|
||||||
if(userCache == null) {
|
if(userCache == null) {
|
||||||
userCache = cacheManager.createCache(context, userCacheConfiguration);
|
userCache = cacheManager.createCache(context, userCacheConfiguration);
|
||||||
userCachePerContext.put(context, userCache);
|
userCachePerContext.put(context, userCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
String gcubeUsername = ContextUtility.getUsername();
|
String gcubeUsername = SecretManager.instance.get().getUsername();
|
||||||
CKANUser ckanUser = userCache.get(gcubeUsername);
|
CKANUser ckanUser = userCache.get(gcubeUsername);
|
||||||
if(ckanUser == null) {
|
if(ckanUser == null) {
|
||||||
ckanUser = new CKANUser();
|
ckanUser = new CKANUser();
|
||||||
|
|
|
@ -8,19 +8,18 @@ import java.util.List;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
|
||||||
import org.gcube.gcat.persistence.ckan.CKANInstance;
|
|
||||||
import org.gcube.gcat.persistence.ckan.CKANUserCache;
|
|
||||||
import org.gcube.gcat.utils.Constants;
|
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
|
||||||
import org.gcube.gcat.utils.HTTPUtility;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
|
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||||
|
import org.gcube.gcat.persistence.ckan.CKANInstance;
|
||||||
|
import org.gcube.gcat.persistence.ckan.CKANUserCache;
|
||||||
|
import org.gcube.gcat.utils.Constants;
|
||||||
|
import org.gcube.gcat.utils.HTTPUtility;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
@ -120,7 +119,7 @@ public class SocialPost extends Thread {
|
||||||
CKANInstance instance = CKANInstance.getInstance();
|
CKANInstance instance = CKANInstance.getInstance();
|
||||||
|
|
||||||
if(!instance.isSocialPostEnabled()) {
|
if(!instance.isSocialPostEnabled()) {
|
||||||
logger.info("Social Post are disabled in the context {}", ContextUtility.getCurrentContext());
|
logger.info("Social Post are disabled in the context {}", SecretManager.instance.get().getContext());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.info("Going to send Social Post about the Item {} available at {}", itemID, itemURL);
|
logger.info("Going to send Social Post about the Item {} available at {}", itemID, itemURL);
|
||||||
|
|
|
@ -7,8 +7,8 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -35,7 +35,7 @@ public class SocialService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SocialService getSocialService() throws Exception {
|
public static SocialService getSocialService() throws Exception {
|
||||||
String contex = ContextUtility.getCurrentContext();
|
String contex = SecretManager.instance.get().getContext();
|
||||||
SocialService socialService = socialServicePerContext.get(contex);
|
SocialService socialService = socialServicePerContext.get(contex);
|
||||||
if(socialService == null) {
|
if(socialService == null) {
|
||||||
socialService = new SocialService();
|
socialService = new SocialService();
|
||||||
|
@ -66,20 +66,20 @@ public class SocialService {
|
||||||
List<String> endpoints = client.submit(query);
|
List<String> endpoints = client.submit(query);
|
||||||
if(endpoints == null || endpoints.isEmpty()) {
|
if(endpoints == null || endpoints.isEmpty()) {
|
||||||
throw new Exception("Cannot retrieve the GCoreEndpoint SERVICE_NAME: " + SERVICE_NAME
|
throw new Exception("Cannot retrieve the GCoreEndpoint SERVICE_NAME: " + SERVICE_NAME
|
||||||
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + ContextUtility.getCurrentContext());
|
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + SecretManager.instance.get().getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.serviceBasePath = endpoints.get(0);
|
this.serviceBasePath = endpoints.get(0);
|
||||||
|
|
||||||
if(serviceBasePath == null)
|
if(serviceBasePath == null)
|
||||||
throw new Exception("Endpoint:" + RESOURCE + ", is null for SERVICE_NAME: " + SERVICE_NAME
|
throw new Exception("Endpoint:" + RESOURCE + ", is null for SERVICE_NAME: " + SERVICE_NAME
|
||||||
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + ContextUtility.getCurrentContext());
|
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + SecretManager.instance.get().getContext());
|
||||||
|
|
||||||
serviceBasePath = serviceBasePath.endsWith("/") ? serviceBasePath : serviceBasePath + "/";
|
serviceBasePath = serviceBasePath.endsWith("/") ? serviceBasePath : serviceBasePath + "/";
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
String error = "An error occurred during GCoreEndpoint discovery, SERVICE_NAME: " + SERVICE_NAME
|
String error = "An error occurred during GCoreEndpoint discovery, SERVICE_NAME: " + SERVICE_NAME
|
||||||
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + ContextUtility.getCurrentContext() + ".";
|
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + SecretManager.instance.get().getContext() + ".";
|
||||||
logger.error(error, e);
|
logger.error(error, e);
|
||||||
throw new Exception(error);
|
throw new Exception(error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Properties;
|
||||||
import javax.ws.rs.InternalServerErrorException;
|
import javax.ws.rs.InternalServerErrorException;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -46,11 +47,12 @@ public class Constants {
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String getCatalogueApplicationToken() {
|
public static String getCatalogueApplicationToken() {
|
||||||
|
String context = SecretManager.instance.get().getContext();
|
||||||
try {
|
try {
|
||||||
return applicationTokens.get(ContextUtility.getCurrentContext());
|
return applicationTokens.get(context);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new InternalServerErrorException(
|
throw new InternalServerErrorException(
|
||||||
"Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
|
"Unable to retrieve Application Token for context " + context, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,12 +72,12 @@ public class Constants {
|
||||||
return clientSecret;
|
return clientSecret;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new InternalServerErrorException(
|
throw new InternalServerErrorException(
|
||||||
"Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
|
"Unable to retrieve Application Token for context " + SecretManager.instance.get().getContext(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getJWTAccessToken() throws Exception {
|
public static String getJWTAccessToken() throws Exception {
|
||||||
String contextToAuthorise = ContextUtility.getCurrentContext();
|
String contextToAuthorise = SecretManager.instance.get().getContext();
|
||||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(CLIENT_ID, getClientSecret(contextToAuthorise), contextToAuthorise, null);
|
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(CLIENT_ID, getClientSecret(contextToAuthorise), contextToAuthorise, null);
|
||||||
return tr.getAccessToken();
|
return tr.getAccessToken();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
package org.gcube.gcat.utils;
|
|
||||||
|
|
||||||
import javax.ws.rs.InternalServerErrorException;
|
|
||||||
|
|
||||||
import org.gcube.common.authorization.client.Constants;
|
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
|
||||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
|
||||||
import org.gcube.common.authorization.library.ClientType;
|
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
|
||||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
|
||||||
*/
|
|
||||||
public class ContextUtility {
|
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ContextUtility.class);
|
|
||||||
|
|
||||||
public static void setContext(String token) throws ObjectNotFound, Exception {
|
|
||||||
SecurityTokenProvider.instance.set(token);
|
|
||||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
||||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
|
||||||
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
|
|
||||||
String qualifier = authorizationEntry.getQualifier();
|
|
||||||
Caller caller = new Caller(clientInfo, qualifier);
|
|
||||||
AuthorizationProvider.instance.set(caller);
|
|
||||||
ScopeProvider.instance.set(getCurrentContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getCurrentContext() {
|
|
||||||
try {
|
|
||||||
String token = SecurityTokenProvider.instance.get();
|
|
||||||
return Constants.authorizationService().get(token).getContext();
|
|
||||||
} catch(Exception e) {
|
|
||||||
String context = ScopeProvider.instance.get();
|
|
||||||
if(context != null) {
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
throw new InternalServerErrorException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ClientInfo getClientInfo() {
|
|
||||||
try {
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
|
||||||
if(caller != null) {
|
|
||||||
return caller.getClient();
|
|
||||||
} else {
|
|
||||||
String token = SecurityTokenProvider.instance.get();
|
|
||||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
||||||
return authorizationEntry.getClientInfo();
|
|
||||||
}
|
|
||||||
} catch(Exception e) {
|
|
||||||
throw new InternalServerErrorException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String GET_USERNAME_ERROR = "Unable to retrieve user";
|
|
||||||
|
|
||||||
public static String getUsername() {
|
|
||||||
try {
|
|
||||||
return getClientInfo().getId();
|
|
||||||
} catch(Exception e) {
|
|
||||||
logger.error(GET_USERNAME_ERROR);
|
|
||||||
throw new InternalServerErrorException(GET_USERNAME_ERROR, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isApplication() {
|
|
||||||
try {
|
|
||||||
ClientInfo clientInfo = getClientInfo();
|
|
||||||
return clientInfo.getType() == ClientType.EXTERNALSERVICE;
|
|
||||||
} catch(Exception e) {
|
|
||||||
throw new InternalServerErrorException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -11,6 +11,7 @@ import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||||
import org.gcube.gcat.persistence.ckan.CKANInstance;
|
import org.gcube.gcat.persistence.ckan.CKANInstance;
|
||||||
|
|
||||||
|
@ -47,7 +48,8 @@ public class URIResolver {
|
||||||
String uriResolverURL = CKANInstance.getInstance().getUriResolverURL();
|
String uriResolverURL = CKANInstance.getInstance().getUriResolverURL();
|
||||||
|
|
||||||
ObjectNode requestContent = mapper.createObjectNode();
|
ObjectNode requestContent = mapper.createObjectNode();
|
||||||
requestContent.put(CATALOGUE_CONTEXT, ContextUtility.getCurrentContext());
|
String context = SecretManager.instance.get().getContext();
|
||||||
|
requestContent.put(CATALOGUE_CONTEXT, context);
|
||||||
|
|
||||||
requestContent.put(ENTITY_TYPE, DATASET);
|
requestContent.put(ENTITY_TYPE, DATASET);
|
||||||
requestContent.put(ENTITY_NAME, name);
|
requestContent.put(ENTITY_NAME, name);
|
||||||
|
|
|
@ -18,15 +18,19 @@ import javax.ws.rs.core.PathSegment;
|
||||||
import javax.ws.rs.core.UriBuilder;
|
import javax.ws.rs.core.UriBuilder;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.resources.gcore.GenericResource;
|
import org.gcube.common.resources.gcore.GenericResource;
|
||||||
import org.gcube.common.resources.gcore.Resources;
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
import org.gcube.gcat.ContextTest;
|
import org.gcube.gcat.ContextTest;
|
||||||
import org.gcube.gcat.api.CMItemStatus;
|
import org.gcube.gcat.api.CMItemStatus;
|
||||||
import org.gcube.gcat.api.GCatConstants;
|
import org.gcube.gcat.api.GCatConstants;
|
||||||
import org.gcube.gcat.utils.ContextUtility;
|
|
||||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -34,11 +38,6 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
|
@ -70,25 +69,21 @@ public class CKANPackageTest extends ContextTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI resolve(URI uri) {
|
public URI resolve(URI uri) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI relativize(URI uri) {
|
public URI relativize(URI uri) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UriBuilder getRequestUriBuilder() {
|
public UriBuilder getRequestUriBuilder() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI getRequestUri() {
|
public URI getRequestUri() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,79 +101,66 @@ public class CKANPackageTest extends ContextTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PathSegment> getPathSegments(boolean decode) {
|
public List<PathSegment> getPathSegments(boolean decode) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PathSegment> getPathSegments() {
|
public List<PathSegment> getPathSegments() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultivaluedMap<String, String> getPathParameters(boolean decode) {
|
public MultivaluedMap<String, String> getPathParameters(boolean decode) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultivaluedMap<String, String> getPathParameters() {
|
public MultivaluedMap<String, String> getPathParameters() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPath(boolean decode) {
|
public String getPath(boolean decode) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getMatchedURIs(boolean decode) {
|
public List<String> getMatchedURIs(boolean decode) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getMatchedURIs() {
|
public List<String> getMatchedURIs() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Object> getMatchedResources() {
|
public List<Object> getMatchedResources() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UriBuilder getBaseUriBuilder() {
|
public UriBuilder getBaseUriBuilder() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI getBaseUri() {
|
public URI getBaseUri() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UriBuilder getAbsolutePathBuilder() {
|
public UriBuilder getAbsolutePathBuilder() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI getAbsolutePath() {
|
public URI getAbsolutePath() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -405,8 +387,7 @@ public class CKANPackageTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CKANPackage createPackage(ObjectMapper mapper) throws Exception {
|
protected CKANPackage createPackage(ObjectMapper mapper) throws Exception {
|
||||||
|
String currentContext = SecretManager.instance.get().getContext();
|
||||||
String currentContext = ContextUtility.getCurrentContext();
|
|
||||||
ScopeBean scopeBean = new ScopeBean(currentContext);
|
ScopeBean scopeBean = new ScopeBean(currentContext);
|
||||||
String ckanOrganizationName = CKANPackage.getOrganizationName(scopeBean);
|
String ckanOrganizationName = CKANPackage.getOrganizationName(scopeBean);
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,15 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.gcube.gcat.ContextTest;
|
import org.gcube.gcat.ContextTest;
|
||||||
import org.gcube.gcat.utils.Constants;
|
|
||||||
import org.gcube.storagehub.ApplicationMode;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
|
|
||||||
public class CKANResourceTest extends ContextTest {
|
public class CKANResourceTest extends ContextTest {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CKANResourceTest.class);
|
private static final Logger logger = LoggerFactory.getLogger(CKANResourceTest.class);
|
||||||
|
@ -39,13 +36,6 @@ public class CKANResourceTest extends ContextTest {
|
||||||
* https://goo.gl/78ViuR
|
* https://goo.gl/78ViuR
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test
|
|
||||||
public void test() throws Exception {
|
|
||||||
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
|
|
||||||
applicationMode.start();
|
|
||||||
//
|
|
||||||
applicationMode.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.gcat.utils;
|
package org.gcube.gcat.utils;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.gcat.ContextTest;
|
import org.gcube.gcat.ContextTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -11,7 +12,7 @@ public class ConstantsTest extends ContextTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetApplicationToken() {
|
public void testGetApplicationToken() {
|
||||||
logger.debug("Application token for Context {} is {}", ContextUtility.getCurrentContext(),
|
logger.debug("Application token for Context {} is {}", SecretManager.instance.get().getContext(),
|
||||||
Constants.getCatalogueApplicationToken());
|
Constants.getCatalogueApplicationToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue