FileDocCategorySizeDatePackage
SslRMIClientSocketFactory.javaAPI DocJava SE 5 API7963Fri Aug 26 14:57:46 BST 2005javax.rmi.ssl

SslRMIClientSocketFactory

public class SslRMIClientSocketFactory extends Object implements Serializable, RMIClientSocketFactory

An SslRMIClientSocketFactory instance is used by the RMI runtime in order to obtain client sockets for RMI calls via SSL.

This class implements RMIClientSocketFactory over the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocols.

This class creates SSL sockets using the default SSLSocketFactory (see {@link SSLSocketFactory#getDefault}). All instances of this class are functionally equivalent. In particular, they all share the same truststore, and the same keystore when client authentication is required by the server. This behavior can be modified in subclasses by overriding the {@link #createSocket(String,int)} method; in that case, {@link #equals(Object) equals} and {@link #hashCode() hashCode} may also need to be overridden.

If the system property javax.rmi.ssl.client.enabledCipherSuites is specified, the {@link #createSocket(String,int)} method will call {@link SSLSocket#setEnabledCipherSuites(String[])} before returning the socket. The value of this system property is a string that is a comma-separated list of SSL/TLS cipher suites to enable.

If the system property javax.rmi.ssl.client.enabledProtocols is specified, the {@link #createSocket(String,int)} method will call {@link SSLSocket#setEnabledProtocols(String[])} before returning the socket. The value of this system property is a string that is a comma-separated list of SSL/TLS protocol versions to enable.

see
javax.net.ssl.SSLSocketFactory
see
javax.rmi.ssl.SslRMIServerSocketFactory
since
1.5

Fields Summary
private static SocketFactory
defaultSocketFactory
private static final long
serialVersionUID
Constructors Summary
public SslRMIClientSocketFactory()

Creates a new SslRMIClientSocketFactory.

        // We don't force the initialization of the default SSLSocketFactory
        // at construction time - because the RMI client socket factory is
        // created on the server side, where that initialization is a priori
        // meaningless, unless both server and client run in the same JVM.
        // We could possibly override readObject() to force this initialization,
        // but it might not be a good idea to actually mix this with possible
        // deserialization problems.
        // So contrarily to what we do for the server side, the initialization
        // of the SSLSocketFactory will be delayed until the first time
        // createSocket() is called - note that the default SSLSocketFactory
        // might already have been initialized anyway if someone in the JVM
        // already called SSLSocketFactory.getDefault().
        //
    
Methods Summary
public java.net.SocketcreateSocket(java.lang.String host, int port)

Creates an SSL socket.

If the system property javax.rmi.ssl.client.enabledCipherSuites is specified, this method will call {@link SSLSocket#setEnabledCipherSuites(String[])} before returning the socket. The value of this system property is a string that is a comma-separated list of SSL/TLS cipher suites to enable.

If the system property javax.rmi.ssl.client.enabledProtocols is specified, this method will call {@link SSLSocket#setEnabledProtocols(String[])} before returning the socket. The value of this system property is a string that is a comma-separated list of SSL/TLS protocol versions to enable.

        // Retrieve the SSLSocketFactory
        //
        final SocketFactory sslSocketFactory = getDefaultClientSocketFactory();
        // Create the SSLSocket
        //
        final SSLSocket sslSocket = (SSLSocket)
            sslSocketFactory.createSocket(host, port);
        // Set the SSLSocket Enabled Cipher Suites
        //
        final String enabledCipherSuites = (String)
            System.getProperty("javax.rmi.ssl.client.enabledCipherSuites");
        if (enabledCipherSuites != null) {
            StringTokenizer st = new StringTokenizer(enabledCipherSuites, ",");
            int tokens = st.countTokens();
            String enabledCipherSuitesList[] = new String[tokens];
            for (int i = 0 ; i < tokens; i++) {
                enabledCipherSuitesList[i] = st.nextToken();
            }
	    try {
		sslSocket.setEnabledCipherSuites(enabledCipherSuitesList);
	    } catch (IllegalArgumentException e) {
		throw (IOException)
		    new IOException(e.getMessage()).initCause(e);
	    }
        }
        // Set the SSLSocket Enabled Protocols
        //
        final String enabledProtocols = (String)
            System.getProperty("javax.rmi.ssl.client.enabledProtocols");
        if (enabledProtocols != null) {
            StringTokenizer st = new StringTokenizer(enabledProtocols, ",");
            int tokens = st.countTokens();
            String enabledProtocolsList[] = new String[tokens];
            for (int i = 0 ; i < tokens; i++) {
                enabledProtocolsList[i] = st.nextToken();
            }
	    try {
		sslSocket.setEnabledProtocols(enabledProtocolsList);
	    } catch (IllegalArgumentException e) {
		throw (IOException)
		    new IOException(e.getMessage()).initCause(e);
	    }
        }
        // Return the preconfigured SSLSocket
        //
        return sslSocket;
    
public booleanequals(java.lang.Object obj)

Indicates whether some other object is "equal to" this one.

Because all instances of this class are functionally equivalent (they all use the default SSLSocketFactory), this method simply returns this.getClass().equals(obj.getClass()).

A subclass should override this method (as well as {@link #hashCode()}) if its instances are not all functionally equivalent.

        if (obj == null) return false;
        if (obj == this) return true;
        return this.getClass().equals(obj.getClass());
    
private static synchronized javax.net.SocketFactorygetDefaultClientSocketFactory()


         
        if (defaultSocketFactory == null)
            defaultSocketFactory = SSLSocketFactory.getDefault();
        return defaultSocketFactory;
    
public inthashCode()

Returns a hash code value for this SslRMIClientSocketFactory.

return
a hash code value for this SslRMIClientSocketFactory.

        return this.getClass().hashCode();