diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-08-17 16:04:45 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-08-17 16:04:45 +0000 |
commit | 9d69b5d4b215f691496a87eea974179a88885383 (patch) | |
tree | 39b4b4e5e5e470a019c5d4a4c66a009214c20bf9 /sca-java-2.x | |
parent | 1798efc6a2291275dcf9a75b6cc06e64776a5cfa (diff) |
TUSCANY-3922 - apply Jennifer's patch to add some missing doPrivileged calls around various classloader calls. Thanks for the patch Jennifer.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1158793 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x')
4 files changed, 62 insertions, 8 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java index 8d80898071..795aae53b8 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java +++ b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java @@ -21,6 +21,9 @@ package org.apache.tuscany.sca.binding.ws.wsdlgen; import java.lang.reflect.Method; import java.net.URI; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -118,7 +121,17 @@ public class Interface2WSDLGenerator { this.dataBindings = dataBindings; this.xsdFactory = xsdFactory; this.monitor = monitor; - this.factory = WSDLFactory.newInstance(); + try{ + this.factory = AccessController.doPrivileged(new PrivilegedExceptionAction<WSDLFactory>() { + public WSDLFactory run() throws WSDLException{ + WSDLFactory factory = WSDLFactory.newInstance(); + return factory; + } + }); + } catch (PrivilegedActionException e){ + throw (WSDLException) e.getException(); + } + } /** diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java index 025b4f7c73..a73e2a1c24 100644 --- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java +++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java @@ -26,6 +26,7 @@ import java.io.InputStreamReader; import java.lang.ref.SoftReference; import java.net.URI; import java.security.AccessController; +import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; @@ -472,7 +473,14 @@ public class JAXBContextCache { for (Class<?> cls : classes) { Package pkg = getPackage(cls); if (pkg != null) { - pkgs.put(pkg, cls.getClassLoader()); + final Class fcls = cls; + ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { + public ClassLoader run() { + ClassLoader cl = fcls.getClassLoader(); + return cl; + } + }); + pkgs.put(pkg, cl); } } return pkgs; diff --git a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java index 5e5774f338..3721fb7e63 100644 --- a/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java +++ b/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.databinding.javabeans; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -30,6 +31,8 @@ import java.io.OutputStream; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.logging.Logger; import org.apache.tuscany.sca.databinding.BaseDataBinding; @@ -88,7 +91,16 @@ public class JavaBeansDataBinding extends BaseDataBinding { // because Collection classes are loaded by the System ClassLoader but their contents // may be loaded from another ClassLoader // - ClassLoader classLoaderToUse = targetDataType.getPhysical().getClassLoader(); + final DataType fTargetDataType = targetDataType; + ClassLoader classLoaderToUse = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { + public ClassLoader run() { + ClassLoader cl = fTargetDataType.getPhysical().getClassLoader(); + return cl; + } + }); + + + if (classLoaderToUse == null) { classLoaderToUse = clazz.getClassLoader(); } diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java index 0b97192cc6..33e1b1891d 100644 --- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java +++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java @@ -18,8 +18,12 @@ */ package org.apache.tuscany.sca.implementation.java.invocation; + + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.List; @@ -94,7 +98,12 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics // store the current thread context classloader // as we need to replace it with the class loader // used to load the java class as per SCA Spec - ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + final ClassLoader tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { + public ClassLoader run() { + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + return tccl; + } + }); try { // The following call might create a new conversation, as a result, the msg.getConversationID() might @@ -107,7 +116,7 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics injectCallbacks(wrapper, (JavaInterface)interfaze.getCallbackInterface()); } - Object instance = wrapper.getInstance(); + final Object instance = wrapper.getInstance(); // If the method couldn't be computed statically, or the instance being // invoked is a user-specified callback object that doesn't implement @@ -125,8 +134,14 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics // Set the thread context classloader of the thread used to invoke an operation // of a Java POJO component implementation is the class loader of the contribution // that contains the POJO implementation class. + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Thread.currentThread().setContextClassLoader(instance.getClass().getClassLoader()); + return null; + } + }); + - Thread.currentThread().setContextClassLoader(instance.getClass().getClassLoader()); int argumentHolderCount = 0; @@ -245,8 +260,14 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics } catch (Exception e) { msg.setFaultBody(e); } finally { - // set the tccl - Thread.currentThread().setContextClassLoader(tccl); + // set the tccl + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Thread.currentThread().setContextClassLoader(tccl); + return null; + } + }); + } return msg; } |