[jboss-remoting-commits] JBoss Remoting SVN: r5009 - remoting2/branches/2.x/src/main/org/jboss/remoting/serialization/impl/java.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Apr 14 06:17:57 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-04-14 06:17:57 -0400 (Tue, 14 Apr 2009)
New Revision: 5009

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

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/serialization/impl/java/ClearableObjectOutputStream.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/serialization/impl/java/ClearableObjectOutputStream.java	2009-04-14 10:17:38 UTC (rev 5008)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/serialization/impl/java/ClearableObjectOutputStream.java	2009-04-14 10:17:57 UTC (rev 5009)
@@ -26,6 +26,9 @@
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
 import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 import org.jboss.logging.Logger;
 import org.jboss.remoting.util.SecurityUtility;
@@ -47,7 +50,7 @@
    {
       try
       {
-         clearMethod = SecurityUtility.getDeclaredMethod(ObjectOutputStream.class, "clear", new Class[]{});
+         clearMethod = getDeclaredMethod(ObjectOutputStream.class, "clear", new Class[]{});
       }
       catch (SecurityException e)
       {
@@ -75,5 +78,33 @@
           log.error(e.getMessage(), e);
       }
    }
+   
+   static private Method getDeclaredMethod(final Class c, final String name, final Class[] parameterTypes)
+   throws NoSuchMethodException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         Method m = c.getDeclaredMethod(name, parameterTypes);
+         m.setAccessible(true);
+         return m;
+      }
+
+      try
+      {
+         return (Method) AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws NoSuchMethodException
+            {
+               Method m = c.getDeclaredMethod(name, parameterTypes);
+               m.setAccessible(true);
+               return m;
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (NoSuchMethodException) e.getCause();
+      }
+   }
 }
 




More information about the jboss-remoting-commits mailing list