~ubuntu-branches/ubuntu/oneiric/libjboss-remoting-java/oneiric

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/transport/rmi/ssl/config/FactoryConfigTestCase.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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.
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
21
 
 */
22
 
package org.jboss.test.remoting.transport.rmi.ssl.config;
23
 
 
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;
31
 
import java.util.Map;
32
 
 
33
 
import javax.net.ServerSocketFactory;
34
 
import javax.net.SocketFactory;
35
 
 
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;
40
 
 
41
 
/**
42
 
 * 
43
 
 * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
44
 
 * <p>
45
 
 * Copyright (c) May 20, 2006
46
 
 * </p>
47
 
 */
48
 
public class FactoryConfigTestCase extends FactoryConfigTestCaseSSLParent
49
 
{
50
 
   protected String getTransport()
51
 
   {
52
 
      return "sslrmi";
53
 
   }
54
 
   
55
 
   // Note.
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
59
 
   {
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);
66
 
   }
67
 
   
68
 
   protected ServerSocketFactory getDefaultCallbackServerSocketFactory() throws IOException
69
 
   {
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);
77
 
   }
78
 
   
79
 
   protected SocketFactory getDefaultSocketFactory() throws IOException
80
 
   {
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);
87
 
   }
88
 
   
89
 
   protected SocketFactory getDefaultCallbackSocketFactory() throws IOException
90
 
   {
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);
98
 
   }
99
 
   
100
 
   public interface SerializableServerSocketFactoryMBean
101
 
   extends SSLServerSocketFactoryServiceMBean
102
 
   {
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;
106
 
   }
107
 
   
108
 
   public static class SerializableServerSocketFactory extends ServerSocketFactory
109
 
   implements Serializable, SerializableServerSocketFactoryMBean
110
 
   {
111
 
      Map config;
112
 
      
113
 
      public SerializableServerSocketFactory(Map config)
114
 
      {
115
 
         this.config = config;
116
 
      }
117
 
 
118
 
      /* (non-Javadoc)
119
 
       * @see org.jboss.test.remoting.transport.rmi.ssl.config.SerializableServerSocketFactoryMBean#createServerSocket(int)
120
 
       */
121
 
      public ServerSocket createServerSocket(int arg0) throws IOException
122
 
      {
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);
129
 
      }
130
 
 
131
 
      /* (non-Javadoc)
132
 
       * @see org.jboss.test.remoting.transport.rmi.ssl.config.SerializableServerSocketFactoryMBean#createServerSocket(int, int)
133
 
       */
134
 
      public ServerSocket createServerSocket(int arg0, int arg1) throws IOException
135
 
      {
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);
142
 
      }
143
 
 
144
 
      /* (non-Javadoc)
145
 
       * @see org.jboss.test.remoting.transport.rmi.ssl.config.SerializableServerSocketFactoryMBean#createServerSocket(int, int, java.net.InetAddress)
146
 
       */
147
 
      public ServerSocket createServerSocket(int arg0, int arg1, InetAddress arg2) throws IOException
148
 
      {
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);
155
 
      }
156
 
 
157
 
      public void create() throws Exception
158
 
      {
159
 
      }
160
 
 
161
 
      public void start() throws Exception
162
 
      { 
163
 
      }
164
 
 
165
 
      public void stop()
166
 
      {
167
 
      }
168
 
 
169
 
      public void destroy()
170
 
      {
171
 
      }
172
 
 
173
 
      public void setSSLSocketBuilder(SSLSocketBuilderMBean sslSocketBuilder)
174
 
      {
175
 
      }
176
 
 
177
 
      public SSLSocketBuilderMBean getSSLSocketBuilder()
178
 
      {
179
 
         int identity = FactoryConfigTestCaseSSLParent.secret;
180
 
         SelfIdentifyingSSLSocketBuilder builder = new SelfIdentifyingSSLSocketBuilder(config, identity);
181
 
         builder.setUseSSLServerSocketFactory(false);
182
 
         return builder;
183
 
      }
184
 
   }
185
 
   
186
 
   static class SerializableSocketFactory extends SocketFactory implements Serializable
187
 
   {
188
 
      Map config;
189
 
      
190
 
      public SerializableSocketFactory(Map config)
191
 
      {
192
 
         this.config = config;
193
 
      }
194
 
      
195
 
      public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
196
 
      {
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);
202
 
      }
203
 
      
204
 
      public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
205
 
      {
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);
211
 
      }
212
 
      
213
 
      
214
 
      public Socket createSocket(InetAddress arg0, int arg1) throws IOException
215
 
      {
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);
221
 
      }
222
 
      
223
 
      public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
224
 
      {
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);
230
 
      }
231
 
   }
232
 
}