2
* JBoss, Home of Professional Open Source
3
* Copyright 2006, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
22
package org.jboss.test.remoting.transport.rmi.ssl.config;
24
import java.io.IOException;
25
import java.io.Serializable;
26
import java.net.InetAddress;
27
import java.net.ServerSocket;
28
import java.net.Socket;
29
import java.net.UnknownHostException;
30
import java.util.HashMap;
33
import javax.net.ServerSocketFactory;
34
import javax.net.SocketFactory;
36
import org.jboss.remoting.security.SSLServerSocketFactoryServiceMBean;
37
import org.jboss.remoting.security.SSLSocketBuilder;
38
import org.jboss.remoting.security.SSLSocketBuilderMBean;
39
import org.jboss.test.remoting.transport.config.FactoryConfigTestCaseSSLParent;
43
* @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
45
* Copyright (c) May 20, 2006
48
public class FactoryConfigTestCase extends FactoryConfigTestCaseSSLParent
50
protected String getTransport()
56
// RMI ServerSocketFactorys aren't required to be Serializable, but for the
57
// tests we put them in config maps that get serialized.
58
protected ServerSocketFactory getDefaultServerSocketFactory() throws IOException
60
HashMap config = new HashMap();
61
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
62
String keyStoreFilePath = getKeystoreFilePath();
63
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
64
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
65
return new SerializableServerSocketFactory(config);
68
protected ServerSocketFactory getDefaultCallbackServerSocketFactory() throws IOException
70
HashMap config = new HashMap();
71
config.put(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE, "true");
72
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
73
String trustStoreFilePath = getTruststoreFilePath();
74
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
75
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
76
return new SerializableServerSocketFactory(config);
79
protected SocketFactory getDefaultSocketFactory() throws IOException
81
HashMap config = new HashMap();
82
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
83
String trustStoreFilePath = getTruststoreFilePath();
84
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
85
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
86
return new SerializableSocketFactory(config);
89
protected SocketFactory getDefaultCallbackSocketFactory() throws IOException
91
HashMap config = new HashMap();
92
config.put(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE, "false");
93
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
94
String keyStoreFilePath = getKeystoreFilePath();
95
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
96
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
97
return new SerializableSocketFactory(config);
100
public interface SerializableServerSocketFactoryMBean
101
extends SSLServerSocketFactoryServiceMBean
103
public abstract ServerSocket createServerSocket(int arg0) throws IOException;
104
public abstract ServerSocket createServerSocket(int arg0, int arg1) throws IOException;
105
public abstract ServerSocket createServerSocket(int arg0, int arg1, InetAddress arg2) throws IOException;
108
public static class SerializableServerSocketFactory extends ServerSocketFactory
109
implements Serializable, SerializableServerSocketFactoryMBean
113
public SerializableServerSocketFactory(Map config)
115
this.config = config;
119
* @see org.jboss.test.remoting.transport.rmi.ssl.config.SerializableServerSocketFactoryMBean#createServerSocket(int)
121
public ServerSocket createServerSocket(int arg0) throws IOException
123
int identity = FactoryConfigTestCaseSSLParent.secret;
124
SelfIdentifyingSSLSocketBuilder builder = new SelfIdentifyingSSLSocketBuilder(config, identity);
125
if (config.containsKey(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE))
126
builder.setServerSocketUseClientMode(true);
127
builder.setUseSSLServerSocketFactory(false);
128
return builder.createSSLServerSocketFactory().createServerSocket(arg0);
132
* @see org.jboss.test.remoting.transport.rmi.ssl.config.SerializableServerSocketFactoryMBean#createServerSocket(int, int)
134
public ServerSocket createServerSocket(int arg0, int arg1) throws IOException
136
int identity = FactoryConfigTestCaseSSLParent.secret;
137
SelfIdentifyingSSLSocketBuilder builder = new SelfIdentifyingSSLSocketBuilder(config, identity);
138
if (config.containsKey(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE))
139
builder.setServerSocketUseClientMode(true);
140
builder.setUseSSLServerSocketFactory(false);
141
return builder.createSSLServerSocketFactory().createServerSocket(arg0, arg1);
145
* @see org.jboss.test.remoting.transport.rmi.ssl.config.SerializableServerSocketFactoryMBean#createServerSocket(int, int, java.net.InetAddress)
147
public ServerSocket createServerSocket(int arg0, int arg1, InetAddress arg2) throws IOException
149
int identity = FactoryConfigTestCaseSSLParent.secret;
150
SelfIdentifyingSSLSocketBuilder builder = new SelfIdentifyingSSLSocketBuilder(config, identity);
151
if (config.containsKey(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE))
152
builder.setServerSocketUseClientMode(true);
153
builder.setUseSSLServerSocketFactory(false);
154
return builder.createSSLServerSocketFactory().createServerSocket(arg0, arg1, arg2);
157
public void create() throws Exception
161
public void start() throws Exception
169
public void destroy()
173
public void setSSLSocketBuilder(SSLSocketBuilderMBean sslSocketBuilder)
177
public SSLSocketBuilderMBean getSSLSocketBuilder()
179
int identity = FactoryConfigTestCaseSSLParent.secret;
180
SelfIdentifyingSSLSocketBuilder builder = new SelfIdentifyingSSLSocketBuilder(config, identity);
181
builder.setUseSSLServerSocketFactory(false);
186
static class SerializableSocketFactory extends SocketFactory implements Serializable
190
public SerializableSocketFactory(Map config)
192
this.config = config;
195
public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
197
SSLSocketBuilder builder = new SSLSocketBuilder(config);
198
if (config.containsKey(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE))
199
builder.setSocketUseClientMode(false);
200
builder.setUseSSLSocketFactory(false);
201
return builder.createSSLSocketFactory().createSocket(arg0, arg1);
204
public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
206
SSLSocketBuilder builder = new SSLSocketBuilder(config);
207
if (config.containsKey(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE))
208
builder.setSocketUseClientMode(false);
209
builder.setUseSSLSocketFactory(false);
210
return builder.createSSLSocketFactory().createSocket(arg0, arg1, arg2, arg3);
214
public Socket createSocket(InetAddress arg0, int arg1) throws IOException
216
SSLSocketBuilder builder = new SSLSocketBuilder(config);
217
if (config.containsKey(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE))
218
builder.setSocketUseClientMode(false);
219
builder.setUseSSLSocketFactory(false);
220
return builder.createSSLSocketFactory().createSocket(arg0, arg1);
223
public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
225
SSLSocketBuilder builder = new SSLSocketBuilder(config);
226
if (config.containsKey(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE))
227
builder.setSocketUseClientMode(false);
228
builder.setUseSSLSocketFactory(false);
229
return builder.createSSLSocketFactory().createSocket(arg0, arg1, arg2, arg3);