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

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu Mar 20 21:35:50 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-03-20 21:35:50 -0400 (Thu, 20 Mar 2008)
New Revision: 3703

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
Log:
JBREM-934: Put ServerSocket creation, Socket creation, and ServerSocket.accept() in AccessController.doPrivileged() calls.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java	2008-03-21 01:33:28 UTC (rev 3702)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java	2008-03-21 01:35:50 UTC (rev 3703)
@@ -28,6 +28,9 @@
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -202,7 +205,7 @@
          while (it.hasNext())
          {
             ServerSocket ss = (ServerSocket) it.next();
-            InetAddress host = ss.getInetAddress();
+            final InetAddress host = ss.getInetAddress();
             int secondaryBindPort = -1;
             if (secondaryBindPorts.size() > i)
             {
@@ -219,13 +222,30 @@
             }
             
             ServerSocket secondaryServerSocket = null;
-            if (serverSocketFactory != null)
+            final int finalBindPort = secondaryBindPort;
+            
+            try
             {
-               secondaryServerSocket = serverSocketFactory.createServerSocket(secondaryBindPort, 0, host);
+               secondaryServerSocket = (ServerSocket) AccessController.doPrivileged( new PrivilegedExceptionAction()
+               {
+                  public Object run() throws Exception
+                  {
+                     ServerSocket ss = null;
+                     if (serverSocketFactory != null)
+                     {
+                        ss = serverSocketFactory.createServerSocket(finalBindPort, 0, host);
+                     }
+                     else
+                     {
+                        ss = new ServerSocket(finalBindPort, 0, host);
+                     }
+                     return ss;
+                  }
+               });
             }
-            else
+            catch (PrivilegedActionException e)
             {
-               secondaryServerSocket = new ServerSocket(secondaryBindPort, 0, host);
+               throw (IOException) e.getCause();
             }
             
             ss = checkSecondaryServerSocketWrapper(secondaryServerSocket);
@@ -356,20 +376,31 @@
 
       Socket socket = null;
       IOException savedException = null;
+      final String finalHost = locator.getHost();
+      final int finalPort = locator.getPort();
       
       for (int i = 0; i < socketCreationRetries; i++)
       {
          try
          {
-            if (socketFactory != null)
-               socket = socketFactory.createSocket(host, port);
-            else
-               socket = new Socket(host, port);
+            socket = (Socket) AccessController.doPrivileged( new PrivilegedExceptionAction()
+            {
+               public Object run() throws Exception
+               {
+                  Socket s = null;
+                  if (socketFactory != null)
+                     s = socketFactory.createSocket(finalHost, finalPort);
+                  else
+                     s = new Socket(finalHost, finalPort);
+                  return s;
+               }
+            });
          }
-         catch (IOException e)
+         catch (PrivilegedActionException e)
          {
-            log.debug("Error creating a control socket", e);
-            savedException = e;
+            IOException ioe = (IOException) e.getCause();
+            log.debug("Error creating a control socket", ioe);
+            savedException = ioe;
          }
          
          if (socket != null)
@@ -934,20 +965,31 @@
                      InvokerLocator locator = (InvokerLocator) listenerIdToInvokerLocatorMap.get(listenerId);
                      
                      IOException savedException = null;
-                     
+                     final String finalHost = locator.getHost();
+                     final int finalPort = locator.getPort();
+
                      for (int i = 0; i < socketCreationRetries; i++)
                      {
                         try
                         {
-                           if (socketFactory != null)
-                              socket = socketFactory.createSocket(locator.getHost(), locator.getPort());
-                           else
-                              socket = new Socket(locator.getHost(), locator.getPort());
+                           socket = (Socket) AccessController.doPrivileged( new PrivilegedExceptionAction()
+                           {
+                              public Object run() throws Exception
+                              {
+                                 Socket s = null;
+                                 if (socketFactory != null)
+                                    s = socketFactory.createSocket(finalHost, finalPort);
+                                 else
+                                    s = new Socket(finalHost, finalPort);
+                                 return s;
+                              }
+                           });
                         }
-                        catch (IOException e)
+                        catch (PrivilegedActionException e)
                         {
-                           log.debug("Error creating a socket", e);
-                           savedException = e;
+                           IOException ioe = (IOException) e.getCause();
+                           log.debug("Error creating a socket", ioe);
+                           savedException = ioe;
                         }
                         
                         if (socket != null)
@@ -1073,7 +1115,22 @@
          {
             try
             {
-               Socket socket = secondaryServerSocket.accept();
+               Socket socket = null;
+               try
+               {
+                   socket = (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+                   {
+                      public Object run() throws Exception
+                      {
+                          return secondaryServerSocket.accept();
+                      }
+                   });
+               }
+               catch (PrivilegedActionException e)
+               {
+                   throw (IOException) e.getCause();
+               }
+               
                if (log.isTraceEnabled()) log.trace("accepted: " + socket);
                DataInputStream dis = new DataInputStream(socket.getInputStream());
                int action = dis.read();




More information about the jboss-remoting-commits mailing list