Author: davsclaus
Date: Sat May 10 05:43:02 2008
New Revision: 655071
URL: http://svn.apache.org/viewvc?rev=655071&view=rev
Log:
CAMEL-491
- added dummyTrustManager option for easier testing with SSL (not requiring to
install certificates in local keystore)
Added:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummySSLSocketFactory.java
(with props)
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummyTrustManager.java
(with props)
Modified:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
Modified:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java?rev=655071&r1=655070&r2=655071&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
(original)
+++
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
Sat May 10 05:43:02 2008
@@ -20,10 +20,10 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-
import javax.mail.Message;
import javax.mail.Session;
+import org.apache.camel.component.mail.security.DummySSLSocketFactory;
import org.springframework.mail.javamail.JavaMailSenderImpl;
/**
@@ -54,6 +54,7 @@
private int fetchSize = -1;
private boolean debugMode;
private long connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
+ private boolean dummyTrustManager;
public MailConfiguration() {
}
@@ -124,11 +125,12 @@
if (username != null) {
answer.setUsername(username);
}
+
return answer;
}
private Properties createJavaMailProperties() {
- // clone the system properties
+ // clone the system properties and set the java mail properties
Properties properties = (Properties)System.getProperties().clone();
properties.put("mail." + protocol + ".connectiontimeout",
connectionTimeout);
properties.put("mail." + protocol + ".timeout", connectionTimeout);
@@ -141,6 +143,18 @@
properties.put("mail.store.protocol", protocol);
properties.put("mail.host", host);
properties.put("mail.user", username);
+
+ if (debugMode) {
+ properties.put("javax.net.debug", "all");
+ }
+
+ if (dummyTrustManager && isSecureProtocol()) {
+ // set the custom SSL properties
+ properties.put("mail." + protocol + ".socketFactory.class",
DummySSLSocketFactory.class.getName());
+ properties.put("mail." + protocol + ".socketFactory.fallback",
"false");
+ properties.put("mail." + protocol + ".socketFactory.port", "" +
port);
+ }
+
return properties;
}
@@ -153,7 +167,12 @@
}
public String getMailStoreLogInformation() {
- return protocol + "//" + host + ":" + port + (isSecureProtocol() ? "
(SSL enabled)" : "") + ", folder=" + folderName;
+ String ssl = "";
+ if (isSecureProtocol()) {
+ ssl = "(SSL enabled" + (dummyTrustManager ? " using
DummyTrustManager)" : ")");
+ }
+
+ return protocol + "//" + host + ":" + port + ssl + ", folder=" +
folderName;
}
// Properties
@@ -338,4 +357,11 @@
this.connectionTimeout = connectionTimeout;
}
+ public boolean isDummyTrustManager() {
+ return dummyTrustManager;
+ }
+
+ public void setDummyTrustManager(boolean dummyTrustManager) {
+ this.dummyTrustManager = dummyTrustManager;
+ }
}
Added:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummySSLSocketFactory.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummySSLSocketFactory.java?rev=655071&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummySSLSocketFactory.java
(added)
+++
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummySSLSocketFactory.java
Sat May 10 05:43:02 2008
@@ -0,0 +1,95 @@
+/**
+ * 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.camel.component.mail.security;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * DummySSLSocketFactory for testing with SSL - <b>NOT SECURE</b>.
+ * <p/>
+ * This factory is only to be used for testing purposes.
+ */
+public class DummySSLSocketFactory extends SSLSocketFactory {
+
+ private static final transient Log LOG =
LogFactory.getLog(DummySSLSocketFactory.class);
+ private SSLSocketFactory factory;
+
+ public DummySSLSocketFactory() {
+ try {
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ TrustManager[] trustManagers = new TrustManager[] { new
DummyTrustManager()};
+ sslContext.init(null, trustManagers, new
java.security.SecureRandom());
+ factory = sslContext.getSocketFactory();
+ } catch (Exception e) {
+ throw new RuntimeCamelException("Error creating
DummySSLSocketFactory: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Must provide this getDefault operation for JavaMail to be able to use
this factory.
+ */
+ public static SocketFactory getDefault() {
+ LOG.warn("Camel is using DummySSLSocketFactory as SSLSocketFactory
(only to be used for testing purpose)");
+ return new DummySSLSocketFactory();
+ }
+
+ public String[] getDefaultCipherSuites() {
+ return factory.getDefaultCipherSuites();
+ }
+
+ public String[] getSupportedCipherSuites() {
+ return factory.getSupportedCipherSuites();
+ }
+
+ public Socket createSocket(Socket socket, String host, int port, boolean
autoClose) throws IOException {
+ return factory.createSocket(socket, host, port, autoClose);
+ }
+
+ public Socket createSocket(String host, int port) throws IOException {
+ return factory.createSocket(host, port);
+ }
+
+ public Socket createSocket(String host, int port, InetAddress
localAddress, int localPort)
+ throws IOException {
+ return factory.createSocket(host, port, localAddress, localPort);
+ }
+
+ public Socket createSocket(InetAddress host, int port) throws IOException {
+ return factory.createSocket(host, port);
+ }
+
+ public Socket createSocket(InetAddress address, int port, InetAddress
localAddress, int localPort)
+ throws IOException {
+ return factory.createSocket(address, port, localAddress, localPort);
+ }
+
+ public Socket createSocket() throws IOException {
+ // must have this createSocket method
+ return factory.createSocket();
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummySSLSocketFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummySSLSocketFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummyTrustManager.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummyTrustManager.java?rev=655071&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummyTrustManager.java
(added)
+++
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummyTrustManager.java
Sat May 10 05:43:02 2008
@@ -0,0 +1,57 @@
+/**
+ * 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.camel.component.mail.security;
+
+import java.security.cert.X509Certificate;
+import java.security.cert.CertificateException;
+import javax.net.ssl.X509TrustManager;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+/**
+ * DummyTrustManager that accepts any given certificate - <b>NOT SECURE</b>.
+ */
+public class DummyTrustManager implements X509TrustManager {
+
+ private static final transient Log LOG =
LogFactory.getLog(DummyTrustManager.class);
+
+ public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
+ // everything is trusted
+ logCertificateChain("Client", chain);
+ }
+
+ public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
+ // everything is trusted
+ logCertificateChain("Server", chain);
+ }
+
+ public X509Certificate[] getAcceptedIssuers() {
+ // everything is trusted
+ return new X509Certificate[0];
+ }
+
+ private static void logCertificateChain(String type, X509Certificate[]
chain) {
+ if (LOG.isDebugEnabled()) {
+ for (X509Certificate certificate : chain) {
+ LOG.debug(type + " certificate is trusted: " + certificate);
+ }
+ }
+ }
+
+}
+
Propchange:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummyTrustManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/security/DummyTrustManager.java
------------------------------------------------------------------------------
svn:keywords = Rev Date