Author: ron.sigal(a)jboss.com
Date: 2008-03-20 21:33:28 -0400 (Thu, 20 Mar 2008)
New Revision: 3702
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java
Log:
JBREM-934: Put ServerSocket creation in AccessController.doPrivileged() call.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java 2008-03-21
01:32:54 UTC (rev 3701)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java 2008-03-21
01:33:28 UTC (rev 3702)
@@ -24,7 +24,12 @@
import java.net.ServerSocket;
import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.security.SecureRandom;
import org.jboss.logging.Logger;
@@ -55,20 +60,31 @@
* @param p
* @return true if available, false if already in use
*/
- public static boolean checkPort(int p, String host)
+ public static boolean checkPort(final int p, String host)
{
boolean available = true;
ServerSocket socket = null;
try
{
- InetAddress inetAddress = InetAddress.getByName(host);
- socket = new ServerSocket(p, 0, inetAddress);
+ final InetAddress inetAddress = InetAddress.getByName(host);
+
+ socket = (ServerSocket) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return new ServerSocket(p, 0, inetAddress);
+ }
+ });
}
- catch(IOException e)
+ catch (PrivilegedActionException e)
{
- log.debug("port " + p + " already in use. Will try
another.", e);
+ log.debug("port " + p + " already in use. Will try
another.", e.getCause());
available = false;
}
+ catch (UnknownHostException e)
+ {
+ log.warn("unknown host: " + host);
+ }
finally
{
if(socket != null)
@@ -83,8 +99,8 @@
}
}
}
+
return available;
-
}
/**
Show replies by date