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

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Apr 14 06:18:35 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-04-14 06:18:34 -0400 (Tue, 14 Apr 2009)
New Revision: 5011

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

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/stream/StreamServer.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/stream/StreamServer.java	2009-04-14 10:18:15 UTC (rev 5010)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/stream/StreamServer.java	2009-04-14 10:18:34 UTC (rev 5011)
@@ -117,16 +117,16 @@
    private String getLocatorURI() throws IOException
    {
       // check for system properties for locator values
-      transport = SecurityUtility.getSystemProperty(STREAM_TRANSPORT_KEY, transport);
+      transport = getSystemProperty(STREAM_TRANSPORT_KEY, transport);
       try
       {
-         host = SecurityUtility.getLocalHostName();
+         host = getLocalHostName();
       }
       catch(UnknownHostException e)
       {
          try
          {
-            InetAddress localAddress = SecurityUtility.getLocalHost();
+            InetAddress localAddress = getLocalHost();
             host = localAddress.getHostAddress();
          }
          catch(UnknownHostException e1)
@@ -135,9 +135,9 @@
          }
       }
 
-      host = SecurityUtility.getSystemProperty(STREAM_HOST_KEY, host);
+      host = getSystemProperty(STREAM_HOST_KEY, host);
       String defaultPort = "" + PortUtil.findFreePort(host);
-      String sPort = SecurityUtility.getSystemProperty(STREAM_PORT_KEY, defaultPort);
+      String sPort = getSystemProperty(STREAM_PORT_KEY, defaultPort);
       
       try
       {
@@ -314,4 +314,97 @@
       }
    }
 
+   static private String getSystemProperty(final String name, final String defaultValue)
+   {
+      if (SecurityUtility.skipAccessControl())
+         return System.getProperty(name, defaultValue);
+         
+      String value = null;
+      try
+      {
+         value = (String)AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               return System.getProperty(name, defaultValue);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (RuntimeException) e.getCause();
+      }
+      
+      return value;
+   }
+   
+   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 String getLocalHostName() throws UnknownHostException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return getLocalHost().getHostName();
+      }
+
+      try
+      {
+         return (String) AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws IOException
+            {
+               InetAddress address = null;
+               try
+               {
+                  address = InetAddress.getLocalHost();
+               }
+               catch (IOException e)
+               {
+                  address = InetAddress.getByName("127.0.0.1");
+               }
+               
+               return address.getHostName();
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (UnknownHostException) e.getCause();
+      }
+   }
 }
\ No newline at end of file




More information about the jboss-remoting-commits mailing list