2
* JBoss, Home of Professional Open Source
4
package org.jboss.remoting.security;
6
import javax.net.ssl.SSLSocket;
7
import javax.net.ssl.SSLSocketFactory;
8
import java.io.IOException;
9
import java.net.InetAddress;
10
import java.net.Socket;
11
import java.net.UnknownHostException;
14
* SSL socket factory whose configuration is customized.
16
* @author <a href="mailto:mazz@jboss.com">John Mazzitelli</a>
17
* @version $Revision: 1099 $
19
public class CustomSSLSocketFactory
20
extends SSLSocketFactory
22
private SSLSocketFactory theDelegate;
23
private SSLSocketBuilderMBean theBuilder;
26
* Constructor for {@link CustomSSLSocketFactory}. The factory can be <code>null</code> - call
27
* {@link #setFactory(SSLSocketFactory)} to set it later.
29
* @param factory the true factory this class delegates to
30
* @param builder the class that built this custom factory - contains all the configuration for this factory
32
public CustomSSLSocketFactory( SSLSocketFactory factory,
33
SSLSocketBuilder builder )
37
theDelegate = factory;
40
public CustomSSLSocketFactory()
46
* Sets the builder that created the factory.
47
* @param sslSocketBuilder
49
public void setSSLSocketBuilder(SSLSocketBuilderMBean sslSocketBuilder)
51
this.theBuilder = sslSocketBuilder;
56
* Returns the builder that created this factory. You can obtain the configuration of this factory
57
* by examining the returned object's configuration.
61
public SSLSocketBuilderMBean getSSLSocketBuilder()
67
* Sets a new factory in this object - this is the factory that this object will use to create new sockets.
69
* @param factory the new factory
71
* @throws IllegalArgumentException if factory is <code>null</code>
73
public void setFactory( SSLSocketFactory factory )
75
if ( factory == null )
77
throw new IllegalArgumentException( "Factory cannot be null" );
80
theDelegate = factory;
84
* @see javax.net.ssl.SSLSocketFactory#createSocket(java.net.Socket, java.lang.String, int, boolean)
86
public Socket createSocket( Socket s,
92
SSLSocket sock = (SSLSocket) theDelegate.createSocket( s, host, port, autoClose );
93
setSocketModes( sock );
98
* @see javax.net.SocketFactory#createSocket()
100
public Socket createSocket()
103
SSLSocket sock = (SSLSocket) theDelegate.createSocket();
104
setSocketModes( sock );
109
* @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int, java.net.InetAddress, int)
111
public Socket createSocket( InetAddress address,
113
InetAddress localAddress,
117
SSLSocket sock = (SSLSocket) theDelegate.createSocket( address, port, localAddress, localPort );
118
setSocketModes( sock );
123
* @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int)
125
public Socket createSocket( InetAddress host,
129
SSLSocket sock = (SSLSocket) theDelegate.createSocket( host, port );
130
setSocketModes( sock );
135
* @see javax.net.SocketFactory#createSocket(java.lang.String, int, java.net.InetAddress, int)
137
public Socket createSocket( String host,
139
InetAddress localHost,
144
SSLSocket sock = (SSLSocket) theDelegate.createSocket( host, port, localHost, localPort );
145
setSocketModes( sock );
150
* @see javax.net.SocketFactory#createSocket(java.lang.String, int)
152
public Socket createSocket( String host,
157
SSLSocket sock = (SSLSocket) theDelegate.createSocket( host, port );
158
setSocketModes( sock );
163
* @see javax.net.ssl.SSLSocketFactory#getDefaultCipherSuites()
165
public String[] getDefaultCipherSuites()
167
return theDelegate.getDefaultCipherSuites();
171
* @see javax.net.ssl.SSLSocketFactory#getSupportedCipherSuites()
173
public String[] getSupportedCipherSuites()
175
return theDelegate.getSupportedCipherSuites();
179
* @see java.lang.Object#equals(java.lang.Object)
181
public boolean equals( Object obj )
183
return theDelegate.equals( obj );
187
* @see java.lang.Object#hashCode()
189
public int hashCode()
191
return theDelegate.hashCode();
195
* @see java.lang.Object#toString()
197
public String toString()
199
return theDelegate.toString();
203
* Sets the socket modes according to the custom configuration.
205
* @param sock the socket whose modes are to be set
207
private void setSocketModes( SSLSocket sock )
209
if ( theBuilder != null )
211
sock.setUseClientMode( theBuilder.isSocketUseClientMode() );
213
if ( theBuilder.isClientAuthModeWant() )
215
sock.setNeedClientAuth( false );
216
sock.setWantClientAuth( true );
218
else if ( theBuilder.isClientAuthModeNeed() )
220
sock.setWantClientAuth( false );
221
sock.setNeedClientAuth( true );
225
sock.setWantClientAuth( false );
226
sock.setNeedClientAuth( false );
b'\\ No newline at end of file'