Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:13:24 -0400 (Tue, 14 Apr 2009)
New Revision: 5000
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java 2009-04-14
10:13:00 UTC (rev 4999)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/multicast/MulticastDetector.java 2009-04-14
10:13:24 UTC (rev 5000)
@@ -35,6 +35,7 @@
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.SocketAddress;
+import java.net.UnknownHostException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -158,11 +159,11 @@
{
if(addr == null)
{
- addr = SecurityUtility.getAddressByName(defaultIP);
+ addr = getAddressByName(defaultIP);
}
// check to see if we're running on a machine with loopback and no NIC
- InetAddress localHost = SecurityUtility.getLocalHost();
+ InetAddress localHost = getLocalHost();
if(bindAddr == null &&
localHost.getHostAddress().equals("127.0.0.1"))
{
// use this to bind so multicast will work w/o network
@@ -370,4 +371,64 @@
}
}
}
+
+ 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();
+ }
+ }
}
Show replies by date