[jboss-remoting-commits] JBoss Remoting SVN: r4995 - remoting2/branches/2.x/src/main/org/jboss/remoting.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Apr 14 06:10:28 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-04-14 06:10:28 -0400 (Tue, 14 Apr 2009)
New Revision: 4995

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java	2009-04-14 10:09:59 UTC (rev 4994)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java	2009-04-14 10:10:28 UTC (rev 4995)
@@ -13,6 +13,10 @@
 import org.jboss.util.id.GUID;
 
 import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -120,7 +124,7 @@
          // class loader.  This allows to load remoting classes as well as user's
          // classes.  If possible, will simply reset context classloader on existing
          // RemotingClassLoader.
-         final ClassLoader contextClassLoader = SecurityUtility.getContextClassLoader(Thread.currentThread());
+         final ClassLoader contextClassLoader = getContextClassLoader(Thread.currentThread());
          if (unmarshaller instanceof UpdateableClassloaderUnMarshaller)
          {
             UpdateableClassloaderUnMarshaller uclum = (UpdateableClassloaderUnMarshaller) unmarshaller;
@@ -132,13 +136,13 @@
             }
             else
             {
-               rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirstClassLoading);
+               rcl = createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirstClassLoading);
                unmarshaller.setClassLoader(rcl);
             }
          }
          else
          {
-            rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirstClassLoading);
+            rcl = createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirstClassLoading);
             unmarshaller.setClassLoader(rcl);  
          }
       }
@@ -364,13 +368,13 @@
 
    public void setUnMarshaller(UnMarshaller unmarshaller)
    {
-      ClassLoader classLoader = SecurityUtility.getContextClassLoader(Thread.currentThread());
+      ClassLoader classLoader = getContextClassLoader(Thread.currentThread());
       unmarshallers.put(classLoader, unmarshaller);
    }
 
    public UnMarshaller getUnMarshaller()
    {
-      ClassLoader classLoader = SecurityUtility.getContextClassLoader(Thread.currentThread());
+      ClassLoader classLoader = getContextClassLoader(Thread.currentThread());
       return (UnMarshaller)unmarshallers.get(classLoader);
    }
    
@@ -545,7 +549,7 @@
       if(flag == null)
       {
          // Fallback to the system property
-         flag = SecurityUtility.getSystemProperty(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP);
+         flag = getSystemProperty(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP);
       }
       boolean parentFirst = true;
       if (flag != null)
@@ -628,5 +632,61 @@
       disconnect();
       super.finalize();
    }
+   
+   static private String getSystemProperty(final String name)
+   {
+      if (SecurityUtility.skipAccessControl())
+         return System.getProperty(name);
+      
+      String value = null;
+      try
+      {
+         value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               return System.getProperty(name);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (RuntimeException) e.getCause();
+      }
+      
+      return value;
+   }
+   
+   static private RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader,
+         final ClassLoader userClassLoader, final boolean parentFirstDelegation)
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
+      }
 
+      return (RemotingClassLoader)AccessController.doPrivileged( new PrivilegedAction()
+      {
+         public Object run()
+         {
+            return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
+         }
+      });
+   }
+   
+   static private ClassLoader getContextClassLoader(final Thread thread)
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return thread.getContextClassLoader();
+      }
+
+      return (ClassLoader) AccessController.doPrivileged( new PrivilegedAction()
+      {
+         public Object run()
+         {
+            return thread.getContextClassLoader();
+         }
+      });
+   }
 }




More information about the jboss-remoting-commits mailing list