Lucio Lelii 2022-07-15 09:22:32 +02:00
commit 5e85a182ac
7 changed files with 46 additions and 30 deletions

View File

@ -12,12 +12,14 @@ import java.util.Set;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.keycloak.KeycloakClient;
import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.model.AccessToken.Access;
import org.gcube.common.keycloak.model.ModelUtils;
import org.gcube.common.keycloak.model.TokenResponse;
import org.gcube.common.keycloak.model.AccessToken.Access;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
import org.gcube.informationsystem.types.reference.Type;
@ -25,6 +27,7 @@ import org.gcube.portlets.admin.resourcemanagement.shared.resource.CacheList;
import org.gcube.portlets.admin.resourcemanagement.shared.resource.UtilityResource;
import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
import org.gcube.resourcemanagement.support.shared.types.datamodel.CompleteResourceProfile;
/**
*
* @author pieve mail:alessandro.pieve@isti.cnr.it
@ -32,7 +35,7 @@ import org.gcube.resourcemanagement.support.shared.types.datamodel.CompleteResou
*/
public class RegistryClientRequester {
private static ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
private static ResourceRegistryClient resourceRegistryClient;
private static KeycloakClient client = KeycloakClientFactory.newInstance();
@ -40,21 +43,26 @@ public class RegistryClientRequester {
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";
public static final Set<String> getAvailableContexts() throws Exception {
Set<String> contexts = new HashSet<String>();
Set<String> contextList = new HashSet<String>();
ScopeProvider.instance.set(rootScope);
AccessTokenProvider.instance.set(getTokenForContext(rootScope));
try {
TokenResponse response = client.queryOIDCToken(new URL(endpoint), clientID, secret);
Map<String, Access> resourceAccess = ModelUtils.getAccessTokenFrom(response).getResourceAccess();
for (String context : resourceAccess.keySet()) {
try {
ScopeBean scope = new ScopeBean(context.replaceAll("%2F", "/"));
contexts.add(scope.toString());
}catch (IllegalArgumentException e) { }
}
resourceRegistryClient = ResourceRegistryClientFactory.create();
ContextCache contextCache = ContextCache.getInstance();
contextList = contextCache.getContextFullNameToUUIDAssociation().keySet();
} catch (Exception e) {
return Collections.emptySet();
}finally {
AccessTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}
return contexts;
return contextList;
}
private static String getTokenForContext(String context) {
@ -84,9 +92,14 @@ public class RegistryClientRequester {
ScopeProvider.instance.set(scope);
AccessTokenProvider.instance.set(getTokenForContext(scope));
try {
resourceRegistryClient = ResourceRegistryClientFactory.create();
List<Type> types = resourceRegistryClient.getType(Resource.class, true);
System.out.println("resource type returned "+types.size());
for (Type t : types) {
System.out.println("resource type found "+t.getName()+ " in "+scope);
String val = null;
if (t.getName().equals("EService"))
val= "RunningInstance";
@ -94,7 +107,15 @@ public class RegistryClientRequester {
val = "GenericResource";
if (t.getName().equals("HostingNode"))
val = "GHN";
retval.put(val, UtilityResource.getSubResourcesTreeQuery(resourceRegistryClient, t.getName()));
try {
if (val!=null) {
ArrayList<String> subtrees = UtilityResource.getSubResourcesTreeQuery(resourceRegistryClient, t.getName());
if (!subtrees.isEmpty())
retval.put(val, subtrees);
}
}catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
@ -117,7 +138,7 @@ public class RegistryClientRequester {
AccessTokenProvider.instance.set(getTokenForContext(scope));
try {
resourceRegistryClient = ResourceRegistryClientFactory.create();
List<String>resource=new ArrayList<String>();
switch (type) {

View File

@ -260,7 +260,7 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
ServerConsole.trace(LOG_PREFIX, "[GET-SCOPES] getting available scopes");
Vector<String> retval = new Vector<String>();
try {
//TODO
retval.addAll(RegistryClientRequester.getAvailableContexts());
} catch (Exception e) {
retval.add("/gcube");
retval.add("/gcube/devsec");

View File

@ -130,7 +130,12 @@ public class UtilityResource {
identifiedFacet="SoftwareFacet";
break;
default:
return new ArrayList<>(0);
}
String query="SELECT DISTINCT("+field+") AS "+field+" "
+ "FROM (TRAVERSE outE('IsIdentifiedBy'),inV('"+identifiedFacet+"') FROM "+entity+")";

View File

@ -4,7 +4,7 @@
<inherits name='com.google.gwt.user.User' />
<!-- To Comment out -->
<!-- <set-property name="user.agent" value="safari,gecko1_8" /> -->
<set-property name="user.agent" value="safari,gecko1_8" />
<!-- Other module inherits -->
<inherits name='com.extjs.gxt.ui.GXT' />

View File

@ -2,7 +2,7 @@
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>resources-management</portlet-name>
<display-name>Resources Management</display-name>
<display-name>Resource Registry Management</display-name>
<portlet-class>org.gcube.portlets.admin.resourcemanagement.server.portlet.ResourceManagementPortlet</portlet-class>
<init-param>
<name>view-jsp</name>
@ -13,7 +13,7 @@
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>Resources Management</title>
<title>Resource Registry Management</title>
<short-title>Resources Management</short-title>
<keywords>Resources Management</keywords>
</portlet-info>

View File

@ -14,16 +14,6 @@
<src>ServiceMap_devsec.xml</src>
<scope>/gcube/devsec</scope>
</vo>
<vo>
<name>gcube/devNext</name>
<src>ServiceMap_devNext.xml</src>
<scope>/gcube/devNext</scope>
</vo>
<vo>
<name>gcube/preprod</name>
<src>ServiceMap_preprod.xml</src>
<scope>/gcube/preprod</scope>
</vo>
</vos>
</infrastructure>

View File

@ -11,7 +11,7 @@ RUNNING_MODE = STANDALONE
DEFAULT_USER = massimiliano.assante
# The scope that will be used as default
DEFAULT_SCOPE =/gcube/devNext
DEFAULT_SCOPE =/gcube
# the target of update notification (if in singleton mode)
# mails MUST be separated by ;
USERMAIL_TO = m.assante@gmail.com