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

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri Apr 11 21:12:50 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-04-11 21:12:49 -0400 (Fri, 11 Apr 2008)
New Revision: 3948

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/socketfactory/CreationListenerServerSocket.java
Log:
JBREM-934: (1) Creates reusable PriviligedExceptionAction; (2) renamed SystemUtility SecurityUtility.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/socketfactory/CreationListenerServerSocket.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/socketfactory/CreationListenerServerSocket.java	2008-04-12 01:11:22 UTC (rev 3947)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/socketfactory/CreationListenerServerSocket.java	2008-04-12 01:12:49 UTC (rev 3948)
@@ -32,6 +32,8 @@
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
+import org.jboss.remoting.util.SecurityUtility;
+
 /** 
  * A CreationListenerServerSocket wraps a ServerSocket to which it delegates
  * calls to accept(), and when the wrapped ServerSocket creates a Socket in 
@@ -47,6 +49,7 @@
 {
    private ServerSocket serverSocket;
    private SocketCreationListener listener;
+   private PrivilegedExceptionAction action;
 
    
    public CreationListenerServerSocket(ServerSocket serverSocket, SocketCreationListener listener)
@@ -54,6 +57,14 @@
    {
       this.serverSocket = serverSocket;
       this.listener = listener;
+      
+      action = new PrivilegedExceptionAction()
+      {
+         public Object run() throws Exception
+         {
+             return CreationListenerServerSocket.this.serverSocket.accept();
+         }
+      };
    }
 
   
@@ -83,34 +94,36 @@
    
    public void bind(SocketAddress endpoint) throws IOException
    {
-      serverSocket.bind(endpoint);
+      SecurityUtility.bind(serverSocket, endpoint);
    }
    
    
    public void bind(SocketAddress endpoint, int backlog) throws IOException
    {
-      serverSocket.bind(endpoint, backlog);
+      SecurityUtility.bind(serverSocket, endpoint, backlog);
    }
    
    
    public Socket accept() throws IOException
    {  
       Socket socket = null;
-      try
+      
+      if (SecurityUtility.skipAccessControl())
       {
-          socket = (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
-          {
-             public Object run() throws Exception
-             {
-                 return serverSocket.accept();
-             }
-          });
+         socket = serverSocket.accept();
       }
-      catch (PrivilegedActionException e)
+      else
       {
-          throw (IOException) e.getCause();
+         try
+         {
+            socket = (Socket)AccessController.doPrivileged(action);
+         }
+         catch (PrivilegedActionException e)
+         {
+            throw (IOException) e.getCause();
+         }
       }
-      
+
       listener.socketCreated(socket, serverSocket);
       return socket;
    }




More information about the jboss-remoting-commits mailing list