diff --git a/pom.xml b/pom.xml index 7d9b7dc..93481d6 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ org.gcube.distribution maven-portal-bom - 3.7.0-SNAPSHOT + 3.8.0-SNAPSHOT pom import @@ -98,22 +98,22 @@ org.gcube.information-system information-system-model - [5.0.0-SNAPSHOT,6.0.0-SNAPSHOT) + [7.0.0-SNAPSHOT,8.0.0-SNAPSHOT) org.gcube.resource-management gcube-model - [4.0.0-SNAPSHOT,5.0.0-SNAPSHOT) + [5.0.0-SNAPSHOT,6.0.0-SNAPSHOT) org.gcube.information-system resource-registry-api - [4.1.0,5.0.0-SNAPSHOT) + [5.0.0-SNAPSHOT,6.0.0-SNAPSHOT) org.gcube.information-system resource-registry-client - [4.1.0,5.0.0-SNAPSHOT) + [4.4.0-SNAPSHOT,5.0.0-SNAPSHOT) diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxy.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxy.java index 09f7482..e670ff0 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxy.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/remote/ServiceProxy.java @@ -56,8 +56,9 @@ public interface ServiceProxy extends RemoteService { /** * @return the list of all available scopes. + * @throws Exception */ - List getAvailableScopes(); + List getAvailableScopes() throws Exception; List getAvailableAddScopes(); diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Callbacks.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Callbacks.java index aa8eabe..456cc35 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Callbacks.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/client/utils/Callbacks.java @@ -93,8 +93,8 @@ public class Callbacks { } public void onFailure(final Throwable caught) { Commands.unmask(UIIdentifiers.MAIN_CONTAINER_VIEWPORT_ID); - MessageBox.info("Failure", "cannot retrieve the scopes", null); - GWT.log("cannot retrieve the scopes", caught); + MessageBox.info("Error", "Cannot retrieve the available contexts", null); + GWT.log("Cannot retrieve the available contexts:", caught); } }; diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java index 2144f7f..51fb751 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java @@ -10,9 +10,12 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; +import javax.servlet.ServletContext; + import org.gcube.common.authorization.library.provider.AccessTokenProvider; import org.gcube.common.keycloak.KeycloakClient; import org.gcube.common.keycloak.KeycloakClientFactory; @@ -37,39 +40,69 @@ import org.slf4j.LoggerFactory; */ public class RegistryClientRequester { + private static final String CLIENT_PROPERTIES = "/WEB-INF/client.properties"; + + private static final String ENDPOINT = "endpoint"; + private static final String CLIENT_ID = "clientID"; + private static final String SECRET = "secret"; + private static final String ROOT_SCOPE = "rootScope"; + + private static final boolean IncludeContextInHeader = true; + private static Logger logger = LoggerFactory.getLogger(RegistryClientRequester.class); private static ResourceRegistryClient resourceRegistryClient; private static KeycloakClient client = KeycloakClientFactory.newInstance(); - private static final String endpoint = "https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token"; - private static final String clientID = "resource-registry-portlet-expieve"; - private static final String secret = "179bd3bc-5cc4-11ec-bf63-0242ac130001"; + // private static final String endpoint = + // "https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token"; + // private static final String clientID = + // "resource-registry-portlet-expieve"; + // private static final String secret = + // "179bd3bc-5cc4-11ec-bf63-0242ac130001"; + // private static final String rootScope = "/gcube"; - private static final String rootScope = "/gcube"; - - public static final Set getAvailableContexts() throws Exception { + public static final Set getAvailableContexts(ServletContext servletContext) throws Exception { + Properties clientProperties=getClientProperties(servletContext); + String rootScope=clientProperties.getProperty(ROOT_SCOPE); + logger.info("GetAvailableContexts: [Scope: {}]", rootScope); Set contextList = new HashSet(); ScopeProvider.instance.set(rootScope); - AccessTokenProvider.instance.set(getTokenForContext(rootScope)); + AccessTokenProvider.instance.set(getTokenForContext(rootScope,clientProperties)); + try { resourceRegistryClient = ResourceRegistryClientFactory.create(); - + //resourceRegistryClient.setIncludeContextsInHeader(IncludeContextInHeader); + + ContextCache contextCache = ContextCache.getInstance(); contextList = contextCache.getContextFullNameToUUIDAssociation().keySet(); } catch (Exception e) { - return Collections.emptySet(); + logger.error("Error retrieving available contexts: {}",e.getLocalizedMessage(),e); + throw new Exception("Error retrieving available contexts: "+e.getLocalizedMessage(),e); } finally { AccessTokenProvider.instance.reset(); ScopeProvider.instance.reset(); } + logger.info("Available contexts: {}",contextList); return contextList; } - private static String getTokenForContext(String context) { + private static Properties getClientProperties(ServletContext servletContext) throws Exception { + Properties properties = new Properties(); + properties.load(servletContext.getResourceAsStream(CLIENT_PROPERTIES)); + return properties; + } + + private static String getTokenForContext(String context, Properties clientProperties) { + logger.info("GetTokenForContext: {}",context); + String endpoint=clientProperties.getProperty(ENDPOINT); + String clientID=clientProperties.getProperty(CLIENT_ID); + String secret=clientProperties.getProperty(SECRET); + try { TokenResponse response = client.queryUMAToken(new URL(endpoint), clientID, secret, context, null); return response.getAccessToken(); @@ -89,13 +122,14 @@ public class RegistryClientRequester { */ // list a resource with a sub category - public static final HashMap> getResourcesTree(String scope) throws Exception { - + public static final HashMap> getResourcesTree(ServletContext servletContext,String scope) throws Exception { + logger.info("GetResourcesTree: [Scope: {}]", scope); + Properties clientProperties=getClientProperties(servletContext); HashMap> retval = new HashMap>(); ScopeProvider.instance.set(scope); - AccessTokenProvider.instance.set(getTokenForContext(scope)); + AccessTokenProvider.instance.set(getTokenForContext(scope,clientProperties)); try { - logger.info("GetResourcesTree: [Scope: {}]", scope); + resourceRegistryClient = ResourceRegistryClientFactory.create(); List types = resourceRegistryClient.getType(Resource.class, true); @@ -200,16 +234,19 @@ public class RegistryClientRequester { } // list string (xml formatted) for table - public static final List getResourcesByTypeSubType(String scope, String type, String subType) + public static final List getResourcesByTypeSubType(ServletContext servletContext,String scope, String type, String subType) throws Exception { - + logger.info("GetResourcesByTypeSubType: [Scope: {}]", scope); + Properties clientProperties=getClientProperties(servletContext); // CacheList.resourceid.clear(); ScopeProvider.instance.set(scope); - AccessTokenProvider.instance.set(getTokenForContext(scope)); + AccessTokenProvider.instance.set(getTokenForContext(scope,clientProperties)); try { - logger.info("GetResourcesByTypeSubType: [Scope: {}, Type: {}, SubType: {}]",new String[]{ scope, type, subType }); + logger.info("GetResourcesByTypeSubType: [Scope: {}, Type: {}, SubType: {}]", + new String[] { scope, type, subType }); resourceRegistryClient = ResourceRegistryClientFactory.create(); + // resourceRegistryClient.setIncludeContextsInHeader(IncludeContextInHeader); List resources = new ArrayList(); switch (type) { @@ -287,7 +324,7 @@ public class RegistryClientRequester { public static CompleteResourceProfile getResourceByID(String xml2htmlMapping, String scope, String type, String resID) { - + logger.info("GetResourceByID: [Scope: {}]", scope); String representation = CacheList.resourceid.get(resID).getBody(); // get resource by id String title = CacheList.resourceid.get(resID).getTitle(); diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java index d58b610..39e39e6 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java @@ -114,6 +114,7 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro private HttpSession getHttpSession() { return this.getThreadLocalRequest().getSession(); + } public final void initScopes(final boolean doClean) { @@ -258,25 +259,24 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro } } - public final List getAvailableScopes() { + public final List getAvailableScopes() throws Exception { ServerConsole.trace(LOG_PREFIX, "[GET-SCOPES] getting available scopes"); Vector retval = new Vector(); try { - retval.addAll(RegistryClientRequester.getAvailableContexts()); + retval.addAll(RegistryClientRequester.getAvailableContexts(this.getServletContext())); } catch (Exception e) { - retval.add("/gcube"); - retval.add("/gcube/devsec"); - e.printStackTrace(); + logger.error("Error retrieving available contexts: {}",e.getLocalizedMessage(),e); + throw new Exception("Error retrieving available contexts: "+e.getLocalizedMessage(),e); } - return retval; } public final List getAvailableAddScopes() { + this.getServletContext(); List retval = new Vector(); try { - retval.addAll(RegistryClientRequester.getAvailableContexts()); + retval.addAll(RegistryClientRequester.getAvailableContexts(this.getServletContext())); } catch (Exception e) { ServerConsole.error(LOG_PREFIX, e); } @@ -287,7 +287,7 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro public final HashMap> getResourceTypeTree(final String scope) throws Exception { try { - HashMap> results = RegistryClientRequester.getResourcesTree(scope); + HashMap> results = RegistryClientRequester.getResourcesTree(this.getServletContext(),scope); logger.info("get result type tree: ("+results.size()+") /n" + results.keySet() ); @@ -306,7 +306,7 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro { try { logger.info("---------------->getResourcesByType: [Scope: {}, type: {}]",scope,type); - List request=RegistryClientRequester.getResourcesByTypeSubType(scope, type,null); + List request=RegistryClientRequester.getResourcesByTypeSubType(this.getServletContext(),scope, type,null); return request; } catch (Exception e) { @@ -410,7 +410,7 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro //List request=ISClientRequester.getResourcesByType(getCacheManager(this.getCurrentStatus()), new ScopeBean(scope), type, subType); //New code - List request=RegistryClientRequester.getResourcesByTypeSubType(scope, type,subType); + List request=RegistryClientRequester.getResourcesByTypeSubType(this.getServletContext(),scope, type,subType); return request; diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java index 1d8a0ae..28541e9 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java @@ -13,7 +13,7 @@ import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; -import org.gcube.informationsystem.utils.ElementMapper; +import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.ContactFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet; @@ -108,16 +108,16 @@ public class UtilityResource { if (f instanceof IdentifierFacet) { logger.info("------------ConfigurationTemplate--IdentifierFacet"); IdentifierFacet sf = (IdentifierFacet) f; - if (!list.contains(sf.getType().toString())) - list.add(sf.getType().toString()); + if (!list.contains(sf.getIdentificationType().toString())) + list.add(sf.getIdentificationType().toString()); } break; case "Configuration": if (f instanceof SoftwareFacet) { logger.info("------------Configuration--IdentifierFacet"); IdentifierFacet sf = (IdentifierFacet) f; - if (!list.contains(sf.getType().toString())) { - list.add(sf.getType().toString()); + if (!list.contains(sf.getIdentificationType().toString())) { + list.add(sf.getIdentificationType().toString()); } } break; @@ -126,8 +126,8 @@ public class UtilityResource { if (f instanceof IdentifierFacet) { logger.info("------------Dataset--IdentifierFacet"); IdentifierFacet sf = (IdentifierFacet) f; - if (!list.contains(sf.getType().toString())) { - list.add(sf.getType().toString()); + if (!list.contains(sf.getIdentificationType().toString())) { + list.add(sf.getIdentificationType().toString()); } } break; @@ -135,8 +135,8 @@ public class UtilityResource { if (f instanceof IdentifierFacet) { logger.info("------------ConcreteDataset--IdentifierFacet"); IdentifierFacet sf = (IdentifierFacet) f; - if (!list.contains(sf.getType().toString())) { - list.add(sf.getType().toString()); + if (!list.contains(sf.getIdentificationType().toString())) { + list.add(sf.getIdentificationType().toString()); } } break; @@ -191,8 +191,8 @@ public class UtilityResource { if (f instanceof IdentifierFacet) { logger.info("------------Site--IdentifierFacet"); IdentifierFacet sf = (IdentifierFacet) f; - if (!list.contains(sf.getType().toString())) - list.add(sf.getType().toString()); + if (!list.contains(sf.getIdentificationType().toString())) + list.add(sf.getIdentificationType().toString()); } break; @@ -351,7 +351,7 @@ public class UtilityResource { } for (Actor actor : actors) { - id = actor.getHeader().getUUID().toString(); + id = actor.getID().toString(); List facets = actor.getIdentificationFacets(); for (Facet f : facets) { @@ -408,7 +408,7 @@ public class UtilityResource { } for (LegalBody actor : legalBodys) { - id = actor.getHeader().getUUID().toString(); + id = actor.getID().toString(); List facets = actor.getIdentificationFacets(); for (Facet f : facets) { @@ -465,7 +465,7 @@ public class UtilityResource { } for (Person person : persons) { - id = person.getHeader().getUUID().toString(); + id = person.getID().toString(); List facets = person.getIdentificationFacets(); for (Facet f : facets) { @@ -530,14 +530,14 @@ public class UtilityResource { } for (ConfigurationTemplate configurationTemplate : configurationTemplates) { - id = configurationTemplate.getHeader().getUUID().toString(); + id = configurationTemplate.getID().toString(); List facets = configurationTemplate.getIdentificationFacets(); for (Facet f : facets) { if (f instanceof IdentifierFacet) { IdentifierFacet sf = (IdentifierFacet) f; name = sf.getValue(); - description = sf.getType().toString(); - subType = sf.getType().toString(); + description = sf.getIdentificationType().toString(); + subType = sf.getIdentificationType().toString(); } } @@ -594,14 +594,14 @@ public class UtilityResource { return resource; } for (Configuration configuration : configurations) { - id = configuration.getHeader().getUUID().toString(); + id = configuration.getID().toString(); List facets = configuration.getIdentificationFacets(); for (Facet f : facets) { if (f instanceof IdentifierFacet) { IdentifierFacet sf = (IdentifierFacet) f; name = sf.getValue(); - subType = sf.getType().toString(); - description = sf.getType().toString(); + subType = sf.getIdentificationType().toString(); + description = sf.getIdentificationType().toString(); } } @@ -650,7 +650,7 @@ public class UtilityResource { } for (Dataset dataset : datasets) { - id = dataset.getHeader().getUUID().toString(); + id = dataset.getID().toString(); List facets = dataset.getIdentificationFacets(); for (Facet f : facets) { @@ -659,8 +659,8 @@ public class UtilityResource { // version = sf.getVersion(); serviceName = sf.getValue(); - serviceClass = sf.getType().toString(); - subType = sf.getType().toString(); + serviceClass = sf.getIdentificationType().toString(); + subType = sf.getIdentificationType().toString(); } } CacheList.resourceid.put(id, new ResourceObject(serviceName, dataset.toString())); @@ -707,7 +707,7 @@ public class UtilityResource { } for (ConcreteDataset concreteDataset : concretedatasets) { - id = concreteDataset.getHeader().getUUID().toString(); + id = concreteDataset.getID().toString(); List facets = concreteDataset.getIdentificationFacets(); for (Facet f : facets) { @@ -716,8 +716,8 @@ public class UtilityResource { // version = sf.getVersion(); serviceName = sf.getValue(); - serviceClass = sf.getType().toString(); - subType = sf.getType().toString(); + serviceClass = sf.getIdentificationType().toString(); + subType = sf.getIdentificationType().toString(); } } CacheList.resourceid.put(id, new ResourceObject(serviceName, concreteDataset.toString())); @@ -765,7 +765,7 @@ public class UtilityResource { } for (Schema schema : schemas) { - id = schema.getHeader().getUUID().toString(); + id = schema.getID().toString(); List facets = schema.getIdentificationFacets(); for (Facet f : facets) { @@ -827,7 +827,7 @@ public class UtilityResource { List eservices = (List) resourceRegistryClient.getInstances(EService.class, false); for (EService et : eservices) { - id = et.getHeader().getUUID().toString(); + id = et.getID().toString(); List facets = et.getIdentificationFacets(); for (Facet f : facets) { if (f instanceof SoftwareFacet) { @@ -905,7 +905,7 @@ public class UtilityResource { } for (RunningPlugin runningPlugin : runningPlugins) { - id = runningPlugin.getHeader().getUUID().toString(); + id = runningPlugin.getID().toString(); List facets = runningPlugin.getIdentificationFacets(); for (Facet f : facets) { @@ -973,10 +973,11 @@ public class UtilityResource { String gcfVersion = ""; String ghnVersion = ""; + resourceRegistryClient.setIncludeMeta(true); List ehosting = (List) resourceRegistryClient.getInstances(HostingNode.class, false); for (HostingNode eh : ehosting) { - id = eh.getHeader().getUUID().toString(); - lastUpdate = eh.getHeader().getLastUpdateTime().toString(); + id = eh.getID().toString(); + lastUpdate = eh.getMetadata().getLastUpdateTime().toString(); List facets = eh.getIdentificationFacets(); for (Facet f : facets) { if (f instanceof NetworkingFacet) { @@ -1081,7 +1082,7 @@ public class UtilityResource { return resource; } for (VirtualService vs : virtualServices) { - id = vs.getHeader().getUUID().toString(); + id = vs.getID().toString(); List facets = vs.getIdentificationFacets(); for (Facet f : facets) { @@ -1138,7 +1139,7 @@ public class UtilityResource { } for (Site site : sites) { - id = site.getHeader().getUUID().toString(); + id = site.getID().toString(); List facets = site.getIdentificationFacets(); for (Facet f : facets) { @@ -1147,8 +1148,8 @@ public class UtilityResource { // version = sf.getVersion(); serviceName = sf.getValue(); - serviceClass = sf.getType().toString(); - subType = sf.getType().toString(); + serviceClass = sf.getIdentificationType().toString(); + subType = sf.getIdentificationType().toString(); } } CacheList.resourceid.put(id, new ResourceObject(serviceName, site.toString())); @@ -1196,7 +1197,7 @@ public class UtilityResource { } for (Software software : softwares) { - id = software.getHeader().getUUID().toString(); + id = software.getID().toString(); List facets = software.getIdentificationFacets(); for (Facet f : facets) { @@ -1253,7 +1254,7 @@ public class UtilityResource { } for (Plugin plugin : plugins) { - id = plugin.getHeader().getUUID().toString(); + id = plugin.getID().toString(); List facets = plugin.getIdentificationFacets(); for (Facet f : facets) { diff --git a/src/main/webapp/WEB-INF/client.properties b/src/main/webapp/WEB-INF/client.properties new file mode 100644 index 0000000..a1eab5c --- /dev/null +++ b/src/main/webapp/WEB-INF/client.properties @@ -0,0 +1,4 @@ +endpoint=https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token +clientID=resource-registry-portlet-expieve +secret= +rootScope=/gcube \ No newline at end of file