axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r785720 - in /webservices/axis2/trunk/java/modules: jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java
Date Wed, 17 Jun 2009 16:52:53 GMT
Author: scheu
Date: Wed Jun 17 16:52:52 2009
New Revision: 785720

URL: http://svn.apache.org/viewvc?rev=785720&view=rev
Log:
JIRA:AXIS2-4390
Contributors:Paul Mariduena & Rich Scheuerle
Summary: Added doPriv code to avoid Java2Security exceptions

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java?rev=785720&r1=785719&r2=785720&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaBeanDispatcher.java
Wed Jun 17 16:52:52 2009
@@ -48,6 +48,8 @@
 import java.lang.reflect.Method;
 import java.util.concurrent.Executor;
 import java.util.concurrent.FutureTask;
+import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedActionException;
 
 /**
  * The JavaBeanDispatcher is used to manage creating an instance of a JAX-WS service implementation
@@ -136,7 +138,7 @@
         }
         
         EndpointInvocationContext eic = (EndpointInvocationContext) request.getInvocationContext();
-        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        ClassLoader cl = getContextClassLoader();
         
         AsyncInvocationWorker worker = new AsyncInvocationWorker(target, 
                                                                  methodInputParams, 
@@ -184,7 +186,7 @@
         }
         
         EndpointInvocationContext eic = (EndpointInvocationContext) request.getInvocationContext();
-        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        ClassLoader cl = getContextClassLoader();
         
         AsyncInvocationWorker worker = new AsyncInvocationWorker(target, methodInputParams,
cl, eic);
         FutureTask task = new FutureTask<AsyncInvocationWorker>(worker);
@@ -356,4 +358,33 @@
         return response;
     }
     
+    /**
+     * @return ClassLoader
+     */
+    private static ClassLoader getContextClassLoader() {
+        // NOTE: This method must remain private because it uses AccessController
+        ClassLoader cl = null;
+        try {
+            cl = (ClassLoader) org.apache.axis2.java.security.AccessController.doPrivileged(new
PrivilegedExceptionAction() {
+                public Object run() throws ClassNotFoundException {
+                    return Thread.currentThread().getContextClassLoader();
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            // The privileged method will throw a PriviledgedActionException which
+            // contains the actual exception.
+            if (log.isDebugEnabled()) {
+                log.debug("Exception thrown from AccessController: " + e);
+            }
+            Exception wrappedE = e.getException();
+            if (wrappedE instanceof RuntimeException) {
+                throw (RuntimeException) wrappedE;
+            } else {
+                throw new RuntimeException(wrappedE);
+            }
+        }
+        
+        return cl;
+    }
+    
 }

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java?rev=785720&r1=785719&r2=785720&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java
(original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java
Wed Jun 17 16:52:52 2009
@@ -22,6 +22,7 @@
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
+import org.apache.axis2.java.security.AccessController;
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.description.AttachmentDescription;
 import org.apache.axis2.jaxws.description.AttachmentType;
@@ -63,6 +64,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -250,7 +252,12 @@
             log.debug("Attempting to load @HandlerChain configuration file: " + configFile
+
                     " relative to class: " + className);
         }
+        // Attempt 1:
+	// Try absolute loading
         try {
+	    if (log.isDebugEnabled()) {
+	        log.debug("Attempt 1: Try absolute load of (" + configFile + ")");
+	    }
             configURL = new URL(configFile);
             if (configURL != null) {
                 if (log.isDebugEnabled()) {
@@ -261,17 +268,30 @@
         }
         catch (MalformedURLException e) {
             // try another method to obtain a stream to the configuration file
+	    if (log.isDebugEnabled()) {
+	        log.debug("Attempt 1 Failed with exception.  Try Attempt 2.  " +
+	                  "The caught exception is : " + e);
+	    }
         }
         catch (IOException e) {
             // report this since it was a valid URL but the openStream caused a problem
+	    if (log.isDebugEnabled()) {
+	        log.debug("The URL was valid, but opening the stream " +
+	                      "caused a problem : " + e);
+	    }
             throw ExceptionFactory.makeWebServiceException(Messages.getMessage("hcConfigLoadFail",
                                                                          configFile, className,
                                                                          e.toString()));
         }
+
+	    // Attempt 2:
+	    // Try relative uri loading from Classloaders
         if (configStream == null) {
             if (log.isDebugEnabled()) {
                 log.debug("@HandlerChain.file attribute refers to a relative location: "
                         + configFile);
+	        log.debug("Attempt 2: Try relative uri load of (" + configFile + ") " +
+	            "from the classloaders");
             }
             className = className.replace(".", "/");
             try {
@@ -285,10 +305,14 @@
                 if (log.isDebugEnabled()) {
                     log.debug("@HandlerChain.file resolved file path location: " + resolvedPath);
                 }
-                configStream = getInputStream(resolvedPath, classLoader);
+                configStream = getInputStream_priv(resolvedPath, classLoader);
             }
-            catch (URISyntaxException e) {
-                throw ExceptionFactory.makeWebServiceException(Messages.getMessage("hcConfigLoadFail",
+	    catch (Throwable e) {
+	      if (log.isDebugEnabled()) {
+	          log.debug("Attempt 2 Failed with exception. " +
+	                    "The caught exception is : " + e);
+	      }
+              throw ExceptionFactory.makeWebServiceException(Messages.getMessage("hcConfigLoadFail",
                                                                              configFile,
className,
                                                                              e.toString()));
             }
@@ -310,12 +334,39 @@
         }
         return configStream;
     }
-    
+
+    /**
+     * A doPriv version of getInputStream
+     * @return
+     */
+    private static InputStream getInputStream_priv(final String path, 
+                                                   final ClassLoader classLoader) {
+        return (InputStream) 
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    return getInputStream(path, classLoader);
+                }
+            });
+    }
+
+    /**
+     * Get the InputStream from the relative path and classloader
+     * @param path
+     * @param classLoader
+     * @return
+     */
     private static InputStream getInputStream(String path, ClassLoader classLoader) {
+        if (log.isDebugEnabled()) {
+            log.debug("Start getInputStream with ("
+                      + path + ") and classloader (" + classLoader  + ")");
+        }
         InputStream configStream = classLoader.getResourceAsStream(path);
         if (configStream == null) {
             // try another classloader
             ClassLoader cl = System.class.getClassLoader();
+            if (log.isDebugEnabled()) {
+                log.debug("Attempting with System classloader (" + cl + ")");
+            }
             if (cl != null) {
                 configStream = cl.getResourceAsStream(path);
             }
@@ -323,6 +374,10 @@
         if (configStream == null) {
             // and another classloader
             ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            if (log.isDebugEnabled()) {
+                log.debug("Attempting with current thread " +
+                            "classloader (" + cl + ")");
+            }
             if (cl != null) {
                 configStream = cl.getResourceAsStream(path);
             }



Mime
View raw message