Author: ron.sigal(a)jboss.com
Date: 2010-07-22 11:52:45 -0400 (Thu, 22 Jul 2010)
New Revision: 5920
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/AbstractDetector.java
Log:
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/AbstractDetector.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/AbstractDetector.java 2010-07-22
15:52:22 UTC (rev 5919)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/AbstractDetector.java 2010-07-22
15:52:45 UTC (rev 5920)
@@ -32,6 +32,7 @@
import org.jboss.remoting.network.NetworkRegistryFinder;
import org.jboss.remoting.network.NetworkRegistryMBean;
import org.jboss.remoting.network.NetworkRegistryWrapper;
+import org.jboss.remoting.util.SecurityUtility;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -40,8 +41,12 @@
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -80,7 +85,81 @@
private boolean acceptLocal = false;
private Map config;
+
+
+ private static final InetAddress LOCAL_HOST;
+ static
+ {
+ try
+ {
+ LOCAL_HOST = (InetAddress) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws UnknownHostException
+ {
+ try
+ {
+ return InetAddress.getLocalHost();
+ }
+ catch (UnknownHostException e)
+ {
+ return InetAddress.getByName("127.0.0.1");
+ }
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ log.debug(AbstractDetector.class.getName() + " unable to get local host
address", e.getCause());
+ throw new ExceptionInInitializerError(e.getCause());
+ }
+ catch (SecurityException e)
+ {
+ log.debug(AbstractDetector.class.getName() + " unable to get local host
address", e);
+ throw e;
+ }
+ }
+
+ static protected InetAddress getLocalHost() throws UnknownHostException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return doGetLocalHost();
+ }
+
+ try
+ {
+ return (InetAddress) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws UnknownHostException
+ {
+ return doGetLocalHost();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (UnknownHostException) e.getCause();
+ }
+ }
+
+ static protected InetAddress doGetLocalHost() throws UnknownHostException
+ {
+ if (LOCAL_HOST != null)
+ {
+ return LOCAL_HOST;
+ }
+
+ try
+ {
+ return InetAddress.getLocalHost();
+ }
+ catch (UnknownHostException e)
+ {
+ return InetAddress.getByName("127.0.0.1");
+ }
+ }
+
public AbstractDetector()
{
this(null);
Show replies by date