You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by eg...@apache.org on 2006/10/02 12:20:45 UTC
svn commit: r451949 - in /incubator/cxf/trunk/rt/transports/http/src:
main/java/org/apache/cxf/transport/http/
main/java/org/apache/cxf/transport/https/
test/java/org/apache/cxf/transport/https/
test/java/org/apache/cxf/transport/https/resources/
Author: eglynn
Date: Mon Oct 2 03:20:43 2006
New Revision: 451949
URL: http://svn.apache.org/viewvc?view=rev&rev=451949
Log:
HTTPS URL connection factory
Added:
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
- copied, changed from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/main/java/org/objectweb/celtix/transports/https/JettySslClientConfigurer.java
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/Messages.properties
- copied unchanged from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/main/java/org/objectweb/celtix/transports/https/Messages.properties
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLSocketFactoryWrapper.java
- copied, changed from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/main/java/org/objectweb/celtix/transports/https/SSLSocketFactoryWrapper.java
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/HttpsURLConnectionFactoryTest.java
- copied, changed from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/JettySslClientConfigurerTest.java
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestHttpsURLConnection.java
- copied, changed from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/DummyHttpsConnection.java
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestLogHandler.java
- copied, changed from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/TestHandler.java
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/resources/
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/resources/abigcompany_ca.pem
- copied unchanged from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/resources/abigcompany_ca.pem
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/resources/celtix.p12
- copied unchanged from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/resources/celtix.p12
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/resources/celtixp12truststore
- copied unchanged from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/resources/celtixp12truststore
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/resources/defaultkeystore
- copied unchanged from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/resources/defaultkeystore
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/resources/defaulttruststore
- copied unchanged from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/resources/defaulttruststore
Modified:
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?view=diff&rev=451949&r1=451948&r2=451949
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Mon Oct 2 03:20:43 2006
@@ -271,9 +271,9 @@
return new URLConnectionFactory() {
public URLConnection createConnection(Proxy proxy, URL u)
throws IOException {
- return getProxy() != null
- ? u.openConnection(proxy)
- : u.openConnection();
+ return proxy != null
+ ? u.openConnection(proxy)
+ : u.openConnection();
}
};
}
Copied: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java (from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/main/java/org/objectweb/celtix/transports/https/JettySslClientConfigurer.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java?view=diff&rev=451949&p1=incubator/cxf/branches/post_apache_integration/rt/transports/http/src/main/java/org/objectweb/celtix/transports/https/JettySslClientConfigurer.java&r1=438444&p2=incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java&r2=451949
==============================================================================
--- incubator/cxf/branches/post_apache_integration/rt/transports/http/src/main/java/org/objectweb/celtix/transports/https/JettySslClientConfigurer.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java Mon Oct 2 03:20:43 2006
@@ -1,4 +1,23 @@
-package org.objectweb.celtix.transports.https;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.transport.https;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -6,6 +25,8 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Method;
+import java.net.Proxy;
+import java.net.URL;
import java.net.URLConnection;
import java.security.KeyStore;
import java.security.cert.CertificateFactory;
@@ -22,59 +43,57 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
-import org.objectweb.celtix.bus.configuration.security.SSLClientPolicy;
-import org.objectweb.celtix.common.logging.LogUtils;
-import org.objectweb.celtix.configuration.Configuration;
-
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.configuration.security.SSLClientPolicy;
+import org.apache.cxf.transport.http.URLConnectionFactory;
-public final class JettySslClientConfigurer {
+public final class HttpsURLConnectionFactory implements URLConnectionFactory {
private static final long serialVersionUID = 1L;
- private static final Logger LOG = LogUtils.getL7dLogger(JettySslClientConfigurer.class);
- private static final String DEFAUL_KEYSTORE_TYPE = "PKCS12";
- private static final String DEFAUL_TRUST_STORE_TYPE = "JKS";
+ private static final Logger LOG =
+ LogUtils.getL7dLogger(HttpsURLConnectionFactory.class);
+ private static final String DEFAULT_KEYSTORE_TYPE = "PKCS12";
+ private static final String DEFAULT_TRUST_STORE_TYPE = "JKS";
private static final String DEFAULT_SECURE_SOCKET_PROTOCOL = "TLSv1";
- private static final String CERTIFICATE_FACTORY_TYPE = "X.509";
+ private static final String CERTIFICATE_FACTORY_TYPE = "X.509";
private static final String PKCS12_TYPE = "PKCS12";
+ // REVISIT inject this resource
SSLClientPolicy sslPolicy;
- private String keyStoreLocation;
- private String keyStorePassword;
- private String keyPassword;
- private String keyStoreType = DEFAUL_KEYSTORE_TYPE;
- private String[] cipherSuites;
- private String trustStoreLocation;
- private String trustStoreType = DEFAUL_TRUST_STORE_TYPE;
- private String keystoreKeyManagerFactoryAlgorithm;
- private String trustStoreKeyManagerFactoryAlgorithm;
- private HttpsURLConnection httpsConnection;
- private String secureSocketProtocol;
- private Configuration config;
-
- public JettySslClientConfigurer(SSLClientPolicy sslPolicyParam,
- URLConnection connection,
- Configuration httpClientConfiguration) {
-
- this.sslPolicy = sslPolicyParam;
- this.httpsConnection = (HttpsURLConnection)connection;
-
- config = httpClientConfiguration;
-
- }
-
- public void configure() {
- setupSecurityConfigurer();
- setupKeystore();
- setupKeystoreType();
- setupKeystorePassword();
- setupKeyPassword();
- setupKeystoreAlgorithm();
- setupTrustStoreAlgorithm();
- setupCiphersuites();
- setupTrustStore();
- setupTrustStoreType();
- setupSecureSocketProtocol();
+ /**
+ * Create a URLConnection, proxified if neccessary.
+ *
+ * @param proxy non-null if connection should be proxified
+ * @param url the target URL
+ * @return an appropriate URLConnection
+ */
+ public URLConnection createConnection(Proxy proxy, URL url)
+ throws IOException {
+ URLConnection connection = proxy != null
+ ? url.openConnection(proxy)
+ : url.openConnection();
+ if (connection instanceof HttpsURLConnection) {
+ decorate((HttpsURLConnection)connection);
+ }
+ return connection;
+ }
+
+ protected void setSSLPolicy(SSLClientPolicy p) {
+ sslPolicy = p;
+ }
+
+ protected void decorate(HttpsURLConnection connection) {
+ String keyStoreLocation = setupKeystore();
+ String keyStoreType = setupKeystoreType();
+ String keyStorePassword = setupKeystorePassword();
+ String keyPassword = setupKeyPassword();
+ String keystoreKeyManagerFactoryAlgorithm = setupKeystoreAlgorithm();
+ String trustStoreKeyManagerFactoryAlgorithm = setupTrustStoreAlgorithm();
+ String[] cipherSuites = setupCiphersuites();
+ String trustStoreLocation = setupTrustStore();
+ String trustStoreType = setupTrustStoreType();
+ String secureSocketProtocol = setupSecureSocketProtocol();
setupSessionCaching();
setupSessionCacheKey();
setupMaxChainLength();
@@ -82,118 +101,108 @@
setupProxyHost();
setupProxyPort();
- if (keyStoreType.equalsIgnoreCase(PKCS12_TYPE)) {
- setupSSLContextPKCS12();
- } else {
- setupSSLContext();
+ try {
+ SSLContext sslctx = SSLContext.getInstance(secureSocketProtocol);
+ boolean pkcs12 = keyStoreType.equalsIgnoreCase(PKCS12_TYPE);
+ sslctx.init(getKeyStoreManagers(pkcs12,
+ keyStoreLocation,
+ keyStoreType,
+ keyStorePassword,
+ keyPassword,
+ keystoreKeyManagerFactoryAlgorithm,
+ secureSocketProtocol),
+ getTrustStoreManagers(pkcs12,
+ trustStoreType,
+ trustStoreLocation,
+ trustStoreKeyManagerFactoryAlgorithm),
+ null);
+ connection.setSSLSocketFactory(new SSLSocketFactoryWrapper(sslctx.getSocketFactory(),
+ cipherSuites));
+ } catch (Exception e) {
+ LogUtils.log(LOG, Level.SEVERE, "SSL_CONTEXT_INIT_FAILURE", e);
}
-
}
- private boolean setupSSLContext() {
-
- //TODO for performance reasons we should cache the KeymanagerFactory and TrustManagerFactory
- if ((keyStorePassword != null) && (keyPassword != null) && (!keyStorePassword.equals(keyPassword))) {
+ private KeyManager[] getKeyStoreManagers(boolean pkcs12,
+ String keyStoreLocation,
+ String keyStoreType,
+ String keyStorePassword,
+ String keyPassword,
+ String keystoreKeyManagerFactoryAlgorithm,
+ String secureSocketProtocol)
+ throws Exception {
+ //TODO for performance reasons we should cache
+ // the KeymanagerFactory and TrustManagerFactory
+ if ((keyStorePassword != null)
+ && (keyPassword != null)
+ && (!keyStorePassword.equals(keyPassword))) {
LogUtils.log(LOG, Level.WARNING, "KEY_PASSWORD_NOT_SAME_KEYSTORE_PASSWORD");
}
- try {
- SSLContext sslctx = SSLContext.getInstance(secureSocketProtocol);
-
- KeyManagerFactory kmf =
- KeyManagerFactory.getInstance(keystoreKeyManagerFactoryAlgorithm);
- KeyStore ks = KeyStore.getInstance(keyStoreType);
+ KeyManager[] keystoreManagers = null;
+ KeyManagerFactory kmf =
+ KeyManagerFactory.getInstance(keystoreKeyManagerFactoryAlgorithm);
+ KeyStore ks = KeyStore.getInstance(keyStoreType);
+
+ if (pkcs12) {
FileInputStream fis = new FileInputStream(keyStoreLocation);
DataInputStream dis = new DataInputStream(fis);
byte[] bytes = new byte[dis.available()];
dis.readFully(bytes);
ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
- KeyManager[] keystoreManagers = null;
if (keyStorePassword != null) {
- try {
- ks.load(bin, keyStorePassword.toCharArray());
- kmf.init(ks, keyStorePassword.toCharArray());
- keystoreManagers = kmf.getKeyManagers();
- LogUtils.log(LOG, Level.INFO, "LOADED_KEYSTORE", new Object[]{keyStoreLocation});
- } catch (Exception e) {
- LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE",
- new Object[]{keyStoreLocation, e.getMessage()});
- }
+ keystoreManagers =
+ loadKeyStore(kmf, ks, bin, keyStoreLocation, keyStorePassword);
}
- if ((keyStorePassword == null) && (keyStoreLocation != null)) {
- LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE_NULL_PASSWORD",
- new Object[]{keyStoreLocation});
- }
-
- // ************************* Load Trusted CA file *************************
-
- TrustManager[] trustStoreManagers = null;
- KeyStore trustedCertStore = KeyStore.getInstance(trustStoreType);
-
- trustedCertStore.load(new FileInputStream(trustStoreLocation), null);
- TrustManagerFactory tmf =
- TrustManagerFactory.getInstance(trustStoreKeyManagerFactoryAlgorithm);
- try {
- tmf.init(trustedCertStore);
- trustStoreManagers = tmf.getTrustManagers();
- LogUtils.log(LOG, Level.INFO, "LOADED_TRUST_STORE", new Object[]{trustStoreLocation});
- } catch (Exception e) {
- LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_TRUST_STORE",
- new Object[]{trustStoreLocation, e.getMessage()});
- }
- sslctx.init(keystoreManagers, trustStoreManagers, null);
-
- httpsConnection.setSSLSocketFactory(new SSLSocketFactoryWrapper(sslctx.getSocketFactory(),
- cipherSuites));
-
-
-
- } catch (Exception e) {
- LogUtils.log(LOG, Level.SEVERE, "SSL_CONTEXT_INIT_FAILURE", new Object[]{e.getMessage()});
- return false;
- }
- return true;
- }
-
-
- private boolean setupSSLContextPKCS12() {
-
- //TODO for performance reasons we should cache the KeymanagerFactory and TrustManagerFactory
- if ((keyStorePassword != null) && (keyPassword != null) && (!keyStorePassword.equals(keyPassword))) {
- LogUtils.log(LOG, Level.WARNING, "KEY_PASSWORD_NOT_SAME_KEYSTORE_PASSWORD");
- }
- try {
- SSLContext sslctx = SSLContext.getInstance(secureSocketProtocol);
- KeyManagerFactory kmf =
- KeyManagerFactory.getInstance(keystoreKeyManagerFactoryAlgorithm);
- KeyStore ks = KeyStore.getInstance(keyStoreType);
- KeyManager[] keystoreManagers = null;
-
-
+ } else {
byte[] sslCert = loadClientCredential(keyStoreLocation);
if (sslCert != null && sslCert.length > 0 && keyStorePassword != null) {
ByteArrayInputStream bin = new ByteArrayInputStream(sslCert);
- try {
- ks.load(bin, keyStorePassword.toCharArray());
- kmf.init(ks, keyStorePassword.toCharArray());
- keystoreManagers = kmf.getKeyManagers();
- LogUtils.log(LOG, Level.INFO, "LOADED_KEYSTORE", new Object[]{keyStoreLocation});
- } catch (Exception e) {
- LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE",
- new Object[]{keyStoreLocation, e.getMessage()});
- }
+ keystoreManagers =
+ loadKeyStore(kmf, ks, bin, keyStoreLocation, keyStorePassword);
}
- if ((keyStorePassword == null) && (keyStoreLocation != null)) {
- LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE_NULL_PASSWORD",
- new Object[]{keyStoreLocation});
- }
-
- // ************************* Load Trusted CA file *************************
+ }
+ if ((keyStorePassword == null) && (keyStoreLocation != null)) {
+ LogUtils.log(LOG, Level.WARNING,
+ "FAILED_TO_LOAD_KEYSTORE_NULL_PASSWORD",
+ new Object[]{keyStoreLocation});
+ }
+ return keystoreManagers;
+ }
+
+ private KeyManager[] loadKeyStore(KeyManagerFactory kmf,
+ KeyStore ks,
+ ByteArrayInputStream bin,
+ String keyStoreLocation,
+ String keyStorePassword) {
+ KeyManager[] keystoreManagers = null;
+ try {
+ ks.load(bin, keyStorePassword.toCharArray());
+ kmf.init(ks, keyStorePassword.toCharArray());
+ keystoreManagers = kmf.getKeyManagers();
+ LogUtils.log(LOG, Level.INFO, "LOADED_KEYSTORE", new Object[]{keyStoreLocation});
+ } catch (Exception e) {
+ LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE",
+ new Object[]{keyStoreLocation, e.getMessage()});
+ }
+ return keystoreManagers;
+ }
+
+ private TrustManager[] getTrustStoreManagers(boolean pkcs12,
+ String trustStoreType,
+ String trustStoreLocation,
+ String trustStoreKeyManagerFactoryAlgorithm)
+ throws Exception {
+ // ************************* Load Trusted CA file *************************
+
+ TrustManager[] trustStoreManagers = null;
+ KeyStore trustedCertStore = KeyStore.getInstance(trustStoreType);
+
+ if (pkcs12) {
//TODO could support multiple trust cas
- TrustManager[] trustStoreManagers = new TrustManager[1];
-
- KeyStore trustedCertStore = KeyStore.getInstance(trustStoreType);
+ trustStoreManagers = new TrustManager[1];
+
trustedCertStore.load(null, "".toCharArray());
CertificateFactory cf = CertificateFactory.getInstance(CERTIFICATE_FACTORY_TYPE);
byte[] caCert = loadCACert(trustStoreLocation);
@@ -208,28 +217,19 @@
LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_TRUST_STORE",
new Object[]{trustStoreLocation, e.getMessage()});
}
- TrustManagerFactory tmf =
- TrustManagerFactory.getInstance(trustStoreKeyManagerFactoryAlgorithm);
-
- tmf.init(trustedCertStore);
- LogUtils.log(LOG, Level.INFO, "LOADED_TRUST_STORE", new Object[]{trustStoreLocation});
-
- trustStoreManagers = tmf.getTrustManagers();
+ } else {
+ trustedCertStore.load(new FileInputStream(trustStoreLocation), null);
+ }
+
+ TrustManagerFactory tmf =
+ TrustManagerFactory.getInstance(trustStoreKeyManagerFactoryAlgorithm);
+ tmf.init(trustedCertStore);
+ LogUtils.log(LOG, Level.INFO, "LOADED_TRUST_STORE", new Object[]{trustStoreLocation});
+ trustStoreManagers = tmf.getTrustManagers();
-
- sslctx.init(keystoreManagers, trustStoreManagers, null);
- httpsConnection.setSSLSocketFactory(new SSLSocketFactoryWrapper(sslctx.getSocketFactory(),
- cipherSuites));
-
- } catch (Exception e) {
- LogUtils.log(LOG, Level.SEVERE, "SSL_CONTEXT_INIT_FAILURE", new Object[]{e.getMessage()});
- return false;
- }
- return true;
+ return trustStoreManagers;
}
-
-
private static byte[] loadClientCredential(String fileName) throws IOException {
if (fileName == null) {
return null;
@@ -245,8 +245,6 @@
in.close();
return out.toByteArray();
}
-
-
private static byte[] loadCACert(String fileName) throws IOException {
if (fileName == null) {
@@ -265,94 +263,103 @@
return out.toByteArray();
}
-
- public void setupKeystore() {
+ public String setupKeystore() {
+ String keyStoreLocation = null;
+ String logMsg = null;
if (sslPolicy.isSetKeystore()) {
keyStoreLocation = sslPolicy.getKeystore();
- LogUtils.log(LOG, Level.INFO, "KEY_STORE_SET", new Object[]{keyStoreLocation});
- return;
- }
- keyStoreLocation = System.getProperty("javax.net.ssl.keyStore");
- if (keyStoreLocation != null) {
- LogUtils.log(LOG, Level.INFO, "KEY_STORE_SYSTEM_PROPERTY_SET", new Object[]{keyStoreLocation});
- return;
+ logMsg = "KEY_STORE_SET";
+ } else {
+ keyStoreLocation = System.getProperty("javax.net.ssl.keyStore");
+ if (keyStoreLocation != null) {
+ logMsg = "KEY_STORE_SYSTEM_PROPERTY_SET";
+ } else {
+ keyStoreLocation = System.getProperty("user.home") + "/.keystore";
+ logMsg = "KEY_STORE_NOT_SET";
+ }
}
-
- keyStoreLocation = System.getProperty("user.home") + "/.keystore";
- LogUtils.log(LOG, Level.INFO, "KEY_STORE_NOT_SET", new Object[]{keyStoreLocation});
-
+ LogUtils.log(LOG, Level.INFO, logMsg, new Object[]{keyStoreLocation});
+ return keyStoreLocation;
}
- public void setupKeystoreType() {
- if (!sslPolicy.isSetKeystoreType()) {
- LogUtils.log(LOG, Level.INFO, "KEY_STORE_TYPE_NOT_SET", new Object[]{DEFAUL_KEYSTORE_TYPE});
- return;
+ public String setupKeystoreType() {
+ String keyStoreType = null;
+ String logMsg = null;
+ if (sslPolicy.isSetKeystoreType()) {
+ keyStoreType = sslPolicy.getKeystoreType();
+ logMsg = "KEY_STORE_TYPE_SET";
+ } else {
+ keyStoreType = DEFAULT_KEYSTORE_TYPE;
+ logMsg = "KEY_STORE_TYPE_NOT_SET";
}
- keyStoreType = sslPolicy.getKeystoreType();
- LogUtils.log(LOG, Level.INFO, "KEY_STORE_TYPE_SET", new Object[]{keyStoreType});
+ LogUtils.log(LOG, Level.INFO, logMsg, new Object[]{keyStoreType});
+ return keyStoreType;
}
- public void setupKeystorePassword() {
+ public String setupKeystorePassword() {
+ String keyStorePassword = null;
+ String logMsg = null;
if (sslPolicy.isSetKeystorePassword()) {
- LogUtils.log(LOG, Level.INFO, "KEY_STORE_PASSWORD_SET");
+ logMsg = "KEY_STORE_PASSWORD_SET";
keyStorePassword = sslPolicy.getKeystorePassword();
- return;
- }
- keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
- if (keyStorePassword != null) {
- LogUtils.log(LOG, Level.INFO, "KEY_STORE_PASSWORD_SYSTEM_PROPERTY_SET");
- return;
- }
- LogUtils.log(LOG, Level.INFO, "KEY_STORE_PASSWORD_NOT_SET");
-
+ } else {
+ keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
+ logMsg = keyStorePassword != null
+ ? "KEY_STORE_PASSWORD_SYSTEM_PROPERTY_SET"
+ : "KEY_STORE_PASSWORD_NOT_SET";
+ }
+ LogUtils.log(LOG, Level.INFO, logMsg);
+ return keyStorePassword;
}
- public void setupKeyPassword() {
+ public String setupKeyPassword() {
+ String keyPassword = null;
+ String logMsg = null;
if (sslPolicy.isSetKeyPassword()) {
- LogUtils.log(LOG, Level.INFO, "KEY_PASSWORD_SET");
+ logMsg = "KEY_PASSWORD_SET";
keyPassword = sslPolicy.getKeyPassword();
- return;
- }
- keyPassword = System.getProperty("javax.net.ssl.keyStorePassword");
- if (keyPassword != null) {
- LogUtils.log(LOG, Level.INFO, "KEY_PASSWORD_SYSTEM_PROPERTY_SET");
- return;
- }
-
- LogUtils.log(LOG, Level.INFO, "KEY_PASSWORD_NOT_SET");
+ } else {
+ keyPassword = System.getProperty("javax.net.ssl.keyStorePassword");
+ logMsg = keyPassword != null
+ ? "KEY_PASSWORD_SYSTEM_PROPERTY_SET"
+ : "KEY_PASSWORD_NOT_SET";
+ }
+ LogUtils.log(LOG, Level.INFO, logMsg);
+ return keyPassword;
}
-
-
-
- public void setupKeystoreAlgorithm() {
+
+ public String setupKeystoreAlgorithm() {
+ String keystoreKeyManagerFactoryAlgorithm = null;
+ String logMsg = null;
if (sslPolicy.isSetKeystoreAlgorithm()) {
keystoreKeyManagerFactoryAlgorithm = sslPolicy.getKeystoreAlgorithm();
- LogUtils.log(LOG, Level.INFO,
- "KEY_STORE_ALGORITHM_SET",
- new Object[] {keystoreKeyManagerFactoryAlgorithm});
- return;
- }
- keystoreKeyManagerFactoryAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
- LogUtils.log(LOG, Level.INFO,
- "KEY_STORE_ALGORITHM_NOT_SET",
+ logMsg = "KEY_STORE_ALGORITHM_SET";
+ } else {
+ keystoreKeyManagerFactoryAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
+ logMsg = "KEY_STORE_ALGORITHM_NOT_SET";
+ }
+ LogUtils.log(LOG, Level.INFO, logMsg,
new Object[] {keystoreKeyManagerFactoryAlgorithm});
+ return keystoreKeyManagerFactoryAlgorithm;
}
- public void setupTrustStoreAlgorithm() {
+ public String setupTrustStoreAlgorithm() {
+ String trustStoreKeyManagerFactoryAlgorithm = null;
+ String logMsg = null;
if (sslPolicy.isSetKeystoreAlgorithm()) {
trustStoreKeyManagerFactoryAlgorithm = sslPolicy.getTrustStoreAlgorithm();
- LogUtils.log(LOG, Level.INFO,
- "TRUST_STORE_ALGORITHM_SET",
- new Object[] {trustStoreKeyManagerFactoryAlgorithm});
- return;
- }
- trustStoreKeyManagerFactoryAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
- LogUtils.log(LOG, Level.INFO,
- "TRUST_STORE_ALGORITHM_NOT_SET",
+ logMsg = "TRUST_STORE_ALGORITHM_SET";
+ } else {
+ trustStoreKeyManagerFactoryAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
+ logMsg = "TRUST_STORE_ALGORITHM_NOT_SET";
+ }
+ LogUtils.log(LOG, Level.INFO, logMsg,
new Object[] {trustStoreKeyManagerFactoryAlgorithm});
+ return trustStoreKeyManagerFactoryAlgorithm;
}
- public void setupCiphersuites() {
+ public String[] setupCiphersuites() {
+ String[] cipherSuites = null;
if (sslPolicy.isSetCiphersuites()) {
List<String> cipherSuitesList = sslPolicy.getCiphersuites();
@@ -368,49 +375,61 @@
}
}
LogUtils.log(LOG, Level.INFO, "CIPHERSUITE_SET", new Object[]{ciphsStr});
- return;
+ } else {
+ LogUtils.log(LOG, Level.INFO, "CIPHERSUITE_NOT_SET");
}
- LogUtils.log(LOG, Level.INFO, "CIPHERSUITE_NOT_SET");
+ return cipherSuites;
}
- public void setupTrustStore() {
+ public String setupTrustStore() {
+ String trustStoreLocation;
+ String logMsg = null;
if (sslPolicy.isSetTrustStore()) {
trustStoreLocation = sslPolicy.getTrustStore();
- LogUtils.log(LOG, Level.INFO, "TRUST_STORE_SET", new Object[]{trustStoreLocation});
- return;
- }
-
- trustStoreLocation = System.getProperty("javax.net.ssl.trustStore");
- if (trustStoreLocation != null) {
- LogUtils.log(LOG, Level.INFO, "TRUST_STORE_SYSTEM_PROPERTY_SET",
- new Object[]{trustStoreLocation});
- return;
+ logMsg = "TRUST_STORE_SET";
+ } else {
+
+ trustStoreLocation = System.getProperty("javax.net.ssl.trustStore");
+ if (trustStoreLocation != null) {
+ logMsg = "TRUST_STORE_SYSTEM_PROPERTY_SET";
+ } else {
+ trustStoreLocation =
+ System.getProperty("java.home") + "/lib/security/cacerts";
+ logMsg = "TRUST_STORE_NOT_SET";
+ }
}
-
- trustStoreLocation = System.getProperty("java.home") + "/lib/security/cacerts";
- LogUtils.log(LOG, Level.INFO, "TRUST_STORE_NOT_SET", new Object[]{trustStoreLocation});
-
+ LogUtils.log(LOG, Level.INFO, logMsg, new Object[]{trustStoreLocation});
+ return trustStoreLocation;
}
- public void setupTrustStoreType() {
- if (!sslPolicy.isSetTrustStoreType()) {
- LogUtils.log(LOG, Level.INFO, "TRUST_STORE_TYPE_NOT_SET", new Object[]{DEFAUL_TRUST_STORE_TYPE});
- //Can default to JKS so return
- return;
+ public String setupTrustStoreType() {
+ String trustStoreType = null;
+ String logMsg = null;
+ if (sslPolicy.isSetTrustStoreType()) {
+ trustStoreType = sslPolicy.getTrustStoreType();
+ logMsg = "TRUST_STORE_TYPE_SET";
+ } else {
+ //Can default to JKS
+ trustStoreType = DEFAULT_TRUST_STORE_TYPE;
+ logMsg = "TRUST_STORE_TYPE_NOT_SET";
}
- trustStoreType = sslPolicy.getTrustStoreType();
- LogUtils.log(LOG, Level.INFO, "TRUST_STORE_TYPE_SET", new Object[]{trustStoreType});
+ LogUtils.log(LOG, Level.INFO, logMsg, new Object[]{trustStoreType});
+ return trustStoreType;
}
-
- public void setupSecureSocketProtocol() {
+ public String setupSecureSocketProtocol() {
+ String secureSocketProtocol = null;
if (!sslPolicy.isSetSecureSocketProtocol()) {
LogUtils.log(LOG, Level.INFO, "SECURE_SOCKET_PROTOCOL_NOT_SET");
secureSocketProtocol = DEFAULT_SECURE_SOCKET_PROTOCOL;
- return;
+ } else {
+ secureSocketProtocol = sslPolicy.getSecureSocketProtocol();
+ LogUtils.log(LOG,
+ Level.INFO,
+ "SECURE_SOCKET_PROTOCOL_SET",
+ new Object[] {secureSocketProtocol});
}
- secureSocketProtocol = sslPolicy.getSecureSocketProtocol();
- LogUtils.log(LOG, Level.INFO, "SECURE_SOCKET_PROTOCOL_SET", new Object[] {secureSocketProtocol});
+ return secureSocketProtocol;
}
public boolean setupSessionCaching() {
@@ -461,43 +480,9 @@
return true;
}
-
- public void setupSecurityConfigurer() {
- String systemProperty = "celtix.security.configurer."
- + config.getId().toString();
- String securityConfigurerName =
- System.getProperty(systemProperty);
-
- if ((securityConfigurerName == null)
- || (securityConfigurerName.equals(""))) {
- return;
- }
- LogUtils.log(LOG, Level.WARNING, "UNOFFICIAL_SECURITY_CONFIGURER");
-
- try {
- Class clazz = Class.forName(securityConfigurerName);
- Method configure = clazz.getDeclaredMethod("configure", SSLClientPolicy.class);
- Object[] params = new Object[]{sslPolicy};
- Object configurer = clazz.newInstance();
- configure.invoke(configurer, params);
- LogUtils.log(LOG, Level.INFO, "SUCCESS_INVOKING_SECURITY_CONFIGURER",
- new Object[]{securityConfigurerName});
- } catch (Exception e) {
- LogUtils.log(LOG, Level.SEVERE, "ERROR_INVOKING_SECURITY_CONFIGURER",
- new Object[]{securityConfigurerName, e.getMessage()});
- }
- }
-
- protected HttpsURLConnection getHttpsConnection() {
- return httpsConnection;
- }
-
-
/*
* For development and testing only
- */
-
-
+ */
protected boolean testAllDataHasSetupMethod() {
Method[] sslPolicyMethods = sslPolicy.getClass().getDeclaredMethods();
Class[] classArgs = null;
@@ -523,6 +508,5 @@
protected void addLogHandler(Handler handler) {
LOG.addHandler(handler);
}
-
}
Copied: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLSocketFactoryWrapper.java (from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/main/java/org/objectweb/celtix/transports/https/SSLSocketFactoryWrapper.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLSocketFactoryWrapper.java?view=diff&rev=451949&p1=incubator/cxf/branches/post_apache_integration/rt/transports/http/src/main/java/org/objectweb/celtix/transports/https/SSLSocketFactoryWrapper.java&r1=438444&p2=incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLSocketFactoryWrapper.java&r2=451949
==============================================================================
--- incubator/cxf/branches/post_apache_integration/rt/transports/http/src/main/java/org/objectweb/celtix/transports/https/SSLSocketFactoryWrapper.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLSocketFactoryWrapper.java Mon Oct 2 03:20:43 2006
@@ -1,4 +1,22 @@
-package org.objectweb.celtix.transports.https;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.transport.https;
import java.io.IOException;
@@ -12,7 +30,7 @@
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
-import org.objectweb.celtix.common.logging.LogUtils;
+import org.apache.cxf.common.logging.LogUtils;
class SSLSocketFactoryWrapper extends SSLSocketFactory {
Copied: incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/HttpsURLConnectionFactoryTest.java (from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/JettySslClientConfigurerTest.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/HttpsURLConnectionFactoryTest.java?view=diff&rev=451949&p1=incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/JettySslClientConfigurerTest.java&r1=438444&p2=incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/HttpsURLConnectionFactoryTest.java&r2=451949
==============================================================================
--- incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/JettySslClientConfigurerTest.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/HttpsURLConnectionFactoryTest.java Mon Oct 2 03:20:43 2006
@@ -1,61 +1,55 @@
-package org.objectweb.celtix.transports.https;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.transport.https;
import java.net.URL;
import java.util.Properties;
import javax.net.ssl.SSLSocketFactory;
-import junit.extensions.TestSetup;
-import junit.framework.Test;
import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.easymock.classextension.EasyMock;
-import org.objectweb.celtix.Bus;
-import org.objectweb.celtix.BusException;
-import org.objectweb.celtix.bus.configuration.security.SSLClientPolicy;
-import org.objectweb.celtix.configuration.CompoundName;
-import org.objectweb.celtix.configuration.Configuration;
-import org.objectweb.celtix.transports.http.JettyHTTPServerEngine;
-
-public class JettySslClientConfigurerTest extends TestCase {
-
- private static final String DROP_BACK_SRC_DIR = "../../../../../../../"
- + "src/test/java/org/objectweb/celtix/transports/https/";
- private static final CompoundName HTTP_CLIENT_CONFIG_ID = new CompoundName("celtix", "port",
- "http-client");
+import org.apache.cxf.configuration.security.SSLClientPolicy;
- Bus bus;
- private Configuration configuration;
- public JettySslClientConfigurerTest(String arg0) {
- super(arg0);
- }
+public class HttpsURLConnectionFactoryTest extends TestCase {
- public static Test suite() throws Exception {
- TestSuite suite = new TestSuite(JettySslClientConfigurerTest.class);
- return new TestSetup(suite) {
- protected void tearDown() throws Exception {
- super.tearDown();
- JettyHTTPServerEngine.destroyForPort(9000);
- }
- };
+ private static final String DROP_BACK_SRC_DIR =
+ "../../../../../../../"
+ + "src/test/java/org/apache/cxf/transport/https/";
+
+ private TestHttpsURLConnection connection;
+
+ public HttpsURLConnectionFactoryTest(String arg0) {
+ super(arg0);
}
public static void main(String[] args) {
- junit.textui.TestRunner.run(JettySslClientConfigurerTest.class);
+ junit.textui.TestRunner.run(HttpsURLConnectionFactoryTest.class);
}
- public void setUp() throws BusException {
- bus = EasyMock.createMock(Bus.class);
-
- configuration = EasyMock.createMock(Configuration.class);
+ public void setUp() throws Exception {
+ connection = new TestHttpsURLConnection(null);
}
public void tearDown() throws Exception {
- EasyMock.reset(bus);
- EasyMock.reset(configuration);
-
Properties props = System.getProperties();
props.remove("javax.net.ssl.trustStore");
props.remove("javax.net.ssl.keyStore");
@@ -63,19 +57,17 @@
props.remove("javax.net.ssl.keyStorePassword");
}
+ /*
public void testSecurityConfigurer() {
try {
- System.setProperty("celtix.security.configurer." + HTTP_CLIENT_CONFIG_ID.toString(),
- "org.objectweb.celtix.transports.https.SetAllDataSecurityDataProvider");
-
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
- TestHandler handler = new TestHandler();
+ TestLogHandler handler = new TestLogHandler();
- JettySslClientConfigurer jettySslClientConfigurer =
- createJettySslClientConfigurer(sslClientPolicy, "https://dummyurl", handler);
+ HttpsURLConnectionFactory factory =
+ createFactory(sslClientPolicy, "https://dummyurl", handler);
- jettySslClientConfigurer.configure();
+ factory.decorate(connection);
assertTrue("Keystore loaded success message not present", handler
.checkLogContainsString("Successfully loaded keystore"));
@@ -128,8 +120,9 @@
System.getProperties().remove("celtix.security.configurer." + HTTP_CLIENT_CONFIG_ID.toString());
}
}
+ */
- public void testSetAllData() {
+ public void testSetAllData() throws Exception {
String keyStoreStr = getPath("resources/defaultkeystore");
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
@@ -150,15 +143,13 @@
String trustStoreStr = getPath("resources/defaulttruststore");
sslClientPolicy.setTrustStore(trustStoreStr);
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
-
- jettySslClientConfigurer.configure();
- SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer.getHttpsConnection()
- .getSSLSocketFactory();
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
+
+ factory.decorate(connection);
+ SSLSocketFactory sSLSocketFactory = connection.getSSLSocketFactory();
assertTrue(sSLSocketFactory instanceof SSLSocketFactoryWrapper);
assertTrue("Keystore loaded success message not present", handler
@@ -207,7 +198,7 @@
.checkLogContainsString("Unsupported SSLClientPolicy property : CertValidator"));
}
- public void testAllValidDataJKS() {
+ public void testAllValidDataJKS() throws Exception {
String keyStoreStr = getPath("resources/defaultkeystore");
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
@@ -218,16 +209,14 @@
sslClientPolicy.setKeystoreType("JKS");
String trustStoreStr = getPath("resources/defaulttruststore");
sslClientPolicy.setTrustStore(trustStoreStr);
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
- jettySslClientConfigurer.configure();
+ factory.decorate(connection);
- SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer.getHttpsConnection()
- .getSSLSocketFactory();
+ SSLSocketFactory sSLSocketFactory = connection.getSSLSocketFactory();
assertTrue(sSLSocketFactory instanceof SSLSocketFactoryWrapper);
assertTrue("Keystore loaded success message not present", handler
@@ -237,7 +226,7 @@
}
- public void testAllValidDataPKCS12() {
+ public void testAllValidDataPKCS12() throws Exception {
String keyStoreStr = getPath("resources/celtix.p12");
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
@@ -248,14 +237,12 @@
sslClientPolicy.setKeystoreType("PKCS12");
String trustStoreStr = getPath("resources/abigcompany_ca.pem");
sslClientPolicy.setTrustStore(trustStoreStr);
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
- jettySslClientConfigurer.configure();
- SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer.getHttpsConnection()
- .getSSLSocketFactory();
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
+ factory.decorate(connection);
+ SSLSocketFactory sSLSocketFactory = connection.getSSLSocketFactory();
assertTrue(sSLSocketFactory instanceof SSLSocketFactoryWrapper);
assertTrue("Keystore loaded success message not present", handler
@@ -265,7 +252,7 @@
}
- public void testNonExistentKeystoreJKS() {
+ public void testNonExistentKeystoreJKS() throws Exception {
String keyStoreStr = getPath("resources/defaultkeystoredontexist");
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
@@ -276,14 +263,12 @@
sslClientPolicy.setKeystoreType("JKS");
String trustStoreStr = getPath("resources/defaulttruststore");
sslClientPolicy.setTrustStore(trustStoreStr);
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
- jettySslClientConfigurer.configure();
- SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer.getHttpsConnection()
- .getSSLSocketFactory();
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
+ factory.decorate(connection);
+ SSLSocketFactory sSLSocketFactory = connection.getSSLSocketFactory();
boolean isNewSocketFactory = sSLSocketFactory instanceof SSLSocketFactoryWrapper;
assertTrue("sSLSocketFactory should be null", !isNewSocketFactory);
assertTrue("SSLContext should have failed, invalid keystore location", handler
@@ -291,7 +276,7 @@
}
- public void testNonExistentKeystorePKCS12() {
+ public void testNonExistentKeystorePKCS12() throws Exception {
String keyStoreStr = getPath("resources/defaultkeystoredontexist");
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
@@ -301,14 +286,12 @@
String trustStoreStr = getPath("resources/abigcompany_ca.pem");
sslClientPolicy.setTrustStore(trustStoreStr);
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
- jettySslClientConfigurer.configure();
- SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer.getHttpsConnection()
- .getSSLSocketFactory();
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
+ factory.decorate(connection);
+ SSLSocketFactory sSLSocketFactory = connection.getSSLSocketFactory();
boolean isNewSocketFactory = sSLSocketFactory instanceof SSLSocketFactoryWrapper;
assertTrue("sSLSocketFactory should be null", !isNewSocketFactory);
assertTrue("SSLContext should have failed, invalid keystore location", handler
@@ -316,7 +299,7 @@
}
- public void testWrongKeystorePasswordJKS() {
+ public void testWrongKeystorePasswordJKS() throws Exception {
String keyStoreStr = getPath("resources/defaultkeystore");
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
@@ -327,14 +310,12 @@
sslClientPolicy.setKeystoreType("JKS");
String trustStoreStr = getPath("resources/defaulttruststore");
sslClientPolicy.setTrustStore(trustStoreStr);
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
- jettySslClientConfigurer.configure();
- SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer.getHttpsConnection()
- .getSSLSocketFactory();
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
+ factory.decorate(connection);
+ SSLSocketFactory sSLSocketFactory = connection.getSSLSocketFactory();
boolean isNewSocketFactory = sSLSocketFactory instanceof SSLSocketFactoryWrapper;
assertTrue("sSLSocketFactory should be non and a new one", isNewSocketFactory);
assertTrue("SSLContext init should have passed, but keystore initialization failed, invalid "
@@ -354,7 +335,7 @@
}
- public void testWrongKeystorePasswordPKCS12() {
+ public void testWrongKeystorePasswordPKCS12() throws Exception {
String keyStoreStr = getPath("resources/celtix.p12");
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
@@ -364,14 +345,12 @@
String trustStoreStr = getPath("resources/abigcompany_ca.pem");
sslClientPolicy.setTrustStore(trustStoreStr);
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
- jettySslClientConfigurer.configure();
- SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer.getHttpsConnection()
- .getSSLSocketFactory();
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
+ factory.decorate(connection);
+ SSLSocketFactory sSLSocketFactory = connection.getSSLSocketFactory();
boolean isNewSocketFactory = sSLSocketFactory instanceof SSLSocketFactoryWrapper;
assertTrue("sSLSocketFactory should be non and a new one", isNewSocketFactory);
assertTrue("SSLContext init should have passed, but keystore initialization failed, invalid "
@@ -392,7 +371,7 @@
}
- public void testWrongKeyPasswordJKS() {
+ public void testWrongKeyPasswordJKS() throws Exception {
String keyStoreStr = getPath("resources/defaultkeystore");
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
@@ -403,14 +382,12 @@
sslClientPolicy.setKeystoreType("JKS");
String trustStoreStr = getPath("resources/defaulttruststore");
sslClientPolicy.setTrustStore(trustStoreStr);
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
- jettySslClientConfigurer.configure();
- SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer.getHttpsConnection()
- .getSSLSocketFactory();
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
+ factory.decorate(connection);
+ SSLSocketFactory sSLSocketFactory = connection.getSSLSocketFactory();
boolean isNewSocketFactory = sSLSocketFactory instanceof SSLSocketFactoryWrapper;
assertTrue("sSLSocketFactory should be non and a new one", isNewSocketFactory);
assertTrue("SSLContext init should have passed, and keystore initialization succeedeed, "
@@ -426,7 +403,7 @@
}
- public void testWrongKeyPasswordPKCS12() {
+ public void testWrongKeyPasswordPKCS12() throws Exception {
String keyStoreStr = getPath("resources/celtix.p12");
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
@@ -436,14 +413,12 @@
String trustStoreStr = getPath("resources/abigcompany_ca.pem");
sslClientPolicy.setTrustStore(trustStoreStr);
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
- jettySslClientConfigurer.configure();
- SSLSocketFactory sSLSocketFactory = jettySslClientConfigurer.getHttpsConnection()
- .getSSLSocketFactory();
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
+ factory.decorate(connection);
+ SSLSocketFactory sSLSocketFactory = connection.getSSLSocketFactory();
boolean isNewSocketFactory = sSLSocketFactory instanceof SSLSocketFactoryWrapper;
assertTrue("sSLSocketFactory should be non and a new one", isNewSocketFactory);
assertTrue("SSLContext init should have passed, and keystore initialization succeedeed, "
@@ -459,40 +434,29 @@
}
- public void testAllElementsHaveSetupMethod() {
+ public void testAllElementsHaveSetupMethod() throws Exception {
SSLClientPolicy sslClientPolicy = new SSLClientPolicy();
- TestHandler handler = new TestHandler();
- JettySslClientConfigurer jettySslClientConfigurer = createJettySslClientConfigurer(
- sslClientPolicy,
- "https://dummyurl",
- handler);
+ TestLogHandler handler = new TestLogHandler();
+ HttpsURLConnectionFactory factory = createFactory(sslClientPolicy,
+ "https://dummyurl",
+ handler);
assertTrue("A new element has been " + "added to SSLClientPolicy without a corresponding "
- + "setup method in the configurer.", jettySslClientConfigurer.testAllDataHasSetupMethod());
+ + "setup method in the configurer.", factory.testAllDataHasSetupMethod());
}
- private JettySslClientConfigurer createJettySslClientConfigurer(SSLClientPolicy sslClientPolicy,
- String urlStr, TestHandler handler) {
-
- EasyMock.expect(configuration.getId()).andReturn(HTTP_CLIENT_CONFIG_ID);
- EasyMock.replay(configuration);
- try {
- DummyHttpsConnection connection = new DummyHttpsConnection(null);
- JettySslClientConfigurer jettySslClientConfigurer = new JettySslClientConfigurer(sslClientPolicy,
- connection,
- configuration);
-
- jettySslClientConfigurer.addLogHandler(handler);
- return jettySslClientConfigurer;
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- EasyMock.verify(configuration);
- return null;
+ private HttpsURLConnectionFactory createFactory(SSLClientPolicy sslClientPolicy,
+ String urlStr,
+ TestLogHandler handler)
+ throws Exception {
+ HttpsURLConnectionFactory factory =
+ new HttpsURLConnectionFactory();
+ factory.setSSLPolicy(sslClientPolicy);
+ factory.addLogHandler(handler);
+ return factory;
}
protected static String getPath(String fileName) {
- URL keystoreURL = JettySslClientConfigurerTest.class.getResource(".");
+ URL keystoreURL = HttpsURLConnectionFactoryTest.class.getResource(".");
String str = keystoreURL.getFile();
str += DROP_BACK_SRC_DIR + fileName;
return str;
@@ -504,5 +468,4 @@
}
return false;
}
-
}
Copied: incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestHttpsURLConnection.java (from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/DummyHttpsConnection.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestHttpsURLConnection.java?view=diff&rev=451949&p1=incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/DummyHttpsConnection.java&r1=438444&p2=incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestHttpsURLConnection.java&r2=451949
==============================================================================
--- incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/DummyHttpsConnection.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestHttpsURLConnection.java Mon Oct 2 03:20:43 2006
@@ -1,4 +1,23 @@
-package org.objectweb.celtix.transports.https;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.transport.https;
import java.io.IOException;
import java.net.URL;
@@ -7,16 +26,15 @@
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;
-class DummyHttpsConnection extends HttpsURLConnection {
+class TestHttpsURLConnection extends HttpsURLConnection {
- protected DummyHttpsConnection(URL arg0) {
+ protected TestHttpsURLConnection(URL arg0) {
super(arg0);
}
public String getCipherSuite() {
return null;
}
-
public void disconnect() {
@@ -45,5 +63,4 @@
// TODO Auto-generated method stub
return null;
}
-
}
Copied: incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestLogHandler.java (from r438444, incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/TestHandler.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestLogHandler.java?view=diff&rev=451949&p1=incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/TestHandler.java&r1=438444&p2=incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestLogHandler.java&r2=451949
==============================================================================
--- incubator/cxf/branches/post_apache_integration/rt/transports/http/src/test/java/org/objectweb/celtix/transports/https/TestHandler.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/https/TestLogHandler.java Mon Oct 2 03:20:43 2006
@@ -1,23 +1,40 @@
-package org.objectweb.celtix.transports.https;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.transport.https;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
-class TestHandler extends Handler {
+class TestLogHandler extends Handler {
String log;
- public TestHandler() {
+ public TestLogHandler() {
log = "";
}
-
public void publish(LogRecord record) {
log += record.getMessage();
}
-
public void flush() {
}
@@ -31,6 +48,5 @@
return false;
}
return true;
- }
-
+ }
}