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

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu Mar 20 21:37:03 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-03-20 21:37:02 -0400 (Thu, 20 Mar 2008)
New Revision: 3705

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java
Log:
JBREM-934: Put Socket creation in AccessController.doPrivileged() call.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java	2008-03-21 01:36:12 UTC (rev 3704)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RemotingRMIClientSocketFactory.java	2008-03-21 01:37:02 UTC (rev 3705)
@@ -28,6 +28,9 @@
 import java.net.Socket;
 import java.net.UnknownHostException;
 import java.rmi.server.RMIClientSocketFactory;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -39,6 +42,7 @@
 import org.jboss.remoting.InvokerLocator;
 import org.jboss.remoting.Remoting;
 import org.jboss.remoting.Version;
+import org.jboss.remoting.loading.ClassByteClassLoader;
 
 
 /**
@@ -168,13 +172,13 @@
     * @return new socket
     * @throws IOException if there is a problem creating a socket
     */
-   public Socket createSocket(String host, int port) throws IOException
+   public Socket createSocket(String host, final int port) throws IOException
    {
       // If invokerLocator isn't in configMaps, an RMICLientInvoker has not been created
       // yet.  This call was probably made by an RMI thread, and is premature.  Best attempt
       // is to return a vanilla socket.
 
-      String effectiveHost = hostName != null ? hostName : host;
+      final String effectiveHost = hostName != null ? hostName : host;
       if (log.isTraceEnabled())
          log.trace("host: " + host + ", effective host: " + effectiveHost + ", port: " + port);
       
@@ -193,20 +197,52 @@
                log.warn(Thread.currentThread().getName() + " unrecognized invoker locator: " + invokerLocator);
                log.warn("unable to retrieve socket factory: returning plain socket");
             }
-            return new Socket(effectiveHost, port);
+         
+            Socket socket = null;
+            try
+            {
+                socket = (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+                {
+                   public Object run() throws Exception
+                   {
+                      return new Socket(effectiveHost, port);
+                   }
+                });
+            }
+            catch (PrivilegedActionException e)
+            {
+               throw (IOException) e.getCause();
+            }
+            return socket;
          }
+         
          socketFactory = retrieveSocketFactory(holder);
       }
 
       Socket socket = null;
       
-      if(socketFactory != null)
+      try
       {
-         socket = socketFactory.createSocket(effectiveHost, port);
+         socket = (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               Socket s = null;
+               if(socketFactory != null)
+               {
+                  s = socketFactory.createSocket(effectiveHost, port);
+               }
+               else
+               {
+                  s = new Socket(effectiveHost, port);
+               }
+               return s;
+            }
+         });
       }
-      else
+      catch (PrivilegedActionException e)
       {
-         socket = new Socket(effectiveHost, port);
+         throw (IOException) e.getCause();
       }
 
       socket.setSoTimeout(timeout);




More information about the jboss-remoting-commits mailing list