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

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Apr 14 06:11:02 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-04-14 06:11:02 -0400 (Tue, 14 Apr 2009)
New Revision: 4996

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

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java	2009-04-14 10:10:28 UTC (rev 4995)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java	2009-04-14 10:11:02 UTC (rev 4996)
@@ -55,6 +55,10 @@
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -1188,11 +1192,11 @@
       InetAddress addr = null;
       if(locatorhost != null)
       {
-         addr = SecurityUtility.getAddressByName(locatorhost);
+         addr = getAddressByName(locatorhost);
       }
       else
       {
-         addr = SecurityUtility.getLocalHost();
+         addr = getLocalHost();
       }
 
       int port = locator.getPort();
@@ -1209,7 +1213,7 @@
          if(clientConnectAddress != null)
          {
             // can't use uri address, as is for client only
-            serverBindAddress = SecurityUtility.getLocalHost().getHostAddress();
+            serverBindAddress = getLocalHost().getHostAddress();
          }
          else
          {
@@ -2124,5 +2128,64 @@
          return handleObject;
       }
    }
+   
+   static private InetAddress getLocalHost() throws UnknownHostException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         try
+         {
+            return InetAddress.getLocalHost();
+         }
+         catch (IOException e)
+         {
+            return InetAddress.getByName("127.0.0.1");
+         }
+      }
 
+      try
+      {
+         return (InetAddress) AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws IOException
+            {
+               try
+               {
+                  return InetAddress.getLocalHost();
+               }
+               catch (IOException e)
+               {
+                  return InetAddress.getByName("127.0.0.1");
+               }
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (UnknownHostException) e.getCause();
+      }
+   }
+   
+   static private InetAddress getAddressByName(final String host) throws UnknownHostException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return InetAddress.getByName(host);
+      }
+      
+      try
+      {
+         return (InetAddress)AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws IOException
+            {
+               return InetAddress.getByName(host);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (UnknownHostException) e.getCause();
+      }
+   }
 }




More information about the jboss-remoting-commits mailing list