AuthorizationToken maangement added
CAllerMethod management added git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-gcore-stubs/1.0@119137 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
074b7b34ba
commit
03c097ddac
|
@ -22,12 +22,12 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
|
15
pom.xml
15
pom.xml
|
@ -8,7 +8,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-gcore-stubs</artifactId>
|
<artifactId>common-gcore-stubs</artifactId>
|
||||||
<version>1.2.0-SNAPSHOT</version>
|
<version>1.2.1-SNAPSHOT</version>
|
||||||
<name>GCore Stubs</name>
|
<name>GCore Stubs</name>
|
||||||
<description>JAXWS Stub Support for gCore Service</description>
|
<description>JAXWS Stub Support for gCore Service</description>
|
||||||
|
|
||||||
|
@ -35,17 +35,22 @@
|
||||||
<artifactId>common-scope</artifactId>
|
<artifactId>common-scope</artifactId>
|
||||||
<version>[1.1.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
<version>[1.1.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- test dependencies -->
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>common-authorization</artifactId>
|
||||||
|
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test dependencies -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-simple</artifactId>
|
<artifactId>slf4j-simple</artifactId>
|
||||||
<version>1.6.4</version>
|
<version>1.6.4</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
|
||||||
|
|
||||||
import org.gcube.common.clients.stubs.jaxws.StubFactoryDSL.AtClause;
|
import org.gcube.common.clients.stubs.jaxws.StubFactoryDSL.AtClause;
|
||||||
import org.gcube.common.clients.stubs.jaxws.handlers.GCoreJAXWSHandler;
|
import org.gcube.common.clients.stubs.jaxws.handlers.GCoreJAXWSHandler;
|
||||||
|
import org.gcube.common.clients.stubs.jaxws.proxies.GenericProxyFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -107,12 +108,14 @@ public class StubFactory<T> implements StubFactoryDSL.AtClause<T> {
|
||||||
// get JAXWS stub
|
// get JAXWS stub
|
||||||
T stub = service.getPort(reference,target.type(),features);
|
T stub = service.getPort(reference,target.type(),features);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BindingProvider provider = (BindingProvider) stub;
|
BindingProvider provider = (BindingProvider) stub;
|
||||||
|
|
||||||
// configure stub for gCube calls
|
// configure stub for gCube calls
|
||||||
registerHandler(provider, target);
|
registerHandler(provider, target);
|
||||||
|
|
||||||
return stub;
|
return GenericProxyFactory.getProxy(target.type(), stub);
|
||||||
|
|
||||||
} catch (Error e) { //bad stubs/wsdls cause java.lang.Errors
|
} catch (Error e) { //bad stubs/wsdls cause java.lang.Errors
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package org.gcube.common.clients.stubs.jaxws.handlers;
|
||||||
|
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
import javax.xml.soap.SOAPHeader;
|
||||||
|
import javax.xml.ws.handler.soap.SOAPMessageContext;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.clients.stubs.jaxws.GCoreService;
|
||||||
|
|
||||||
|
public class AuthorizationHandler extends AbstractHandler {
|
||||||
|
|
||||||
|
/** Namespace of scope-related headers */
|
||||||
|
public static final String TOKEN_NS = "http://gcube-system.org/namespaces/gcube-token";
|
||||||
|
|
||||||
|
/** Name of the scope call header. */
|
||||||
|
public static final String TOKEN_HEADER_NAME = "gcube-token";
|
||||||
|
public static final QName TOKEN_QNAME = new QName(TOKEN_NS,TOKEN_HEADER_NAME);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleRequest(GCoreService<?> target, SOAPHeader header, SOAPMessageContext context) throws Exception {
|
||||||
|
String token = SecurityTokenProvider.instance.get();
|
||||||
|
if (token!=null)
|
||||||
|
addHeader(header,TOKEN_QNAME, token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import javax.xml.namespace.QName;
|
||||||
import javax.xml.soap.SOAPHeader;
|
import javax.xml.soap.SOAPHeader;
|
||||||
import javax.xml.ws.handler.soap.SOAPMessageContext;
|
import javax.xml.ws.handler.soap.SOAPMessageContext;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
||||||
import org.gcube.common.clients.stubs.jaxws.GCoreService;
|
import org.gcube.common.clients.stubs.jaxws.GCoreService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,9 +22,16 @@ public class ClientInfoHandler extends AbstractHandler {
|
||||||
public static final String CALLER_NS = "http://gcube-system.org/namespaces/caller";
|
public static final String CALLER_NS = "http://gcube-system.org/namespaces/caller";
|
||||||
|
|
||||||
public static final QName CALLER_QNAME = new QName(CALLER_NS,CALLER_HEADER_NAME);
|
public static final QName CALLER_QNAME = new QName(CALLER_NS,CALLER_HEADER_NAME);
|
||||||
|
|
||||||
|
public static final String CALLED_METHOD_HEADER_NAME = "gcube-method";
|
||||||
|
/** Namespace of scope-related headers */
|
||||||
|
public static final String CALLED_METHOD_NS = "http://gcube-system.org/namespaces/method";
|
||||||
|
|
||||||
|
public static final QName CALLED_METHOD_QNAME = new QName(CALLED_METHOD_NS,CALLED_METHOD_HEADER_NAME);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(GCoreService<?> target, SOAPHeader header, SOAPMessageContext context) throws Exception {
|
public void handleRequest(GCoreService<?> target, SOAPHeader header, SOAPMessageContext context) throws Exception {
|
||||||
addHeader(header,CALLER_QNAME, target.clientId());
|
addHeader(header,CALLER_QNAME, target.clientId());
|
||||||
|
addHeader(header, CALLED_METHOD_QNAME, CalledMethodProvider.instance.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,6 @@ public class ScopeHandler extends AbstractHandler {
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(GCoreService<?> target, SOAPHeader header, SOAPMessageContext context) throws Exception {
|
public void handleRequest(GCoreService<?> target, SOAPHeader header, SOAPMessageContext context) throws Exception {
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
if (scope==null)
|
|
||||||
throw new IllegalStateException("no scope is defined for this call");
|
|
||||||
addHeader(header,SCOPE_QNAME, scope);
|
addHeader(header,SCOPE_QNAME, scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package org.gcube.common.clients.stubs.jaxws.proxies;
|
||||||
|
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
|
public class GenericProxyFactory {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T, I extends T> T getProxy(Class<T> intf,
|
||||||
|
final I obj) {
|
||||||
|
return (T)
|
||||||
|
Proxy.newProxyInstance(obj.getClass().getClassLoader(),
|
||||||
|
new Class[] { intf },
|
||||||
|
new MethodRetriever<I>(obj));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.gcube.common.clients.stubs.jaxws.proxies;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class MethodRetriever<T> implements InvocationHandler{
|
||||||
|
|
||||||
|
public static Logger log = LoggerFactory.getLogger(MethodRetriever.class);
|
||||||
|
|
||||||
|
private T service;
|
||||||
|
|
||||||
|
public MethodRetriever(T service){
|
||||||
|
this.service= service;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object invoke(Object proxy, Method method,
|
||||||
|
Object[] args) throws Throwable {
|
||||||
|
CalledMethodProvider.instance.set(method.getName());
|
||||||
|
try{
|
||||||
|
return method.invoke(service, args);
|
||||||
|
}finally{
|
||||||
|
CalledMethodProvider.instance.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
org.gcube.common.clients.stubs.jaxws.handlers.ScopeHandler
|
org.gcube.common.clients.stubs.jaxws.handlers.ScopeHandler
|
||||||
|
org.gcube.common.clients.stubs.jaxws.handlers.AuthorizationHandler
|
||||||
org.gcube.common.clients.stubs.jaxws.handlers.TargetServiceHandler
|
org.gcube.common.clients.stubs.jaxws.handlers.TargetServiceHandler
|
||||||
org.gcube.common.clients.stubs.jaxws.handlers.ClientInfoHandler
|
org.gcube.common.clients.stubs.jaxws.handlers.ClientInfoHandler
|
||||||
org.gcube.common.clients.stubs.jaxws.handlers.LegacyWSAddressingHandler
|
org.gcube.common.clients.stubs.jaxws.handlers.LegacyWSAddressingHandler
|
Loading…
Reference in New Issue