[jboss-cvs] JBossAS SVN: r68657 - projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dispatch.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 7 14:49:06 EST 2008


Author: adrian at jboss.org
Date: 2008-01-07 14:49:06 -0500 (Mon, 07 Jan 2008)
New Revision: 68657

Added:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dispatch/SecurityActions.java
Modified:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dispatch/InvokeDispatchHelper.java
Log:
Retrieve the classloader in a privileged block when necessary

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dispatch/InvokeDispatchHelper.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dispatch/InvokeDispatchHelper.java	2008-01-07 19:09:50 UTC (rev 68656)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dispatch/InvokeDispatchHelper.java	2008-01-07 19:49:06 UTC (rev 68657)
@@ -70,10 +70,11 @@
          int size = params.size();
          signature = Configurator.getParameterTypes(log.isTraceEnabled(), params);
          // TODO - is this ok for non-POJO targets?
+         ClassLoader classLoader = SecurityActions.getClassLoader(context);
          if (target != null)
          {
             MethodInfo methodInfo = Configurator.findMethodInfo(configurator.getClassInfo(target.getClass()), methodName, signature);
-            parameters = Configurator.getParameters(log.isTraceEnabled(), context.getClassLoader(), methodInfo.getParameterTypes(), params);
+            parameters = Configurator.getParameters(log.isTraceEnabled(), classLoader, methodInfo.getParameterTypes(), params);
             // add some more info, if not yet set
             for(int i = 0; i < size; i++)
             {
@@ -86,7 +87,6 @@
          else
          {
             parameters = new Object[size];
-            ClassLoader classLoader = context.getClassLoader();
             for (int i = 0; i < size; i++)
             {
                ParameterMetaData pmd = params.get(i);

Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dispatch/SecurityActions.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dispatch/SecurityActions.java	                        (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dispatch/SecurityActions.java	2008-01-07 19:49:06 UTC (rev 68657)
@@ -0,0 +1,81 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.kernel.plugins.dispatch;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
+
+/**
+ * SecurityActions.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+   public static ClassLoader getClassLoader(final InvokeDispatchContext context) throws Throwable
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return context.getClassLoader();
+      }
+      else
+      {
+         try
+         {
+            return AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+            {
+                public ClassLoader run() throws Exception
+                {
+                   try
+                   {
+                      return context.getClassLoader();
+                   }
+                   catch (RuntimeException e)
+                   {
+                      throw e;
+                   }
+                   catch (Exception e)
+                   {
+                      throw e;
+                   }
+                   catch (Error e)
+                   {
+                      throw e;
+                   }
+                   catch (Throwable e)
+                   {
+                      throw new RuntimeException("Error retrieving classloader", e);
+                   }
+                }
+            });
+         }
+         catch (PrivilegedActionException e)
+         {
+            throw e.getCause();
+         }
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list