Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4B1689D7B for ; Mon, 5 Mar 2012 15:50:21 +0000 (UTC) Received: (qmail 76368 invoked by uid 500); 5 Mar 2012 15:50:20 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 76334 invoked by uid 500); 5 Mar 2012 15:50:20 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 76303 invoked by uid 99); 5 Mar 2012 15:50:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2012 15:50:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2012 15:50:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2A1C1238889B; Mon, 5 Mar 2012 15:49:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1297097 - in /camel/trunk/components/camel-mail/src: main/java/org/apache/camel/component/mail/ test/java/org/apache/camel/component/mail/security/ test/resources/jsse/ Date: Mon, 05 Mar 2012 15:49:59 -0000 To: commits@camel.apache.org From: dvaleri@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120305154959.2A1C1238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dvaleri Date: Mon Mar 5 15:49:58 2012 New Revision: 1297097 URL: http://svn.apache.org/viewvc?rev=1297097&view=rev Log: [CAMEL-4665] Added support for JSSE Configuration Utility to Camel Mail component. Added: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java (with props) camel/trunk/components/camel-mail/src/test/resources/jsse/ camel/trunk/components/camel-mail/src/test/resources/jsse/localhost.ks Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java?rev=1297097&r1=1297096&r2=1297097&view=diff ============================================================================== --- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java (original) +++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java Mon Mar 5 15:49:58 2012 @@ -181,6 +181,8 @@ public class MailConfiguration implement throw new RuntimeCamelException("Error initializing SSLContext.", e); } properties.put("mail." + protocol + ".socketFactory", sslContext.getSocketFactory()); + properties.put("mail." + protocol + ".socketFactory.fallback", "false"); + properties.put("mail." + protocol + ".socketFactory.port", "" + port); } if (dummyTrustManager && isSecureProtocol()) { // set the custom SSL properties Added: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java?rev=1297097&view=auto ============================================================================== --- camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java (added) +++ camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java Mon Mar 5 15:49:58 2012 @@ -0,0 +1,146 @@ +/** + * 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.util.HashMap; + +import javax.net.ssl.SSLHandshakeException; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.util.jsse.KeyManagersParameters; +import org.apache.camel.util.jsse.KeyStoreParameters; +import org.apache.camel.util.jsse.SSLContextParameters; +import org.apache.camel.util.jsse.TrustManagersParameters; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Test of integration between the mail component and JSSE Configuration Utility. + * This test does not easily automate. This test is therefore ignored and the + * source is maintained here for easier development in the future. + */ +@Ignore +public class SslContextParametersMailRouteTest extends CamelTestSupport { + + protected static final String KEY_STORE_PASSWORD = "changeit"; + + private String email = "USERNAME@gmail.com"; + private String username = "USERNAME@gmail.com"; + private String imapHost = "imap.gmail.com"; + private String smtpHost = "smtp.gmail.com"; + private String password = "PASSWORD"; + + @Test + public void testSendAndReceiveMails() throws Exception { + + context.addRoutes(new RouteBuilder() { + public void configure() { + + from("imaps://" + imapHost + "?username=" + username + "&password=" + password + + "&delete=false&unseen=true&fetchSize=1&consumer.useFixedDelay=true&consumer.delay=1000") + .to("mock:in"); + + from("direct:in") + .to("smtps://" + smtpHost + "?username=" + username + "&password=" + password); + } + }); + + context.start(); + + MockEndpoint resultEndpoint = getMockEndpoint("mock:in"); + resultEndpoint.expectedBodiesReceived("Test Email Body\r\n"); + + HashMap headers = new HashMap(); + headers.put("To", email); + headers.put("From", email); + headers.put("Reply-to", email); + headers.put("Subject", "SSL/TLS Test"); + + template.sendBodyAndHeaders("direct:in", "Test Email Body", headers); + + resultEndpoint.assertIsSatisfied(); + } + + @Test + public void testSendAndReceiveMailsWithCustomTrustStore() throws Exception { + + context.addRoutes(new RouteBuilder() { + public void configure() { + + from("direct:in") + .to("smtps://" + smtpHost + "?username=" + username + "&password=" + password + + "&sslContextParameters=#sslContextParameters"); + } + }); + + context.start(); + + HashMap headers = new HashMap(); + headers.put("To", email); + headers.put("From", email); + headers.put("Reply-to", email); + headers.put("Subject", "SSL/TLS Test"); + + try { + template.sendBodyAndHeaders("direct:in", "Test Email Body", headers); + } catch (CamelExecutionException e) { + assertTrue(e.getCause().getCause() instanceof SSLHandshakeException); + assertTrue(e.getCause().getCause().getMessage().contains( + "unable to find valid certification path to requested target")); + } + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry reg = super.createRegistry(); + + addSslContextParametersToRegistry(reg); + + return reg; + } + + protected void addSslContextParametersToRegistry(JndiRegistry registry) { + KeyStoreParameters ksp = new KeyStoreParameters(); + ksp.setResource(this.getClass().getClassLoader().getResource("jsse/localhost.ks").toString()); + ksp.setPassword(KEY_STORE_PASSWORD); + + KeyManagersParameters kmp = new KeyManagersParameters(); + kmp.setKeyPassword(KEY_STORE_PASSWORD); + kmp.setKeyStore(ksp); + + TrustManagersParameters tmp = new TrustManagersParameters(); + tmp.setKeyStore(ksp); + + SSLContextParameters sslContextParameters = new SSLContextParameters(); + sslContextParameters.setKeyManagers(kmp); + sslContextParameters.setTrustManagers(tmp); + + registry.bind("sslContextParameters", sslContextParameters); + } + + /** + * Stop Camel startup. + */ + @Override + public boolean isUseAdviceWith() { + return true; + } +} Propchange: camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/security/SslContextParametersMailRouteTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: camel/trunk/components/camel-mail/src/test/resources/jsse/localhost.ks URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/test/resources/jsse/localhost.ks?rev=1297097&view=auto ============================================================================== Files camel/trunk/components/camel-mail/src/test/resources/jsse/localhost.ks (added) and camel/trunk/components/camel-mail/src/test/resources/jsse/localhost.ks Mon Mar 5 15:49:58 2012 differ