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

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/security/CustomSSLServerSocketFactory.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20110909140103-o8ucrolqt5g25k57
Tags: upstream-2.5.3.SP1
ImportĀ upstreamĀ versionĀ 2.5.3.SP1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JBoss, Home of Professional Open Source
 
3
 */
 
4
package org.jboss.remoting.security;
 
5
 
 
6
import java.io.IOException;
 
7
import java.net.InetAddress;
 
8
import java.net.ServerSocket;
 
9
import java.security.AccessController;
 
10
import java.security.PrivilegedAction;
 
11
 
 
12
import javax.net.ssl.SSLServerSocket;
 
13
import javax.net.ssl.SSLServerSocketFactory;
 
14
 
 
15
/**
 
16
 * SSL server socket factory whose configuration is customized.
 
17
 *
 
18
 * @author  <a href="mailto:mazz@jboss.com">John Mazzitelli</a>
 
19
 * @version $Revision: 3839 $
 
20
 */
 
21
public class CustomSSLServerSocketFactory
 
22
   extends SSLServerSocketFactory
 
23
{
 
24
   private SSLServerSocketFactory theDelegate;
 
25
   private SSLSocketBuilderMBean       theBuilder;
 
26
 
 
27
   /**
 
28
    * Constructor for {@link CustomSSLServerSocketFactory}. The factory can be <code>null</code> - call
 
29
    * {@link #setFactory(SSLServerSocketFactory)} to set it later.
 
30
    *
 
31
    * @param factory the true factory this class delegates to
 
32
    * @param builder the class that built this custom factory - contains all the configuration for this factory
 
33
    */
 
34
   public CustomSSLServerSocketFactory( SSLServerSocketFactory factory,
 
35
                                        SSLSocketBuilderMBean       builder )
 
36
   {
 
37
      super();
 
38
      theBuilder  = builder;
 
39
      theDelegate = factory;
 
40
   }
 
41
 
 
42
   public CustomSSLServerSocketFactory()
 
43
   {
 
44
 
 
45
   }
 
46
 
 
47
   /**
 
48
    * Sets the builder that creates the true socket server factory.
 
49
    * @param sslSocketBuilder
 
50
    */
 
51
   public void setSSLSocketBuilder(SSLSocketBuilderMBean sslSocketBuilder)
 
52
   {
 
53
      this.theBuilder = sslSocketBuilder;
 
54
   }
 
55
 
 
56
   /**
 
57
    * Returns the builder that created this factory.  You can obtain the configuration of this factory
 
58
    * by examining the returned object's configuration.
 
59
    *
 
60
    * @return the builder
 
61
    */
 
62
   public SSLSocketBuilderMBean getSSLSocketBuilder()
 
63
   {
 
64
      return theBuilder;
 
65
   }
 
66
 
 
67
   /**
 
68
    * Sets a new factory in this object - this is the factory that this object will use to create new sockets.
 
69
    *
 
70
    * @param  factory the new factory
 
71
    *
 
72
    * @throws IllegalArgumentException if factory is <code>null</code>
 
73
    */
 
74
   public void setFactory( SSLServerSocketFactory factory )
 
75
   {
 
76
      if ( factory == null )
 
77
      {
 
78
         throw new IllegalArgumentException( "Factory cannot be null" );
 
79
      }
 
80
 
 
81
      theDelegate = factory;
 
82
   }
 
83
 
 
84
   /**
 
85
    * @see javax.net.ServerSocketFactory#createServerSocket()
 
86
    */
 
87
   public ServerSocket createServerSocket()
 
88
   throws IOException
 
89
   {
 
90
      SSLServerSocket sock = (SSLServerSocket) theDelegate.createServerSocket();
 
91
      setSocketModes( sock );
 
92
      return sock;
 
93
   }
 
94
 
 
95
   /**
 
96
    * @see javax.net.ServerSocketFactory#createServerSocket(int)
 
97
    */
 
98
   public ServerSocket createServerSocket( int port )
 
99
   throws IOException
 
100
   {
 
101
      SSLServerSocket sock = (SSLServerSocket) theDelegate.createServerSocket( port );
 
102
      setSocketModes( sock );
 
103
      return sock;
 
104
   }
 
105
 
 
106
   /**
 
107
    * @see javax.net.ServerSocketFactory#createServerSocket(int, int)
 
108
    */
 
109
   public ServerSocket createServerSocket( int port,
 
110
                                           int backlog )
 
111
   throws IOException
 
112
   {
 
113
      SSLServerSocket sock = (SSLServerSocket) theDelegate.createServerSocket( port, backlog );
 
114
      setSocketModes( sock );
 
115
      return sock;
 
116
   }
 
117
 
 
118
   /**
 
119
    * @see javax.net.ServerSocketFactory#createServerSocket(int, int, java.net.InetAddress)
 
120
    */
 
121
   public ServerSocket createServerSocket( int         port,
 
122
                                           int         backlog,
 
123
                                           InetAddress ifAddress )
 
124
   throws IOException
 
125
   {
 
126
      SSLServerSocket sock = (SSLServerSocket) theDelegate.createServerSocket( port, backlog, ifAddress );
 
127
      setSocketModes( sock );
 
128
      return sock;
 
129
   }
 
130
 
 
131
   /**
 
132
    * @see javax.net.ssl.SSLServerSocketFactory#getDefaultCipherSuites()
 
133
    */
 
134
   public String[] getDefaultCipherSuites()
 
135
   {
 
136
      return theDelegate.getDefaultCipherSuites();
 
137
   }
 
138
 
 
139
   /**
 
140
    * @see javax.net.ssl.SSLServerSocketFactory#getSupportedCipherSuites()
 
141
    */
 
142
   public String[] getSupportedCipherSuites()
 
143
   {
 
144
      return theDelegate.getSupportedCipherSuites();
 
145
   }
 
146
 
 
147
   /**
 
148
    * @see java.lang.Object#equals(java.lang.Object)
 
149
    */
 
150
   public boolean equals( Object obj )
 
151
   {
 
152
      return theDelegate.equals( obj );
 
153
   }
 
154
 
 
155
   /**
 
156
    * @see java.lang.Object#hashCode()
 
157
    */
 
158
   public int hashCode()
 
159
   {
 
160
      return theDelegate.hashCode();
 
161
   }
 
162
 
 
163
   /**
 
164
    * @see java.lang.Object#toString()
 
165
    */
 
166
   public String toString()
 
167
   {
 
168
      return theDelegate.toString();
 
169
   }
 
170
 
 
171
   /**
 
172
    * Sets the socket modes according to the custom configuration.
 
173
    *
 
174
    * @param sock the socket whose modes are to be set
 
175
    */
 
176
   private void setSocketModes( SSLServerSocket sock )
 
177
   {
 
178
      if ( theBuilder != null )
 
179
      {
 
180
         
 
181
         boolean isServerSocketUseClientMode = ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
 
182
         {
 
183
            public Object run()
 
184
            {
 
185
               return new Boolean(theBuilder.isServerSocketUseClientMode());
 
186
            }
 
187
         })).booleanValue();
 
188
         
 
189
         boolean isClientAuthModeWant = ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
 
190
         {
 
191
            public Object run()
 
192
            {
 
193
               return new Boolean(theBuilder.isClientAuthModeWant());
 
194
            }
 
195
         })).booleanValue();
 
196
         
 
197
         boolean isClientAuthModeNeed = ((Boolean)AccessController.doPrivileged( new PrivilegedAction()
 
198
         {
 
199
            public Object run()
 
200
            {
 
201
               return new Boolean(theBuilder.isClientAuthModeNeed());
 
202
            }
 
203
         })).booleanValue();
 
204
 
 
205
         sock.setUseClientMode( isServerSocketUseClientMode );
 
206
         
 
207
         if ( isClientAuthModeWant )
 
208
         {
 
209
            sock.setNeedClientAuth( false );
 
210
            sock.setWantClientAuth( true );
 
211
         }
 
212
         else if ( isClientAuthModeNeed )
 
213
         {
 
214
            sock.setWantClientAuth( false );
 
215
            sock.setNeedClientAuth( true );
 
216
         }
 
217
         else
 
218
         {
 
219
            sock.setWantClientAuth( false );
 
220
            sock.setNeedClientAuth( false );
 
221
         }
 
222
      }
 
223
 
 
224
      return;
 
225
   }
 
226
}
 
 
b'\\ No newline at end of file'