- Maps taken from AuthorizationEntry if not null
This commit is contained in:
parent
8176da86cd
commit
87c5fcf09e
|
@ -16,7 +16,6 @@
|
|||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
|
|
4
.project
4
.project
|
@ -16,12 +16,12 @@
|
|||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
|
|
23
pom.xml
23
pom.xml
|
@ -1,4 +1,5 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
|
@ -9,15 +10,15 @@
|
|||
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
<version>1.0.5-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<name>Information Collector Client</name>
|
||||
<description>Client API for the Information Collector service</description>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
||||
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
||||
</scm>
|
||||
<scm>
|
||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
||||
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
|
@ -26,12 +27,18 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>discovery-client</artifactId>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.resources.discovery.icclient;
|
||||
|
||||
import static org.gcube.common.scope.impl.ScopeBean.Type.*;
|
||||
import static org.gcube.common.scope.impl.ScopeBean.Type.VRE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -24,9 +24,8 @@ public class Helper {
|
|||
public static String queryAddAuthenticationControl(String expression) throws MalformedQueryException
|
||||
{
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
|
||||
if (scope==null || !new ScopeBean(scope).is(VRE))
|
||||
String context = ScopeProvider.instance.get();
|
||||
if (context==null || !new ScopeBean(context).is(VRE))
|
||||
return expression;
|
||||
|
||||
int wherePathIndex=0;
|
||||
|
@ -41,10 +40,9 @@ public class Helper {
|
|||
HashMap<String, String> varReplacementMap = new HashMap<String, String>();
|
||||
|
||||
|
||||
String forPropertiesString=" *VAR* in *COLLECTION*/Data "; ///child::*[local-name()='Scope']
|
||||
String forString=" *VAR* in *COLLECTION*/Scopes ";
|
||||
String authString=" (functx:is-value-in-sequence('"+scope+"',*VAR*/child::*[local-name()='Scope']/text()) or functx:is-value-in-sequence('"+scope.substring(0,scope.lastIndexOf("/"))+"',*VAR*/child::*[local-name()='Scope']/text())) ";
|
||||
String authStringNormal=" (functx:is-value-in-sequence('"+scope+"',*VAR*/child::*[local-name()='Scope']/text())) ";
|
||||
String authString=" (functx:is-value-in-sequence('"+context+"',*VAR*/child::*[local-name()='Scope']/text()) or functx:is-value-in-sequence('"+context.substring(0,context.lastIndexOf("/"))+"',*VAR*/child::*[local-name()='Scope']/text())) ";
|
||||
String authStringNormal=" (functx:is-value-in-sequence('"+context+"',*VAR*/child::*[local-name()='Scope']/text())) ";
|
||||
|
||||
String queryFiltered;
|
||||
List<Boolean> collInsert= new ArrayList<Boolean>();
|
||||
|
@ -57,7 +55,6 @@ public class Helper {
|
|||
Pattern collectionPattern= Pattern.compile("[^\\s]*\\s*in\\s*collection\\s*[^\\s,]*");
|
||||
Pattern varPattern= Pattern.compile("[^\\s]*");
|
||||
Pattern resourcePattern= Pattern.compile("\\scollection\\s*\\([^\\)]*.*/Resource", Pattern.DOTALL);
|
||||
Pattern propertiesPattern=Pattern.compile("\\scollection\\s*\\([^\\)]*.*/Document", Pattern.DOTALL);
|
||||
Matcher varMat;
|
||||
Matcher resourceMat;
|
||||
Matcher collMat=collectionPattern.matcher(expression);
|
||||
|
@ -74,38 +71,19 @@ public class Helper {
|
|||
log.warn("error parsing collection statement");
|
||||
}
|
||||
varMat= varPattern.matcher(temp);
|
||||
boolean propBool=false;
|
||||
if (temp.contains("/Properties"))
|
||||
{
|
||||
resourceMat= propertiesPattern.matcher(temp);
|
||||
propBool=true;
|
||||
}
|
||||
else resourceMat=resourcePattern.matcher(temp);
|
||||
resourceMat=resourcePattern.matcher(temp);
|
||||
varMat.lookingAt();
|
||||
resourceMat.find();
|
||||
String tempPath="";
|
||||
try{
|
||||
tempPath= temp.substring(resourceMat.end());
|
||||
String resourceMatString= resourceMat.group();
|
||||
String oldVar = varMat.group();
|
||||
String newVar = "$entry"+collInsert.size()+"ValueAuth";
|
||||
forStringTemp=forString.replace("*VAR*",newVar ).replace("*COLLECTION*",resourceMatString );
|
||||
collInsert.add(resourceMatString.contains("/Profiles/RunningInstance") || resourceMatString.contains("/Profiles/GHN") || resourceMatString.contains("/Profiles/Service"));
|
||||
varReplacementMap.put(oldVar, newVar+"/.."+tempPath);
|
||||
|
||||
if (propBool)
|
||||
{
|
||||
String resourceMatString= resourceMat.group();
|
||||
forStringTemp=forPropertiesString.replace("*VAR*","$entry"+collInsert.size()+"ValueAuth" ).replace("*COLLECTION*", resourceMatString );
|
||||
String oldVar = varMat.group();
|
||||
String newVar = "$entry"+collInsert.size()+"ValueAuth";
|
||||
collInsert.add(true);
|
||||
|
||||
varReplacementMap.put(oldVar, newVar+"/.."+tempPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
String resourceMatString= resourceMat.group();
|
||||
String oldVar = varMat.group();
|
||||
String newVar = "$entry"+collInsert.size()+"ValueAuth";
|
||||
forStringTemp=forString.replace("*VAR*",newVar ).replace("*COLLECTION*",resourceMatString );
|
||||
collInsert.add(resourceMatString.contains("/Profiles/RunningInstance") || resourceMatString.contains("/Profiles/GHN") || resourceMatString.contains("/Profiles/Service"));
|
||||
varReplacementMap.put(oldVar, newVar+"/.."+tempPath);
|
||||
}
|
||||
}catch(IllegalStateException e){ log.debug("error parsing statement");}
|
||||
expression=expression.substring(0, collIndexStart)+ forStringTemp +expression.substring(collIndexEnd);
|
||||
collMat=collectionPattern.matcher(expression);
|
||||
|
@ -198,7 +176,6 @@ public class Helper {
|
|||
queryFiltered = queryFiltered.replaceAll("text\\(\\) ne ","text() != ");
|
||||
|
||||
log.info("submitting filtered query: {}",queryFiltered);
|
||||
|
||||
|
||||
return queryFiltered;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.resources.discovery.icclient;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
import static org.gcube.common.clients.stubs.jaxws.StubFactory.*;
|
||||
import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.*;
|
||||
|
||||
|
@ -11,7 +12,11 @@ import java.util.regex.Pattern;
|
|||
|
||||
import javax.xml.ws.soap.SOAPFaultException;
|
||||
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.clients.stubs.jaxws.JAXWSUtils;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.api.ServiceMap;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryException;
|
||||
|
@ -70,8 +75,20 @@ public class ICClient implements DiscoveryClient<String> {
|
|||
|
||||
//helper
|
||||
private CollectorStub getStub() {
|
||||
|
||||
ServiceMap serviceMap = ServiceMap.instance;
|
||||
|
||||
ServiceMap serviceMap = null;
|
||||
|
||||
if (SecurityTokenProvider.instance.get()!=null) {
|
||||
try {
|
||||
AuthorizationEntry entry = authorizationService().get(SecurityTokenProvider.instance.get());
|
||||
serviceMap = entry.getMap();
|
||||
if (serviceMap==null) ScopeProvider.instance.set(entry.getContext());
|
||||
} catch (Throwable e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (serviceMap ==null) serviceMap = ServiceMap.instance;
|
||||
String address = serviceMap.endpoint(localname);
|
||||
log.info("connecting to {}",address);
|
||||
if (serviceMap.version().equals("2.0.0"))
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Map;
|
|||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceInstance;
|
||||
import org.gcube.common.resources.gcore.Software;
|
||||
|
@ -42,7 +43,9 @@ public class ICFactory {
|
|||
|
||||
// registers parameters for known queries
|
||||
static {
|
||||
|
||||
|
||||
register(Resource.class,
|
||||
params().add(ns, nsDeclaration).add(range, format(profile_range, "")).build());
|
||||
register(GenericResource.class,
|
||||
params().add(ns, nsDeclaration).add(range, format(profile_range, "GenericResource")).build());
|
||||
register(ServiceEndpoint.class,
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package org.acme;
|
||||
|
||||
import static java.lang.String.*;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.*;
|
||||
import static java.lang.String.format;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -12,11 +15,16 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.GenericResource;
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Resources;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.resources.gcore.ServiceInstance;
|
||||
import org.gcube.common.resources.gcore.Software;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.api.ResultParser;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.resources.discovery.client.queries.impl.XQuery;
|
||||
|
@ -149,6 +157,48 @@ public class APIClient {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getResources() {
|
||||
|
||||
XQuery query = ICFactory.queryFor(Resource.class);
|
||||
query.addCondition(String.format("$resource/ID/text() eq '%s'","bdaccb35-7f27-45a6-8ca9-11d467cb9233"));
|
||||
query.setResult("<Ret>{$resource/Type}{$resource}</Ret>");
|
||||
DiscoveryClient<? extends Resource> client = ICFactory.clientWith(new ResourceParser());
|
||||
List<? extends Resource> resources = client.submit(query);
|
||||
resources.forEach(res-> System.out.println(res.id()));
|
||||
|
||||
}
|
||||
|
||||
public static class ResourceParser implements ResultParser<Resource>{
|
||||
|
||||
private enum ResourceType {
|
||||
GenericResource(GenericResource.class),
|
||||
RuntimeResource(ServiceEndpoint.class),
|
||||
RunningInstance(GCoreEndpoint.class),
|
||||
Service(Software.class),
|
||||
GHN(HostingNode.class);
|
||||
|
||||
private Class<? extends Resource> managerClass;
|
||||
|
||||
ResourceType(Class<? extends Resource> managerClass) {
|
||||
this.managerClass = managerClass;
|
||||
}
|
||||
|
||||
public Class<? extends Resource> getManagerClass(){
|
||||
return this.managerClass;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource parse(String res) throws Exception {
|
||||
String type = res.replaceAll("<Ret>\\s*<Type>([^<]*).*", "$1");
|
||||
String resource = res.replaceAll(".*(<Resource.*>.*</Resource>).*", "$1");
|
||||
Class<? extends Resource> classForUnmrshalling= ResourceType.valueOf(type).getManagerClass();
|
||||
return Resources.unmarshal(classForUnmrshalling, new StringReader(resource));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void someServiceEndpointsAccessData() {
|
||||
|
||||
|
|
Loading…
Reference in New Issue