001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.transport.https;
019:
020: import java.io.IOException;
021: import java.net.InetAddress;
022: import java.net.Socket;
023: import java.net.UnknownHostException;
024:
025: import java.util.logging.Handler;
026: import java.util.logging.Level;
027: import java.util.logging.Logger;
028:
029: import javax.net.ssl.SSLSocket;
030: import javax.net.ssl.SSLSocketFactory;
031:
032: import org.apache.cxf.common.logging.LogUtils;
033:
034: class SSLSocketFactoryWrapper extends SSLSocketFactory {
035:
036: private static final Logger LOG = LogUtils
037: .getL7dLogger(SSLSocketFactoryWrapper.class);
038:
039: private SSLSocketFactory sslSocketFactory;
040: private String[] ciphers;
041:
042: public SSLSocketFactoryWrapper(
043: SSLSocketFactory sslSocketFactoryParam,
044: String[] ciphersParam) {
045: sslSocketFactory = sslSocketFactoryParam;
046: ciphers = ciphersParam;
047: }
048:
049: public String[] getDefaultCipherSuites() {
050: return sslSocketFactory.getDefaultCipherSuites();
051: }
052:
053: public String[] getSupportedCipherSuites() {
054: return sslSocketFactory.getSupportedCipherSuites();
055: }
056:
057: public Socket createSocket(Socket s, String host, int port,
058: boolean autoClose) throws IOException, UnknownHostException {
059: return enableCipherSuites(sslSocketFactory.createSocket(s,
060: host, port, autoClose), new Object[] { host, port });
061: }
062:
063: public Socket createSocket(String host, int port)
064: throws IOException, UnknownHostException {
065: return enableCipherSuites(sslSocketFactory.createSocket(host,
066: port), new Object[] { host, port });
067: }
068:
069: public Socket createSocket(String host, int port,
070: InetAddress localHost, int localPort) throws IOException,
071: UnknownHostException {
072: return enableCipherSuites(sslSocketFactory.createSocket(host,
073: port, localHost, localPort),
074: new Object[] { host, port });
075: }
076:
077: public Socket createSocket(InetAddress host, int port)
078: throws IOException {
079: return enableCipherSuites(sslSocketFactory.createSocket(host,
080: port), new Object[] { host, port });
081: }
082:
083: public Socket createSocket(InetAddress address, int port,
084: InetAddress localAddress, int localPort) throws IOException {
085: return enableCipherSuites(sslSocketFactory.createSocket(
086: address, port, localAddress, localPort), new Object[] {
087: address, port });
088: }
089:
090: private Socket enableCipherSuites(Socket s, Object[] logParams) {
091: SSLSocket socket = (SSLSocket) s;
092:
093: if ((socket != null) && (ciphers != null)) {
094: socket.setEnabledCipherSuites(ciphers);
095: }
096:
097: if (socket == null) {
098: LogUtils.log(LOG, Level.SEVERE,
099: "PROBLEM_CREATING_OUTBOUND_REQUEST_SOCKET",
100: logParams);
101: }
102:
103: return socket;
104: }
105:
106: /*
107: * For testing only
108: */
109: protected void addLogHandler(Handler handler) {
110: LOG.addHandler(handler);
111: }
112: }
|