KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > net > AuthenticatedSocketFactory


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * Initial developer(s): Marc Wick.
21  * Contributor(s): ______________________.
22  */

23
24 package org.continuent.sequoia.common.net;
25
26 import java.io.IOException JavaDoc;
27 import java.io.Serializable JavaDoc;
28 import java.net.InetAddress JavaDoc;
29 import java.net.Socket JavaDoc;
30 import java.net.UnknownHostException JavaDoc;
31
32 import javax.net.ssl.SSLSocket;
33 import javax.net.ssl.SSLSocketFactory;
34
35 /**
36  * This class defines a AuthenticatedSSLSocketFactory
37  * <p>
38  * It is a wrapper around the socket factory in the constructor and sets the
39  * setNeedClientAuth to true to enforce client authentication with the public
40  * key
41  *
42  * @author <a HREF="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
43  * @version 1.0
44  */

45 public class AuthenticatedSocketFactory extends SSLSocketFactory
46     implements
47       Serializable JavaDoc
48 {
49
50   private static final long serialVersionUID = 3408254276587727154L;
51
52   private SSLSocketFactory factory;
53
54   /**
55    * Creates a new <code>AuthenticatedSSLSocketFactory.java</code> object
56    *
57    * @param factory - the factory
58    */

59   public AuthenticatedSocketFactory(SSLSocketFactory factory)
60   {
61     this.factory = factory;
62   }
63
64   /**
65    * @see javax.net.SocketFactory#createSocket(java.lang.String, int)
66    */

67   public Socket JavaDoc createSocket(String JavaDoc host, int port) throws IOException JavaDoc,
68       UnknownHostException JavaDoc
69   {
70     SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
71     socket.setNeedClientAuth(true);
72     return socket;
73   }
74
75   /**
76    * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int)
77    */

78   public Socket JavaDoc createSocket(InetAddress JavaDoc host, int port) throws IOException JavaDoc
79   {
80     SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
81     socket.setNeedClientAuth(true);
82     return socket;
83   }
84
85   /**
86    * @see javax.net.SocketFactory#createSocket(java.lang.String, int,
87    * java.net.InetAddress, int)
88    */

89   public Socket JavaDoc createSocket(String JavaDoc host, int port, InetAddress JavaDoc localAddress,
90       int localPort) throws IOException JavaDoc, UnknownHostException JavaDoc
91   {
92     SSLSocket socket = (SSLSocket) factory.createSocket(host, port,
93         localAddress, localPort);
94     socket.setNeedClientAuth(true);
95     return socket;
96   }
97
98   /**
99    * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int,
100    * java.net.InetAddress, int)
101    */

102   public Socket JavaDoc createSocket(InetAddress JavaDoc address, int port,
103       InetAddress JavaDoc localAddress, int localPort) throws IOException JavaDoc
104   {
105     SSLSocket socket = (SSLSocket) factory.createSocket(address, port,
106         localAddress, localPort);
107     socket.setNeedClientAuth(true);
108     return socket;
109   }
110
111   /**
112    * @see javax.net.ssl.SSLSocketFactory#createSocket(java.net.Socket,
113    * java.lang.String, int, boolean)
114    */

115   public Socket JavaDoc createSocket(Socket JavaDoc s, String JavaDoc host, int port, boolean autoClose)
116       throws IOException JavaDoc
117   {
118     SSLSocket socket = (SSLSocket) factory.createSocket(s, host, port,
119         autoClose);
120     socket.setNeedClientAuth(true);
121     return socket;
122   }
123
124   /**
125    * @see javax.net.ssl.SSLSocketFactory#getDefaultCipherSuites()
126    */

127   public String JavaDoc[] getDefaultCipherSuites()
128   {
129     return factory.getDefaultCipherSuites();
130   }
131
132   /**
133    * @see javax.net.ssl.SSLSocketFactory#getSupportedCipherSuites()
134    */

135   public String JavaDoc[] getSupportedCipherSuites()
136   {
137     return factory.getDefaultCipherSuites();
138   }
139
140 }
141
Popular Tags