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

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri May 16 22:47:01 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-05-16 22:47:01 -0400 (Fri, 16 May 2008)
New Revision: 4193

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
Log:
JBREM-978: Added methods for ServerInvokerServlet.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java	2008-05-17 02:43:14 UTC (rev 4192)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java	2008-05-17 02:47:01 UTC (rev 4193)
@@ -29,6 +29,7 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.HttpURLConnection;
 import java.net.InetAddress;
@@ -50,6 +51,7 @@
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
 
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServer;
@@ -57,12 +59,16 @@
 import javax.management.ObjectName;
 import javax.net.ServerSocketFactory;
 import javax.net.SocketFactory;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.jboss.remoting.Remoting;
 import org.jboss.remoting.security.ServerSocketFactoryMBean;
 import org.jboss.remoting.transport.rmi.RMIServerInvoker;
 import org.jboss.remoting.transport.rmi.RMIServerInvokerInf;
 import org.jboss.remoting.transport.rmi.RemotingRMIClientSocketFactory;
+import org.jboss.remoting.transport.servlet.ServletServerInvokerMBean;
 import org.jboss.serial.io.JBossObjectInputStream;
 import org.jboss.serial.io.JBossObjectOutputStream;
 
@@ -123,6 +129,7 @@
       return skipAccessControl;
    }
    
+   
    ///////////////////////////////////////////////////////////////////////////////////////
    // FilePermission methods
    ///////////////////////////////////////////////////////////////////////////////////////
@@ -354,81 +361,125 @@
    // MBeanPermission methods
    ///////////////////////////////////////////////////////////////////////////////////////
    
-   static public void connect(final Socket socket, final InetSocketAddress address)
-   throws IOException
+   static public MBeanServer createMBeanServer() throws Exception
    {
       if (skipAccessControl)
       {
-         socket.connect(address);
-         return;
+         return MBeanServerFactory.createMBeanServer();
       }
       
       try
       {
-         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         return (MBeanServer) AccessController.doPrivileged( new PrivilegedExceptionAction()
          {
             public Object run() throws Exception
             {
-               socket.connect(address);
-               return null;
+               return MBeanServerFactory.createMBeanServer();
             }
          });
       }
       catch (PrivilegedActionException e)
       {
-         throw (IOException) e.getCause();
+         throw (Exception) e.getCause();
       }   
    }
    
    
-   static public void connect(final Socket socket, final InetSocketAddress address, final int timeout)
-   throws IOException
+   static public ArrayList findMBeanServer(final String agentId)
    {
       if (skipAccessControl)
       {
-         socket.connect(address, timeout);
-         return;
+         return MBeanServerFactory.findMBeanServer(agentId);
       }
       
+      return (ArrayList)AccessController.doPrivileged( new PrivilegedAction()
+      {
+         public Object run()
+         {
+            return MBeanServerFactory.findMBeanServer(agentId);
+         }
+      });
+   }
+   
+   
+   static public Object getMBeanAttribute(final MBeanServer server, final ObjectName objectName, final String attribute)
+   throws Exception
+   {
+      if (skipAccessControl)
+      {
+         return server.getAttribute(objectName, attribute);
+      }
+      
       try
       {
-         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         return AccessController.doPrivileged( new PrivilegedExceptionAction()
          {
             public Object run() throws Exception
             {
-               socket.connect(address, timeout);
-               return null;
+               return server.getAttribute(objectName, attribute);
             }
          });
       }
       catch (PrivilegedActionException e)
       {
-         throw (IOException) e.getCause();
-      }   
+         throw (Exception) e.getCause();
+      }  
    }
    
    
-   static public MBeanServer createMBeanServer() throws Exception
+   static public MBeanServer getPlatformMBeanServer()
+   throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
    {
       if (skipAccessControl)
       {
-         return MBeanServerFactory.createMBeanServer();
+         Class c = null;
+         try
+         {
+            c = Class.forName("java.lang.management.ManagementFactory");
+         }
+         catch (Exception e)
+         {
+            System.out.println("Unable to access java.lang.management.ManagementFactory: must be using jdk 1.4");
+            return null;
+         }
+         Method m = c.getMethod("getPlatformMBeanServer", new Class[] {});
+         MBeanServer s = (MBeanServer) m.invoke(null, new Object[] {});
+         return s;
       }
       
       try
       {
          return (MBeanServer) AccessController.doPrivileged( new PrivilegedExceptionAction()
          {
-            public Object run() throws Exception
+            public Object run()
+            throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
             {
-               return MBeanServerFactory.createMBeanServer();
+               Class c = null;
+               try
+               {
+                  c = Class.forName("java.lang.management.ManagementFactory");
+               }
+               catch (Exception e)
+               {
+                  System.out.println("Unable to access java.lang.management.ManagementFactory: must be using jdk 1.4");
+                  return null;
+               }
+               Method m = c.getMethod("getPlatformMBeanServer", new Class[] {});
+               MBeanServer s = (MBeanServer) m.invoke(null, new Object[] {});
+               return s;
             }
          });
       }
       catch (PrivilegedActionException e)
       {
-         throw (Exception) e.getCause();
-      }   
+        Throwable cause = e.getCause();
+        if (cause instanceof NoSuchMethodException)
+           throw (NoSuchMethodException) cause;
+        else if (cause instanceof IllegalAccessException)
+           throw (IllegalAccessException) cause;
+        else
+           throw (InvocationTargetException) cause;
+      }  
    }
    
    
@@ -457,27 +508,34 @@
    }
    
    
-   static public Object getMBeanAttribute(final MBeanServer server, final ObjectName objectName, final String attribute)
-   throws Exception
+   static public byte[] processRequest(final ServletServerInvokerMBean invoker,
+                                       final HttpServletRequest request,
+                                       final byte[] byteArray,
+                                       final HttpServletResponse response)
+   throws ServletException, IOException
    {
       if (skipAccessControl)
       {
-         return server.getAttribute(objectName, attribute);
+         return invoker.processRequest(request, byteArray, response);
       }
       
       try
       {
-         return AccessController.doPrivileged( new PrivilegedExceptionAction()
+         return (byte[]) AccessController.doPrivileged( new PrivilegedExceptionAction()
          {
-            public Object run() throws Exception
+            public Object run() throws ServletException, IOException
             {
-               return server.getAttribute(objectName, attribute);
+               return invoker.processRequest(request, byteArray, response);
             }
          });
       }
       catch (PrivilegedActionException e)
       {
-         throw (Exception) e.getCause();
+         Throwable cause = e.getCause();
+         if (cause instanceof ServletException)
+            throw (ServletException) cause;
+         else
+            throw (IOException) e.getCause();
       }  
    }
    
@@ -790,6 +848,7 @@
       }
    }
    
+   
    ///////////////////////////////////////////////////////////////////////////////////////
    // SocketPermission methods
    ///////////////////////////////////////////////////////////////////////////////////////
@@ -872,6 +931,60 @@
    }
    
    
+   static public void connect(final Socket socket, final InetSocketAddress address)
+   throws IOException
+   {
+      if (skipAccessControl)
+      {
+         socket.connect(address);
+         return;
+      }
+      
+      try
+      {
+         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               socket.connect(address);
+               return null;
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (IOException) e.getCause();
+      }   
+   }
+   
+   
+   static public void connect(final Socket socket, final InetSocketAddress address, final int timeout)
+   throws IOException
+   {
+      if (skipAccessControl)
+      {
+         socket.connect(address, timeout);
+         return;
+      }
+      
+      try
+      {
+         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               socket.connect(address, timeout);
+               return null;
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (IOException) e.getCause();
+      }   
+   }
+   
+   
    static public void connect(final HttpURLConnection conn) throws IOException
    {
       if (skipAccessControl)




More information about the jboss-remoting-commits mailing list