cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject svn commit: r1506620 - in /cxf/trunk: api/src/main/java/org/apache/cxf/common/injection/ api/src/main/java/org/apache/cxf/common/logging/ api/src/main/java/org/apache/cxf/common/util/ rt/core/src/main/java/org/apache/cxf/bus/extension/ rt/databinding/j...
Date Wed, 24 Jul 2013 16:38:44 GMT
Author: asoldano
Date: Wed Jul 24 16:38:44 2013
New Revision: 1506620

URL: http://svn.apache.org/r1506620
Log:
[CXF-5142] Initial set of changes for running jaxws client with security manager on

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
    cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java
    cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
    cxf/trunk/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java?rev=1506620&r1=1506619&r2=1506620&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java Wed
Jul 24 16:38:44 2013
@@ -24,6 +24,8 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 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.Collection;
 import java.util.LinkedList;
@@ -388,14 +390,14 @@ public class ResourceInjector extends Ab
 
         Collection<Method> methods = new LinkedList<Method>(); 
         addAnnotatedMethods(acls, getTarget().getClass().getMethods(), methods); 
-        addAnnotatedMethods(acls, getTarget().getClass().getDeclaredMethods(), methods);
+        addAnnotatedMethods(acls, ReflectionUtil.getDeclaredMethods(getTarget().getClass()),
methods);
         if (getTargetClass() != getTarget().getClass()) {
             addAnnotatedMethods(acls, getTargetClass().getMethods(), methods); 
-            addAnnotatedMethods(acls, getTargetClass().getDeclaredMethods(), methods);  
         
+            addAnnotatedMethods(acls, ReflectionUtil.getDeclaredMethods(getTargetClass()),
methods);            
         }
         return methods;
-    } 
-
+    }
+    
     private void addAnnotatedMethods(Class<? extends Annotation> acls, Method[] methods,
         Collection<Method> annotatedMethods) {
         for (Method method : methods) { 

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java?rev=1506620&r1=1506619&r2=1506620&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java Wed Jul 24 16:38:44
2013
@@ -235,7 +235,7 @@ public final class LogUtils {
         ClassLoader orig = Thread.currentThread().getContextClassLoader();
         ClassLoader n = cls.getClassLoader();
         if (n != null) {
-            Thread.currentThread().setContextClassLoader(n);
+            setContextClassLoader(n);
         }
         String bundleName = name;
         try {
@@ -304,10 +304,19 @@ public final class LogUtils {
             return logger;
         } finally {
             if (n != orig) {
-                Thread.currentThread().setContextClassLoader(orig);
+                setContextClassLoader(orig);
             }
         }
     }
+    
+    private static void setContextClassLoader(final ClassLoader classLoader) {
+        AccessController.doPrivileged(new PrivilegedAction<Object>() {
+            public Object run() {
+                Thread.currentThread().setContextClassLoader(classLoader);
+                return null;
+            }
+        });
+    }
 
     /**
      * Allows both parameter substitution and a typed Throwable to be logged.

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java?rev=1506620&r1=1506619&r2=1506620&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java Wed Jul 24
16:38:44 2013
@@ -29,6 +29,8 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -110,6 +112,25 @@ public final class ReflectionUtil {
             }
         });
     }
+
+    public static Method getDeclaredMethod(final Class<?> clazz, final String name,
+                                            final Class<?>... parameterTypes) throws
NoSuchMethodException {
+        try {
+            return AccessController.doPrivileged(new PrivilegedExceptionAction<Method>()
{
+                public Method run() throws Exception {
+                    return clazz.getDeclaredMethod(name, parameterTypes);
+                }
+            });
+        } catch (PrivilegedActionException pae) {
+            Exception e = pae.getException();
+            if (e instanceof NoSuchMethodException) {
+                throw (NoSuchMethodException)e;
+            } else {
+                throw new SecurityException(e);
+            }
+        }
+    }
+
     public static Field[] getDeclaredFields(final Class<?> cls) {
         return AccessController.doPrivileged(new PrivilegedAction<Field[]>() {
             public Field[] run() {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java?rev=1506620&r1=1506619&r2=1506620&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
Wed Jul 24 16:38:44 2013
@@ -23,6 +23,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.LinkedHashMap;
@@ -154,8 +157,17 @@ public class ExtensionManagerImpl implem
         Enumeration<URL> urls = l.getResources(resource);
         
         while (urls.hasMoreElements()) {
-            URL url = urls.nextElement();
-            InputStream is = url.openStream();
+            final URL url = urls.nextElement();
+            InputStream is;
+            try {
+                is = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>()
{
+                    public InputStream run() throws Exception {
+                        return url.openStream();
+                    }
+                });
+            } catch (PrivilegedActionException pae) {
+                throw (IOException)pae.getException();
+            }
             try {
                 List<Extension> exts = new TextExtensionFragmentParser(loader).getExtensions(is);
                 for (Extension e : exts) {

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=1506620&r1=1506619&r2=1506620&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Wed
Jul 24 16:38:44 2013
@@ -27,6 +27,8 @@ import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -787,9 +789,10 @@ public class JAXBDataBinding extends Abs
                                  objectFactory);
     }
 
-    private static Field getElField(String partName, Class<?> wrapperType) {
+    private static Field getElField(String partName, final Class<?> wrapperType) {
         String fieldName = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.VARIABLE);
-        for (Field field : wrapperType.getDeclaredFields()) {
+        Field[] fields = ReflectionUtil.getDeclaredFields(wrapperType);
+        for (Field field : fields) {
             XmlElement el = field.getAnnotation(XmlElement.class);
             if (el != null
                 && partName.equals(el.name())) {

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java?rev=1506620&r1=1506619&r2=1506620&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java Wed Jul
24 16:38:44 2013
@@ -60,6 +60,7 @@ import org.apache.cxf.binding.BindingFac
 import org.apache.cxf.binding.soap.wsdl.extensions.SoapAddress;
 import org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding;
 import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.i18n.UncheckedException;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.common.util.StringUtils;
@@ -199,6 +200,9 @@ public class ServiceImpl extends Service
         } catch (WebServiceException e) {
             throw e;
         } catch (Throwable e) {
+            if (e instanceof UncheckedException && LOG.isLoggable(Level.FINE)) {
+                LOG.log(Level.FINE, e.getLocalizedMessage(), e);
+            }
             WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL, serviceName);
             Service service = sf.create();
             for (ServiceInfo si : service.getServiceInfos()) { 

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java?rev=1506620&r1=1506619&r2=1506620&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
Wed Jul 24 16:38:44 2013
@@ -56,6 +56,7 @@ import org.apache.cxf.common.i18n.Messag
 import org.apache.cxf.common.injection.NoJSR250Annotations;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.databinding.source.SourceDataBinding;
@@ -263,16 +264,17 @@ public class JaxWsServiceFactoryBean ext
 
         try {
             // Find the Async method which returns a Response
-            Method responseMethod = method.getDeclaringClass().getDeclaredMethod(method.getName()
+ "Async",
-                                                                                 method.getParameterTypes());
+            Method responseMethod = ReflectionUtil.getDeclaredMethod(method.getDeclaringClass(),
+                                                                     method.getName() + "Async",
+                                                                     method.getParameterTypes());
 
             // Find the Async method whic has a Future & AsyncResultHandler
             List<Class<?>> asyncHandlerParams = Arrays.asList(method.getParameterTypes());
             //copy it to may it non-readonly
             asyncHandlerParams = new ArrayList<Class<?>>(asyncHandlerParams);
             asyncHandlerParams.add(AsyncHandler.class);
-            Method futureMethod = method.getDeclaringClass()
-                .getDeclaredMethod(method.getName() + "Async",
+            Method futureMethod = ReflectionUtil
+                .getDeclaredMethod(method.getDeclaringClass(), method.getName() + "Async",
                                    asyncHandlerParams.toArray(new Class<?>[asyncHandlerParams.size()]));
 
             getMethodDispatcher().bind(op, method, responseMethod, futureMethod);
@@ -283,7 +285,7 @@ public class JaxWsServiceFactoryBean ext
             getMethodDispatcher().bind(op, method);
         }
     }
-
+    
     @Override
     protected void initializeWSDLOperations() {
         if (implInfo.isWebServiceProvider()) {

Modified: cxf/trunk/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java?rev=1506620&r1=1506619&r2=1506620&view=diff
==============================================================================
--- cxf/trunk/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java (original)
+++ cxf/trunk/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java Wed Jul 24
16:38:44 2013
@@ -74,6 +74,7 @@ import org.apache.cxf.common.util.ASMHel
 import org.apache.cxf.common.util.ASMHelper.MethodVisitor;
 import org.apache.cxf.common.util.ASMHelper.Opcodes;
 import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -173,7 +174,7 @@ public class JAXBExtensionHelper impleme
         try {
             Class<?> objectFactory = Class.forName(PackageUtils.getPackageName(cls)
+ ".ObjectFactory",
                                                    true, cls.getClassLoader());
-            Method methods[] = objectFactory.getDeclaredMethods();
+            Method methods[] = ReflectionUtil.getDeclaredMethods(objectFactory);
             for (Method method : methods) {
                 if (method.getParameterTypes().length == 1
                     && method.getParameterTypes()[0].equals(cls)) {



Mime
View raw message