Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

AuthenticatedSocketFactory.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Marc Wick.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.common.net;
00026 
00027 import java.io.IOException;
00028 import java.io.Serializable;
00029 import java.net.InetAddress;
00030 import java.net.Socket;
00031 import java.net.UnknownHostException;
00032 
00033 import javax.net.ssl.SSLSocket;
00034 import javax.net.ssl.SSLSocketFactory;
00035 
00036 /**
00037  * This class defines a AuthenticatedSSLSocketFactory
00038  * <p>
00039  * It is a wrapper around the socket factory in the constructor and sets the
00040  * setNeedClientAuth to true to enforce client authentication with the public
00041  * key
00042  * 
00043  * @author <a href="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
00044  * @version 1.0
00045  */
00046 public class AuthenticatedSocketFactory extends SSLSocketFactory
00047     implements
00048       Serializable
00049 {
00050 
00051   private SSLSocketFactory factory;
00052 
00053   /**
00054    * Creates a new <code>AuthenticatedSSLSocketFactory.java</code> object
00055    * 
00056    * @param factory - the factory
00057    */
00058   public AuthenticatedSocketFactory(SSLSocketFactory factory)
00059   {
00060     this.factory = factory;
00061   }
00062 
00063   /**
00064    * @see javax.net.SocketFactory#createSocket(java.lang.String, int)
00065    */
00066   public Socket createSocket(String host, int port) throws IOException,
00067       UnknownHostException
00068   {
00069     SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
00070     socket.setNeedClientAuth(true);
00071     return socket;
00072   }
00073 
00074   /**
00075    * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int)
00076    */
00077   public Socket createSocket(InetAddress host, int port) throws IOException
00078   {
00079     SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
00080     socket.setNeedClientAuth(true);
00081     return socket;
00082   }
00083 
00084   /**
00085    * @see javax.net.SocketFactory#createSocket(java.lang.String, int,
00086    *      java.net.InetAddress, int)
00087    */
00088   public Socket createSocket(String host, int port, InetAddress localAddress,
00089       int localPort) throws IOException, UnknownHostException
00090   {
00091     SSLSocket socket = (SSLSocket) factory.createSocket(host, port,
00092         localAddress, localPort);
00093     socket.setNeedClientAuth(true);
00094     return socket;
00095   }
00096 
00097   /**
00098    * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int,
00099    *      java.net.InetAddress, int)
00100    */
00101   public Socket createSocket(InetAddress address, int port,
00102       InetAddress localAddress, int localPort) throws IOException
00103   {
00104     SSLSocket socket = (SSLSocket) factory.createSocket(address, port,
00105         localAddress, localPort);
00106     socket.setNeedClientAuth(true);
00107     return socket;
00108   }
00109 
00110   /**
00111    * @see javax.net.ssl.SSLSocketFactory#createSocket(java.net.Socket,
00112    *      java.lang.String, int, boolean)
00113    */
00114   public Socket createSocket(Socket s, String host, int port, boolean autoClose)
00115       throws IOException
00116   {
00117     SSLSocket socket = (SSLSocket) factory.createSocket(s, host, port,
00118         autoClose);
00119     socket.setNeedClientAuth(true);
00120     return socket;
00121   }
00122 
00123   /**
00124    * @see javax.net.ssl.SSLSocketFactory#getDefaultCipherSuites()
00125    */
00126   public String[] getDefaultCipherSuites()
00127   {
00128     return factory.getDefaultCipherSuites();
00129   }
00130 
00131   /**
00132    * @see javax.net.ssl.SSLSocketFactory#getSupportedCipherSuites()
00133    */
00134   public String[] getSupportedCipherSuites()
00135   {
00136     return factory.getDefaultCipherSuites();
00137   }
00138 
00139 }

Generated on Mon Apr 11 22:01:29 2005 for C-JDBC by  doxygen 1.3.9.1