public JmxTransRMIClientSocketFactory(int timeoutMillis, boolean ssl){ this.timeoutMillis = timeoutMillis; this.rmiClientSocketFactory = ssl ? new SslRMIClientSocketFactory() : RMISocketFactory.getDefaultSocketFactory(); }
/** * Return the JVM-level configured {@code RMISocketFactory}. * <p> * If a global socket factory has been set via the * {@link RMISocketFactory#setSocketFactory(RMISocketFactory)} method then * that factory will be returned. Otherwise the default socket factory as * returned by {@link RMISocketFactory#getDefaultSocketFactory()} is used * instead. * * @return the configured @{code {@link RMISocketFactory} */ public static RMISocketFactory getConfiguredRMISocketFactory() { RMISocketFactory globalSocketFactory = RMISocketFactory.getSocketFactory(); if (globalSocketFactory == null) { return RMISocketFactory.getDefaultSocketFactory(); } else { return globalSocketFactory; } } }
/** * Programmatically starts a JMX server. * * @param port * port server should listen on. * @param allowConnections * allows restriction of connections to those from "localhost" * only. */ public static void startLocalJMXServer(final int port, final AllowConnections allowConnections) throws IOException, MalformedURLException, RemoteException { final RMISocketFactory serverSocketFactory = allowConnections == AllowConnections.ALL ? RMISocketFactory.getDefaultSocketFactory() : new LocalhostRMIServerSocketFactory(); LocateRegistry.createRegistry(port, RMISocketFactory.getDefaultSocketFactory(), serverSocketFactory); final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + port + "/jmxrmi"); final JMXConnectorServer rmiServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); rmiServer.start(); }
public Socket createSocket(String host, int port) throws IOException { Socket s = RMISocketFactory.getDefaultSocketFactory(). createSocket(this.host, this.port); return s; } public boolean equals(Object o) {
private RMIClientSocketFactory getRMIClientSocketFactory() { if (Boolean.parseBoolean(System.getProperty("ssl.enable"))) return new SslRMIClientSocketFactory(); else return RMISocketFactory.getDefaultSocketFactory(); }
private RMIClientSocketFactory getRMIClientSocketFactory() { if (Boolean.parseBoolean(System.getProperty("ssl.enable"))) return new SslRMIClientSocketFactory(); else return RMISocketFactory.getDefaultSocketFactory(); }
@Override public Socket createSocket(final String host, final int port) throws IOException { return RMISocketFactory.getDefaultSocketFactory().createSocket(host, port); }
public JmxTransRMIClientSocketFactory(int timeoutMillis, boolean ssl){ this.timeoutMillis = timeoutMillis; this.rmiClientSocketFactory = ssl ? new SslRMIClientSocketFactory() : RMISocketFactory.getDefaultSocketFactory(); }
private RMIClientSocketFactory getRMIClientSocketFactory() throws IOException { if (Boolean.parseBoolean(System.getProperty("ssl.enable"))) return new SslRMIClientSocketFactory(); else return RMISocketFactory.getDefaultSocketFactory(); }
private RMIClientSocketFactory getRMIClientSocketFactory() { if (Boolean.parseBoolean(System.getProperty("ssl.enable"))) return new SslRMIClientSocketFactory(); else return RMISocketFactory.getDefaultSocketFactory(); }
@Override public Socket createSocket(final String host, final int port) throws IOException { return RMISocketFactory.getDefaultSocketFactory().createSocket(host, port); }
import java.io.IOException; import java.net.*; import java.rmi.server.*; import java.rmi.registry.LocateRegistry; public class RestrictedRMIRegistry implements RMIServerSocketFactory { public static void main(String... args) throws IOException { int port = (args.length == 0 ? 1099 : Integer.parseInt(args[0], 10)); RMIClientSocketFactory csf = RMISocketFactory.getDefaultSocketFactory(); RMIServerSocketFactory ssf = new RestrictedRMIRegistry(); LocateRegistry.createRegistry(port, csf, ssf); } public ServerSocket createServerSocket(int port) throws IOException { // Tricky bit; make a server socket with bound address return new ServerSocket(port, 0, InetAddress.getLocalHost()); } }
/** * Return the JVM-level configured {@code RMISocketFactory}. * <p> * If a global socket factory has been set via the * {@link RMISocketFactory#setSocketFactory(RMISocketFactory)} method then * that factory will be returned. Otherwise the default socket factory as * returned by {@link RMISocketFactory#getDefaultSocketFactory()} is used * instead. * * @return the configured @{code {@link RMISocketFactory} */ public static RMISocketFactory getConfiguredRMISocketFactory() { RMISocketFactory globalSocketFactory = RMISocketFactory.getSocketFactory(); if (globalSocketFactory == null) { return RMISocketFactory.getDefaultSocketFactory(); } else { return globalSocketFactory; } } }
private static MarshalledObject<java.rmi.registry.Registry> makeRegistry() throws IOException { if (!localhostOnly) return new MarshalledObject<>(createRegistry(port)); setProperty("java.rmi.server.hostname", "127.0.0.1"); return new MarshalledObject<>(createRegistry(port, getDefaultSocketFactory(), new RMIServerSocketFactory() { @Override public ServerSocket createServerSocket(int port) throws IOException { return new ServerSocket(port, 0, getLocalHost()); } })); } }
private static MarshalledObject<java.rmi.registry.Registry> makeRegistry() throws IOException { if (!localhostOnly) return new MarshalledObject<>(createRegistry(port)); setProperty("java.rmi.server.hostname", "127.0.0.1"); return new MarshalledObject<>(createRegistry(port, getDefaultSocketFactory(), new RMIServerSocketFactory() { @Override public ServerSocket createServerSocket(int port) throws IOException { return new ServerSocket(port, 0, getLocalHost()); } })); } }
/** * Return the JVM-level configured {@code RMISocketFactory}. * <p> * If a global socket factory has been set via the * {@link RMISocketFactory#setSocketFactory(RMISocketFactory)} method then * that factory will be returned. Otherwise the default socket factory as * returned by {@link RMISocketFactory#getDefaultSocketFactory()} is used * instead. * * @return the configured @{code {@link RMISocketFactory} */ public static RMISocketFactory getConfiguredRMISocketFactory() { RMISocketFactory globalSocketFactory = RMISocketFactory.getSocketFactory(); if (globalSocketFactory == null) { return RMISocketFactory.getDefaultSocketFactory(); } else { return globalSocketFactory; } } }
/** * Return the JVM-level configured {@code RMISocketFactory}. * <p> * If a global socket factory has been set via the * {@link RMISocketFactory#setSocketFactory(RMISocketFactory)} method then * that factory will be returned. Otherwise the default socket factory as * returned by {@link RMISocketFactory#getDefaultSocketFactory()} is used * instead. * * @return the configured @{code {@link RMISocketFactory} */ public static RMISocketFactory getConfiguredRMISocketFactory() { RMISocketFactory globalSocketFactory = RMISocketFactory.getSocketFactory(); if (globalSocketFactory == null) { return RMISocketFactory.getDefaultSocketFactory(); } else { return globalSocketFactory; } } }
public ServerSocket createServerSocket(int port) throws IOException { ServerSocket ss = host == null ? RMISocketFactory.getDefaultSocketFactory(). createServerSocket(this.port) : new ServerSocket(this.port, 50, InetAddress.getByName(host)); if (host == null) { host = ss.getInetAddress().getHostAddress(); System.setProperty("java.rmi.server.hostname", host); } if (this.port == 0) this.port = ss.getLocalPort(); if (rcsf != null) { if (rcsf.host == null) rcsf.host = InetAddress.getLocalHost().getHostAddress(); if (rcsf.port == 0) rcsf.port = this.port; Remote.defaultServerHost = this.host; Remote.defaultServerPort = this.port; Remote.defaultClientHost = rcsf.host; Remote.defaultClientPort = rcsf.port; rcsf = null; } return ss; } public boolean equals(Object o) {
private RMIClientSocketFactory getRMIClientSocketFactory() { if (config.jmxSslEnabled()) { return new SslRMIClientSocketFactory(); } else { return RMISocketFactory.getDefaultSocketFactory(); } }
/** * Programmatically starts a JMX server. * * @param port * port server should listen on. * @param allowConnections * allows restriction of connections to those from "localhost" * only. */ public static void startLocalJMXServer(final int port, final AllowConnections allowConnections) throws IOException, MalformedURLException, RemoteException { final RMISocketFactory serverSocketFactory = allowConnections == AllowConnections.ALL ? RMISocketFactory.getDefaultSocketFactory() : new LocalhostRMIServerSocketFactory(); LocateRegistry.createRegistry(port, RMISocketFactory.getDefaultSocketFactory(), serverSocketFactory); final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + port + "/jmxrmi"); final JMXConnectorServer rmiServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); rmiServer.start(); }