From aaf03576ee287b4f43d0dd28643948c8730d41c3 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Tue, 11 Sep 2012 12:07:35 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-3989 - ActiveMQSslConnectionFactory.setKeyAndTrustManagers does not work with failover enabled - fix and test git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1383370 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/ActiveMQSslConnectionFactory.java | 6 +++--- .../ActiveMQSslConnectionFactoryTest.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java index 09af08c85b..eb0c4fe97b 100644 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQSslConnectionFactory.java @@ -104,9 +104,9 @@ public class ActiveMQSslConnectionFactory extends ActiveMQConnectionFactory { if (keyStore != null || trustStore != null) { keyManager = createKeyManager(); trustManager = createTrustManager(); - if (keyManager != null || trustManager != null) { - SslContext.setCurrentSslContext(new SslContext(keyManager, trustManager, secureRandom)); - } + } + if (keyManager != null || trustManager != null) { + SslContext.setCurrentSslContext(new SslContext(keyManager, trustManager, secureRandom)); } return super.createTransport(); } catch (Exception e) { diff --git a/activemq-core/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java b/activemq-core/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java index 641fa93d4d..77405f85a6 100644 --- a/activemq-core/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java @@ -25,6 +25,7 @@ import java.io.ObjectOutputStream; import java.net.URI; import java.net.URISyntaxException; import java.security.KeyStore; +import java.security.SecureRandom; import javax.jms.ExceptionListener; import javax.jms.JMSException; @@ -129,6 +130,22 @@ public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { brokerStop(); } + public void testFailoverSslConnectionWithKeyAndTrustManagers() throws Exception { + String sslUri = "ssl://localhost:61611"; + broker = createSslBroker(sslUri); + assertNotNull(broker); + + ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4"); + cf.setKeyAndTrustManagers(getKeyManager(), getTrustManager(), new SecureRandom()); + connection = (ActiveMQConnection)cf.createConnection(); + LOG.info("Created client connection"); + assertNotNull(connection); + connection.start(); + connection.stop(); + + brokerStop(); + } + public void testNegativeCreateSslConnectionWithWrongPassword() throws Exception { // Create SSL/TLS connection with trusted cert from truststore. String sslUri = "ssl://localhost:61611";