001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Marc Wick.
021: * Contributor(s): ______________________.
022: */package org.continuent.sequoia.common.net;
023:
024: import java.io.IOException;
025: import java.io.Serializable;
026: import java.net.InetAddress;
027: import java.net.Socket;
028: import java.net.UnknownHostException;
029:
030: import javax.net.ssl.SSLSocket;
031: import javax.net.ssl.SSLSocketFactory;
032:
033: /**
034: * This class defines a AuthenticatedSSLSocketFactory
035: * <p>
036: * It is a wrapper around the socket factory in the constructor and sets the
037: * setNeedClientAuth to true to enforce client authentication with the public
038: * key
039: *
040: * @author <a href="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
041: * @version 1.0
042: */
043: public class AuthenticatedSocketFactory extends SSLSocketFactory
044: implements Serializable {
045:
046: private static final long serialVersionUID = 3408254276587727154L;
047:
048: private SSLSocketFactory factory;
049:
050: /**
051: * Creates a new <code>AuthenticatedSSLSocketFactory.java</code> object
052: *
053: * @param factory - the factory
054: */
055: public AuthenticatedSocketFactory(SSLSocketFactory factory) {
056: this .factory = factory;
057: }
058:
059: /**
060: * @see javax.net.SocketFactory#createSocket(java.lang.String, int)
061: */
062: public Socket createSocket(String host, int port)
063: throws IOException, UnknownHostException {
064: SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
065: socket.setNeedClientAuth(true);
066: return socket;
067: }
068:
069: /**
070: * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int)
071: */
072: public Socket createSocket(InetAddress host, int port)
073: throws IOException {
074: SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
075: socket.setNeedClientAuth(true);
076: return socket;
077: }
078:
079: /**
080: * @see javax.net.SocketFactory#createSocket(java.lang.String, int,
081: * java.net.InetAddress, int)
082: */
083: public Socket createSocket(String host, int port,
084: InetAddress localAddress, int localPort)
085: throws IOException, UnknownHostException {
086: SSLSocket socket = (SSLSocket) factory.createSocket(host, port,
087: localAddress, localPort);
088: socket.setNeedClientAuth(true);
089: return socket;
090: }
091:
092: /**
093: * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int,
094: * java.net.InetAddress, int)
095: */
096: public Socket createSocket(InetAddress address, int port,
097: InetAddress localAddress, int localPort) throws IOException {
098: SSLSocket socket = (SSLSocket) factory.createSocket(address,
099: port, localAddress, localPort);
100: socket.setNeedClientAuth(true);
101: return socket;
102: }
103:
104: /**
105: * @see javax.net.ssl.SSLSocketFactory#createSocket(java.net.Socket,
106: * java.lang.String, int, boolean)
107: */
108: public Socket createSocket(Socket s, String host, int port,
109: boolean autoClose) throws IOException {
110: SSLSocket socket = (SSLSocket) factory.createSocket(s, host,
111: port, autoClose);
112: socket.setNeedClientAuth(true);
113: return socket;
114: }
115:
116: /**
117: * @see javax.net.ssl.SSLSocketFactory#getDefaultCipherSuites()
118: */
119: public String[] getDefaultCipherSuites() {
120: return factory.getDefaultCipherSuites();
121: }
122:
123: /**
124: * @see javax.net.ssl.SSLSocketFactory#getSupportedCipherSuites()
125: */
126: public String[] getSupportedCipherSuites() {
127: return factory.getDefaultCipherSuites();
128: }
129:
130: }
|