- 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">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
<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>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
|
11
pom.xml
11
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
|
@ -9,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.resources.discovery</groupId>
|
<groupId>org.gcube.resources.discovery</groupId>
|
||||||
<artifactId>ic-client</artifactId>
|
<artifactId>ic-client</artifactId>
|
||||||
<version>1.0.5-SNAPSHOT</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
<name>Information Collector Client</name>
|
<name>Information Collector Client</name>
|
||||||
<description>Client API for the Information Collector service</description>
|
<description>Client API for the Information Collector service</description>
|
||||||
|
|
||||||
|
@ -26,6 +27,12 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>authorization-client</artifactId>
|
||||||
|
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-scope</artifactId>
|
<artifactId>common-scope</artifactId>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.gcube.resources.discovery.icclient;
|
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.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -24,9 +24,8 @@ public class Helper {
|
||||||
public static String queryAddAuthenticationControl(String expression) throws MalformedQueryException
|
public static String queryAddAuthenticationControl(String expression) throws MalformedQueryException
|
||||||
{
|
{
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
|
if (context==null || !new ScopeBean(context).is(VRE))
|
||||||
if (scope==null || !new ScopeBean(scope).is(VRE))
|
|
||||||
return expression;
|
return expression;
|
||||||
|
|
||||||
int wherePathIndex=0;
|
int wherePathIndex=0;
|
||||||
|
@ -41,10 +40,9 @@ public class Helper {
|
||||||
HashMap<String, String> varReplacementMap = new HashMap<String, String>();
|
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 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 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('"+scope+"',*VAR*/child::*[local-name()='Scope']/text())) ";
|
String authStringNormal=" (functx:is-value-in-sequence('"+context+"',*VAR*/child::*[local-name()='Scope']/text())) ";
|
||||||
|
|
||||||
String queryFiltered;
|
String queryFiltered;
|
||||||
List<Boolean> collInsert= new ArrayList<Boolean>();
|
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 collectionPattern= Pattern.compile("[^\\s]*\\s*in\\s*collection\\s*[^\\s,]*");
|
||||||
Pattern varPattern= Pattern.compile("[^\\s]*");
|
Pattern varPattern= Pattern.compile("[^\\s]*");
|
||||||
Pattern resourcePattern= Pattern.compile("\\scollection\\s*\\([^\\)]*.*/Resource", Pattern.DOTALL);
|
Pattern resourcePattern= Pattern.compile("\\scollection\\s*\\([^\\)]*.*/Resource", Pattern.DOTALL);
|
||||||
Pattern propertiesPattern=Pattern.compile("\\scollection\\s*\\([^\\)]*.*/Document", Pattern.DOTALL);
|
|
||||||
Matcher varMat;
|
Matcher varMat;
|
||||||
Matcher resourceMat;
|
Matcher resourceMat;
|
||||||
Matcher collMat=collectionPattern.matcher(expression);
|
Matcher collMat=collectionPattern.matcher(expression);
|
||||||
|
@ -74,38 +71,19 @@ public class Helper {
|
||||||
log.warn("error parsing collection statement");
|
log.warn("error parsing collection statement");
|
||||||
}
|
}
|
||||||
varMat= varPattern.matcher(temp);
|
varMat= varPattern.matcher(temp);
|
||||||
boolean propBool=false;
|
resourceMat=resourcePattern.matcher(temp);
|
||||||
if (temp.contains("/Properties"))
|
|
||||||
{
|
|
||||||
resourceMat= propertiesPattern.matcher(temp);
|
|
||||||
propBool=true;
|
|
||||||
}
|
|
||||||
else resourceMat=resourcePattern.matcher(temp);
|
|
||||||
varMat.lookingAt();
|
varMat.lookingAt();
|
||||||
resourceMat.find();
|
resourceMat.find();
|
||||||
String tempPath="";
|
String tempPath="";
|
||||||
try{
|
try{
|
||||||
tempPath= temp.substring(resourceMat.end());
|
tempPath= temp.substring(resourceMat.end());
|
||||||
|
|
||||||
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 resourceMatString= resourceMat.group();
|
||||||
String oldVar = varMat.group();
|
String oldVar = varMat.group();
|
||||||
String newVar = "$entry"+collInsert.size()+"ValueAuth";
|
String newVar = "$entry"+collInsert.size()+"ValueAuth";
|
||||||
forStringTemp=forString.replace("*VAR*",newVar ).replace("*COLLECTION*",resourceMatString );
|
forStringTemp=forString.replace("*VAR*",newVar ).replace("*COLLECTION*",resourceMatString );
|
||||||
collInsert.add(resourceMatString.contains("/Profiles/RunningInstance") || resourceMatString.contains("/Profiles/GHN") || resourceMatString.contains("/Profiles/Service"));
|
collInsert.add(resourceMatString.contains("/Profiles/RunningInstance") || resourceMatString.contains("/Profiles/GHN") || resourceMatString.contains("/Profiles/Service"));
|
||||||
varReplacementMap.put(oldVar, newVar+"/.."+tempPath);
|
varReplacementMap.put(oldVar, newVar+"/.."+tempPath);
|
||||||
}
|
|
||||||
}catch(IllegalStateException e){ log.debug("error parsing statement");}
|
}catch(IllegalStateException e){ log.debug("error parsing statement");}
|
||||||
expression=expression.substring(0, collIndexStart)+ forStringTemp +expression.substring(collIndexEnd);
|
expression=expression.substring(0, collIndexStart)+ forStringTemp +expression.substring(collIndexEnd);
|
||||||
collMat=collectionPattern.matcher(expression);
|
collMat=collectionPattern.matcher(expression);
|
||||||
|
@ -199,7 +177,6 @@ public class Helper {
|
||||||
|
|
||||||
log.info("submitting filtered query: {}",queryFiltered);
|
log.info("submitting filtered query: {}",queryFiltered);
|
||||||
|
|
||||||
|
|
||||||
return queryFiltered;
|
return queryFiltered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.resources.discovery.icclient;
|
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.common.clients.stubs.jaxws.StubFactory.*;
|
||||||
import static org.gcube.resources.discovery.icclient.stubs.CollectorConstants.*;
|
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 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.clients.stubs.jaxws.JAXWSUtils;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.common.scope.api.ServiceMap;
|
import org.gcube.common.scope.api.ServiceMap;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryException;
|
import org.gcube.resources.discovery.client.api.DiscoveryException;
|
||||||
|
@ -71,7 +76,19 @@ public class ICClient implements DiscoveryClient<String> {
|
||||||
//helper
|
//helper
|
||||||
private CollectorStub getStub() {
|
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);
|
String address = serviceMap.endpoint(localname);
|
||||||
log.info("connecting to {}",address);
|
log.info("connecting to {}",address);
|
||||||
if (serviceMap.version().equals("2.0.0"))
|
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.GCoreEndpoint;
|
||||||
import org.gcube.common.resources.gcore.GenericResource;
|
import org.gcube.common.resources.gcore.GenericResource;
|
||||||
import org.gcube.common.resources.gcore.HostingNode;
|
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.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceInstance;
|
import org.gcube.common.resources.gcore.ServiceInstance;
|
||||||
import org.gcube.common.resources.gcore.Software;
|
import org.gcube.common.resources.gcore.Software;
|
||||||
|
@ -43,6 +44,8 @@ public class ICFactory {
|
||||||
// registers parameters for known queries
|
// registers parameters for known queries
|
||||||
static {
|
static {
|
||||||
|
|
||||||
|
register(Resource.class,
|
||||||
|
params().add(ns, nsDeclaration).add(range, format(profile_range, "")).build());
|
||||||
register(GenericResource.class,
|
register(GenericResource.class,
|
||||||
params().add(ns, nsDeclaration).add(range, format(profile_range, "GenericResource")).build());
|
params().add(ns, nsDeclaration).add(range, format(profile_range, "GenericResource")).build());
|
||||||
register(ServiceEndpoint.class,
|
register(ServiceEndpoint.class,
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package org.acme;
|
package org.acme;
|
||||||
|
|
||||||
import static java.lang.String.*;
|
import static java.lang.String.format;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.*;
|
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.net.URI;
|
||||||
import java.util.List;
|
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.GCoreEndpoint;
|
||||||
import org.gcube.common.resources.gcore.GenericResource;
|
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;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceInstance;
|
import org.gcube.common.resources.gcore.ServiceInstance;
|
||||||
|
import org.gcube.common.resources.gcore.Software;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
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.Query;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.gcube.resources.discovery.client.queries.impl.XQuery;
|
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
|
@Test
|
||||||
public void someServiceEndpointsAccessData() {
|
public void someServiceEndpointsAccessData() {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue