Search in sources :

Example 1 with RMIClientSocketFactory

use of java.rmi.server.RMIClientSocketFactory in project tomcat by apache.

the class JmxRemoteLifecycleListener method lifecycleEvent.

@Override
public void lifecycleEvent(LifecycleEvent event) {
    // When the server starts, configure JMX/RMI
    if (Lifecycle.START_EVENT.equals(event.getType())) {
        // Configure using standard jmx system properties
        init();
        // Prevent an attacker guessing the RMI object ID
        System.setProperty("java.rmi.server.randomIDs", "true");
        // Create the environment
        HashMap<String, Object> env = new HashMap<>();
        RMIClientSocketFactory registryCsf = null;
        RMIServerSocketFactory registrySsf = null;
        RMIClientSocketFactory serverCsf = null;
        RMIServerSocketFactory serverSsf = null;
        // Configure registry socket factories
        if (rmiRegistrySSL) {
            registryCsf = new SslRMIClientSocketFactory();
            if (rmiBindAddress == null) {
                registrySsf = new SslRMIServerSocketFactory(ciphers, protocols, clientAuth);
            } else {
                registrySsf = new SslRmiServerBindSocketFactory(ciphers, protocols, clientAuth, rmiBindAddress);
            }
        } else {
            if (rmiBindAddress != null) {
                registrySsf = new RmiServerBindSocketFactory(rmiBindAddress);
            }
        }
        // Configure server socket factories
        if (rmiServerSSL) {
            serverCsf = new SslRMIClientSocketFactory();
            if (rmiBindAddress == null) {
                serverSsf = new SslRMIServerSocketFactory(ciphers, protocols, clientAuth);
            } else {
                serverSsf = new SslRmiServerBindSocketFactory(ciphers, protocols, clientAuth, rmiBindAddress);
            }
        } else {
            if (rmiBindAddress != null) {
                serverSsf = new RmiServerBindSocketFactory(rmiBindAddress);
            }
        }
        // the configured address.
        if (rmiBindAddress != null) {
            System.setProperty("java.rmi.server.hostname", rmiBindAddress);
        }
        // Force the use of local ports if required
        if (useLocalPorts) {
            registryCsf = new RmiClientLocalhostSocketFactory(registryCsf);
            serverCsf = new RmiClientLocalhostSocketFactory(serverCsf);
        }
        env.put("jmx.remote.rmi.server.credential.types", new String[] { String[].class.getName(), String.class.getName() });
        // Populate the env properties used to create the server
        if (serverCsf != null) {
            env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, serverCsf);
            env.put("com.sun.jndi.rmi.factory.socket", registryCsf);
        }
        if (serverSsf != null) {
            env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverSsf);
        }
        // Configure authentication
        if (authenticate) {
            env.put("jmx.remote.x.password.file", passwordFile);
            env.put("jmx.remote.x.access.file", accessFile);
            env.put("jmx.remote.x.login.config", loginModuleName);
        }
        // Create the Platform server
        csPlatform = createServer("Platform", rmiBindAddress, rmiRegistryPortPlatform, rmiServerPortPlatform, env, registryCsf, registrySsf, serverCsf, serverSsf);
    } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
        destroyServer("Platform", csPlatform);
    }
}
Also used : SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) HashMap(java.util.HashMap) SslRMIServerSocketFactory(javax.rmi.ssl.SslRMIServerSocketFactory) RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) SslRMIServerSocketFactory(javax.rmi.ssl.SslRMIServerSocketFactory) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory)

Example 2 with RMIClientSocketFactory

use of java.rmi.server.RMIClientSocketFactory in project felix by apache.

the class RMIResolver method createRMIServer.

protected RMIServerImpl createRMIServer(JMXServiceURL url, Map environment) throws IOException {
    int port = url.getPort();
    RMIClientSocketFactory clientFactory = (RMIClientSocketFactory) environment.get(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE);
    RMIServerSocketFactory serverFactory = (RMIServerSocketFactory) environment.get(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE);
    return new RMIJRMPServerImpl(port, clientFactory, serverFactory, environment);
}
Also used : RMIJRMPServerImpl(javax.management.remote.rmi.RMIJRMPServerImpl) RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory)

Example 3 with RMIClientSocketFactory

use of java.rmi.server.RMIClientSocketFactory in project jdk8u_jdk by JetBrains.

the class TCPEndpoint method newSocket.

/**
     * Open and return new client socket connection to endpoint.
     */
Socket newSocket() throws RemoteException {
    if (TCPTransport.tcpLog.isLoggable(Log.VERBOSE)) {
        TCPTransport.tcpLog.log(Log.VERBOSE, "opening socket to " + this);
    }
    Socket socket;
    try {
        RMIClientSocketFactory clientFactory = csf;
        if (clientFactory == null) {
            clientFactory = chooseFactory();
        }
        socket = clientFactory.createSocket(host, port);
    } catch (java.net.UnknownHostException e) {
        throw new java.rmi.UnknownHostException("Unknown host: " + host, e);
    } catch (java.net.ConnectException e) {
        throw new java.rmi.ConnectException("Connection refused to host: " + host, e);
    } catch (IOException e) {
        // We might have simply run out of file descriptors
        try {
            TCPEndpoint.shedConnectionCaches();
        // REMIND: should we retry createSocket?
        } catch (OutOfMemoryError | Exception mem) {
        // don't quit if out of memory
        // or shed fails non-catastrophically
        }
        throw new ConnectIOException("Exception creating connection to: " + host, e);
    }
    // TBD: should this be left up to socket factory instead?
    try {
        socket.setTcpNoDelay(true);
    } catch (Exception e) {
    // if we fail to set this, ignore and proceed anyway
    }
    // fix 4187495: explicitly set SO_KEEPALIVE to prevent client hangs
    try {
        socket.setKeepAlive(true);
    } catch (Exception e) {
    // ignore and proceed
    }
    return socket;
}
Also used : ConnectIOException(java.rmi.ConnectIOException) ConnectIOException(java.rmi.ConnectIOException) IOException(java.io.IOException) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) ConnectIOException(java.rmi.ConnectIOException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory)

Example 4 with RMIClientSocketFactory

use of java.rmi.server.RMIClientSocketFactory in project jdk8u_jdk by JetBrains.

the class TCPEndpoint method read.

/**
     * Get the endpoint from the input stream.
     * @param in the input stream
     * @exception IOException If id could not be read (due to stream failure)
     */
public static TCPEndpoint read(ObjectInput in) throws IOException, ClassNotFoundException {
    String host;
    int port;
    RMIClientSocketFactory csf = null;
    byte format = in.readByte();
    switch(format) {
        case FORMAT_HOST_PORT:
            host = in.readUTF();
            port = in.readInt();
            break;
        case FORMAT_HOST_PORT_FACTORY:
            host = in.readUTF();
            port = in.readInt();
            csf = (RMIClientSocketFactory) in.readObject();
            break;
        default:
            throw new IOException("invalid endpoint format");
    }
    return new TCPEndpoint(host, port, csf, null);
}
Also used : ConnectIOException(java.rmi.ConnectIOException) IOException(java.io.IOException) Endpoint(sun.rmi.transport.Endpoint) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory)

Example 5 with RMIClientSocketFactory

use of java.rmi.server.RMIClientSocketFactory in project jdk8u_jdk by JetBrains.

the class RMIConnectorServer method newJRMPServer.

private static RMIServerImpl newJRMPServer(Map<String, ?> env, int port) throws IOException {
    RMIClientSocketFactory csf = (RMIClientSocketFactory) env.get(RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE);
    RMIServerSocketFactory ssf = (RMIServerSocketFactory) env.get(RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE);
    return new RMIJRMPServerImpl(port, csf, ssf, env);
}
Also used : RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory)

Aggregations

RMIClientSocketFactory (java.rmi.server.RMIClientSocketFactory)16 RMIServerSocketFactory (java.rmi.server.RMIServerSocketFactory)12 SslRMIClientSocketFactory (javax.rmi.ssl.SslRMIClientSocketFactory)8 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)4 JMXServiceURL (javax.management.remote.JMXServiceURL)4 RemoteException (java.rmi.RemoteException)3 MBeanServer (javax.management.MBeanServer)3 SslRMIServerSocketFactory (javax.rmi.ssl.SslRMIServerSocketFactory)3 InetAddress (java.net.InetAddress)2 ConnectIOException (java.rmi.ConnectIOException)2 RemoteObject (java.rmi.server.RemoteObject)2 RMIJRMPServerImpl (javax.management.remote.rmi.RMIJRMPServerImpl)2 SSLServerSocketFactory (javax.net.ssl.SSLServerSocketFactory)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 AlreadyBoundException (java.rmi.AlreadyBoundException)1 Remote (java.rmi.Remote)1