KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > net > AuthenticatedSocketFactory


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Marc Wick.
22  * Contributor(s): ______________________.
23  */

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

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

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

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

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

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

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

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

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

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