You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by si...@apache.org on 2017/03/22 13:04:25 UTC
camel git commit: CAMEL-11047: STARTTLS broken with camel-mail
Repository: camel
Updated Branches:
refs/heads/master a8910d540 -> 86ba6933d
CAMEL-11047: STARTTLS broken with camel-mail
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/86ba6933
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/86ba6933
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/86ba6933
Branch: refs/heads/master
Commit: 86ba6933d161db1fb4ca9c2c680942b3ced6a0fc
Parents: a8910d5
Author: Stephan Siano <st...@sap.com>
Authored: Wed Mar 22 13:30:19 2017 +0100
Committer: Stephan Siano <st...@sap.com>
Committed: Wed Mar 22 14:03:50 2017 +0100
----------------------------------------------------------------------
.../camel/component/mail/MailConfiguration.java | 35 ++++++++++++--------
.../component/mail/MailEndpointTlsTest.java | 15 ++++-----
2 files changed, 28 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/86ba6933/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
index 9b4df7a..2ab4b26 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
@@ -244,27 +244,38 @@ public class MailConfiguration implements Cloneable {
properties.put("javax.net.debug", "all");
}
- if (sslContextParameters != null && (isSecureProtocol() || isStartTlsEnabled())) {
- SSLContext sslContext;
- try {
- sslContext = sslContextParameters.createSSLContext();
- } catch (Exception e) {
- throw new RuntimeCamelException("Error initializing SSLContext.", e);
- }
- properties.put("mail." + protocol + ".socketFactory", sslContext.getSocketFactory());
+ if (sslContextParameters != null && isSecureProtocol()) {
+ properties.put("mail." + protocol + ".socketFactory", createSSLContext().getSocketFactory());
properties.put("mail." + protocol + ".socketFactory.fallback", "false");
properties.put("mail." + protocol + ".socketFactory.port", "" + port);
}
- if (dummyTrustManager && (isSecureProtocol() || isStartTlsEnabled())) {
+ if (sslContextParameters != null && isStartTlsEnabled()) {
+ properties.put("mail." + protocol + ".ssl.socketFactory", createSSLContext().getSocketFactory());
+ properties.put("mail." + protocol + ".ssl.socketFactory.port", "" + port);
+ }
+ if (dummyTrustManager && isSecureProtocol()) {
// set the custom SSL properties
properties.put("mail." + protocol + ".socketFactory.class", "org.apache.camel.component.mail.DummySSLSocketFactory");
properties.put("mail." + protocol + ".socketFactory.fallback", "false");
properties.put("mail." + protocol + ".socketFactory.port", "" + port);
}
+ if (dummyTrustManager && isStartTlsEnabled()) {
+ // set the custom SSL properties
+ properties.put("mail." + protocol + ".ssl.socketFactory.class", "org.apache.camel.component.mail.DummySSLSocketFactory");
+ properties.put("mail." + protocol + ".ssl.socketFactory.port", "" + port);
+ }
return properties;
}
+ private SSLContext createSSLContext() {
+ try {
+ return sslContextParameters.createSSLContext();
+ } catch (Exception e) {
+ throw new RuntimeCamelException("Error initializing SSLContext.", e);
+ }
+ }
+
/**
* Is the used protocol to be secure or not
*/
@@ -275,10 +286,8 @@ public class MailConfiguration implements Cloneable {
public boolean isStartTlsEnabled() {
if (additionalJavaMailProperties != null) {
- return ObjectHelper.equal(
- additionalJavaMailProperties.getProperty("mail." + protocol + ".starttls.enable"),
- "true",
- true);
+ return ObjectHelper.equal(additionalJavaMailProperties.getProperty("mail." + protocol + ".starttls.enable"), "true", true)
+ || ObjectHelper.equal(additionalJavaMailProperties.getProperty("mail." + protocol + ".starttls.required"), "true", true);
}
return false;
http://git-wip-us.apache.org/repos/asf/camel/blob/86ba6933/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java
index fcd70e1..9e6782a 100644
--- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java
+++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailEndpointTlsTest.java
@@ -62,9 +62,8 @@ public class MailEndpointTlsTest extends CamelTestSupport {
assertTrue(cfg.isStartTlsEnabled());
Properties javaMailProperties = cfg.createJavaMailSender().getJavaMailProperties();
- assertNull(javaMailProperties.get("mail." + protocol + ".socketFactory"));
- assertNull(javaMailProperties.get("mail." + protocol + ".socketFactory.fallback"));
- assertNull(javaMailProperties.get("mail." + protocol + ".socketFactory.port"));
+ assertNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory"));
+ assertNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory.port"));
}
@Test
@@ -111,9 +110,8 @@ public class MailEndpointTlsTest extends CamelTestSupport {
assertTrue(cfg.isStartTlsEnabled());
Properties javaMailProperties = cfg.createJavaMailSender().getJavaMailProperties();
- assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory"));
- assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.fallback"));
- assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.port"));
+ assertNotNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory"));
+ assertNotNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory.port"));
}
@Test
@@ -133,8 +131,7 @@ public class MailEndpointTlsTest extends CamelTestSupport {
assertTrue(cfg.isStartTlsEnabled());
Properties javaMailProperties = cfg.createJavaMailSender().getJavaMailProperties();
- assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.class"));
- assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.fallback"));
- assertNotNull(javaMailProperties.get("mail." + protocol + ".socketFactory.port"));
+ assertNotNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory.class"));
+ assertNotNull(javaMailProperties.get("mail." + protocol + ".ssl.socketFactory.port"));
}
}