Index: java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java =================================================================== --- java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java (revision 1486077) +++ java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java (working copy) @@ -21,7 +21,10 @@ import java.io.Serializable; import java.lang.management.ManagementFactory; import java.net.MalformedURLException; +import java.net.UnknownHostException; import java.net.Socket; +import java.net.ServerSocket; +import java.net.InetAddress; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.server.RMIClientSocketFactory; @@ -61,6 +64,7 @@ protected static final StringManager sm = StringManager.getManager(Constants.Package); + protected String rmiBindAddress = null; protected int rmiRegistryPortPlatform = -1; protected int rmiServerPortPlatform = -1; protected boolean rmiSSL = true; @@ -76,6 +80,22 @@ protected JMXConnectorServer csPlatform = null; /** + * Get the inet address on which the Platform RMI server is exported. + * @return The textual representation of inet address + */ + public String getRmiBindAddress() { + return rmiBindAddress; + } + + /** + * Set the inet address on which the Platform RMI server is exported. + * @param theRmiBindAddress The textual representation of inet address + */ + public void setRmiBindAddress(String theRmiBindAddress) { + rmiBindAddress = theRmiBindAddress; + } + + /** * Get the port on which the Platform RMI server is exported. This is the * port that is normally chosen by the RMI stack. * @return The port number @@ -192,7 +212,18 @@ csf = new SslRMIClientSocketFactory(); ssf = new SslRMIServerSocketFactory(ciphers, protocols, clientAuth); + + if (rmiBindAddress != null) { + log.warn("Ignoring rmiBindAddress as incompatible with rmiSSL"); } + } else if (rmiBindAddress != null) { + // Force server bind address if required + try { + ssf = new RmiServerBindSocketFactory(InetAddress.getByName(rmiBindAddress)); + } catch (UnknownHostException e) { + log.error("Invalid bind address: " + rmiBindAddress, e); + } + } // Force the use of local ports if required if (useLocalPorts) { @@ -219,7 +250,7 @@ // Create the Platform server csPlatform = createServer("Platform", rmiRegistryPortPlatform, - rmiServerPortPlatform, env, + rmiServerPortPlatform, env, csf, ssf, ManagementFactory.getPlatformMBeanServer()); } else if (Lifecycle.STOP_EVENT == event.getType()) { @@ -229,11 +260,11 @@ private JMXConnectorServer createServer(String serverName, int theRmiRegistryPort, int theRmiServerPort, - HashMap theEnv, MBeanServer theMBeanServer) { + HashMap theEnv, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, MBeanServer theMBeanServer) { // Create the RMI registry try { - LocateRegistry.createRegistry(theRmiRegistryPort); + LocateRegistry.createRegistry(theRmiRegistryPort, csf, ssf); } catch (RemoteException e) { log.error(sm.getString( "jmxRemoteLifecycleListener.createRegistryFailed", @@ -311,4 +342,18 @@ } + + public static class RmiServerBindSocketFactory + implements RMIServerSocketFactory { + private final InetAddress bindAddress; + + public RmiServerBindSocketFactory(InetAddress address) { + bindAddress = address; } + + public ServerSocket createServerSocket(int port) throws IOException { + return new ServerSocket(port, 0, bindAddress); + } + + } +}