View | Details | Raw Unified | Return to bug 55017
Collapse All | Expand All

(-)java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java (-3 / +50 lines)
Lines 21-27 Link Here
21
import java.io.Serializable;
21
import java.io.Serializable;
22
import java.lang.management.ManagementFactory;
22
import java.lang.management.ManagementFactory;
23
import java.net.MalformedURLException;
23
import java.net.MalformedURLException;
24
import java.net.UnknownHostException;
24
import java.net.Socket;
25
import java.net.Socket;
26
import java.net.ServerSocket;
27
import java.net.InetAddress;
25
import java.rmi.RemoteException;
28
import java.rmi.RemoteException;
26
import java.rmi.registry.LocateRegistry;
29
import java.rmi.registry.LocateRegistry;
27
import java.rmi.server.RMIClientSocketFactory;
30
import java.rmi.server.RMIClientSocketFactory;
Lines 61-66 Link Here
61
    protected static final StringManager sm =
64
    protected static final StringManager sm =
62
        StringManager.getManager(Constants.Package);
65
        StringManager.getManager(Constants.Package);
63
66
67
    protected String rmiBindAddress = null;
64
    protected int rmiRegistryPortPlatform = -1;
68
    protected int rmiRegistryPortPlatform = -1;
65
    protected int rmiServerPortPlatform = -1;
69
    protected int rmiServerPortPlatform = -1;
66
    protected boolean rmiSSL = true;
70
    protected boolean rmiSSL = true;
Lines 76-81 Link Here
76
    protected JMXConnectorServer csPlatform = null;
80
    protected JMXConnectorServer csPlatform = null;
77
    
81
    
78
    /**
82
    /**
83
     * Get the inet address on which the Platform RMI server is exported.
84
     * @return The textual representation of inet address
85
     */
86
    public String getRmiBindAddress() {
87
        return rmiBindAddress;
88
    }
89
90
    /**
91
     * Set the inet address on which the Platform RMI server is exported.
92
     * @param theRmiBindAddress The textual representation of inet address
93
     */
94
    public void setRmiBindAddress(String theRmiBindAddress) {
95
        rmiBindAddress = theRmiBindAddress;
96
    }
97
98
    /**
79
     * Get the port on which the Platform RMI server is exported. This is the
99
     * Get the port on which the Platform RMI server is exported. This is the
80
     * port that is normally chosen by the RMI stack.
100
     * port that is normally chosen by the RMI stack.
81
     * @return The port number
101
     * @return The port number
Lines 189-199 Link Here
189
209
190
            // Configure SSL for RMI connection if required
210
            // Configure SSL for RMI connection if required
191
            if (rmiSSL) {
211
            if (rmiSSL) {
212
                if (rmiBindAddress != null) {
213
                    throw new IllegalStateException("rmiBindAddress is incompatible with com.sun.management.jmxremote.ssl = true");
214
                }
215
192
                csf = new SslRMIClientSocketFactory();
216
                csf = new SslRMIClientSocketFactory();
193
                ssf = new SslRMIServerSocketFactory(ciphers, protocols,
217
                ssf = new SslRMIServerSocketFactory(ciphers, protocols,
194
                            clientAuth);
218
                            clientAuth);
195
            }
219
            }
196
            
220
            
221
            // Force server bind address if required
222
            if (rmiBindAddress != null) {
223
                try {
224
                    ssf = new RmiServerBindSocketFactory(InetAddress.getByName(rmiBindAddress));
225
                } catch (UnknownHostException e) {
226
                    log.error("Invalid bind address: " + rmiBindAddress, e);
227
                }
228
            }
229
197
            // Force the use of local ports if required
230
            // Force the use of local ports if required
198
            if (useLocalPorts) {
231
            if (useLocalPorts) {
199
                csf = new RmiClientLocalhostSocketFactory(csf);
232
                csf = new RmiClientLocalhostSocketFactory(csf);
Lines 219-225 Link Here
219
252
220
            // Create the Platform server
253
            // Create the Platform server
221
            csPlatform = createServer("Platform", rmiRegistryPortPlatform,
254
            csPlatform = createServer("Platform", rmiRegistryPortPlatform,
222
                    rmiServerPortPlatform, env,
255
                    rmiServerPortPlatform, env, csf, ssf,
223
                    ManagementFactory.getPlatformMBeanServer());
256
                    ManagementFactory.getPlatformMBeanServer());
224
            
257
            
225
        } else if (Lifecycle.STOP_EVENT == event.getType()) {
258
        } else if (Lifecycle.STOP_EVENT == event.getType()) {
Lines 229-239 Link Here
229
262
230
    private JMXConnectorServer createServer(String serverName,
263
    private JMXConnectorServer createServer(String serverName,
231
            int theRmiRegistryPort, int theRmiServerPort,
264
            int theRmiRegistryPort, int theRmiServerPort,
232
            HashMap<String,Object> theEnv, MBeanServer theMBeanServer) {
265
            HashMap<String,Object> theEnv, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, MBeanServer theMBeanServer) {
233
        
266
        
234
        // Create the RMI registry
267
        // Create the RMI registry
235
        try {
268
        try {
236
            LocateRegistry.createRegistry(theRmiRegistryPort);
269
            LocateRegistry.createRegistry(theRmiRegistryPort, csf, ssf);
237
        } catch (RemoteException e) {
270
        } catch (RemoteException e) {
238
            log.error(sm.getString(
271
            log.error(sm.getString(
239
                    "jmxRemoteLifecycleListener.createRegistryFailed",
272
                    "jmxRemoteLifecycleListener.createRegistryFailed",
Lines 311-314 Link Here
311
344
312
        
345
        
313
    }
346
    }
347
348
    public static class RmiServerBindSocketFactory
349
    implements RMIServerSocketFactory {
350
        private final InetAddress bindAddress;
351
352
        public RmiServerBindSocketFactory(InetAddress address) {
353
            bindAddress = address;
314
}
354
}
355
356
        public ServerSocket createServerSocket(int port) throws IOException  {
357
            return new ServerSocket(port, 0, bindAddress);
358
        }
359
360
    }
361
}

Return to bug 55017