Repository: activemq Updated Branches: refs/heads/activemq-5.14.x 4cbe692bc -> ed4ffaba5
https://issues.apache.org/jira/browse/AMQ-6489 Add support for SSL configurations using JNDI. (cherry picked from commit 11541e8608807d900f0fd66ef48bbc7c5590ee4c) Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/ed4ffaba Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/ed4ffaba Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/ed4ffaba Branch: refs/heads/activemq-5.14.x Commit: ed4ffaba544ea579a1ea3b4239373ca8d3d839ff Parents: 4cbe692 Author: Michael L. Bloom <[email protected]> Authored: Mon Oct 31 11:32:34 2016 -0400 Committer: Christopher L. Shannon (cshannon) <[email protected]> Committed: Mon Oct 31 12:48:13 2016 -0400 ---------------------------------------------------------------------- .../jndi/ActiveMQSslInitialContextFactory.java | 40 +++++++++++ .../ActiveMQSslInitialContextFactoryTest.java | 75 ++++++++++++++++++++ 2 files changed, 115 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/ed4ffaba/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactory.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactory.java b/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactory.java new file mode 100644 index 0000000..d13ab67 --- /dev/null +++ b/activemq-client/src/main/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactory.java @@ -0,0 +1,40 @@ +/** + * 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.activemq.jndi; + +import java.net.URISyntaxException; +import java.util.Hashtable; +import java.util.Properties; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.ActiveMQSslConnectionFactory; + +public class ActiveMQSslInitialContextFactory extends ActiveMQInitialContextFactory { + + /** + * Factory method to create a new connection factory from the given + * environment + */ + @Override + protected ActiveMQConnectionFactory createConnectionFactory(Hashtable environment) throws URISyntaxException { + ActiveMQConnectionFactory answer = new ActiveMQSslConnectionFactory(); + Properties properties = new Properties(); + properties.putAll(environment); + answer.setProperties(properties); + return answer; + } +} http://git-wip-us.apache.org/repos/asf/activemq/blob/ed4ffaba/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactoryTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactoryTest.java new file mode 100644 index 0000000..e2962bf --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jndi/ActiveMQSslInitialContextFactoryTest.java @@ -0,0 +1,75 @@ +/** + * 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.activemq.jndi; + +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.spi.InitialContextFactory; + +import org.apache.activemq.ActiveMQSslConnectionFactory; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class ActiveMQSslInitialContextFactoryTest { + + protected Context context; + + @Before + public void setUp() throws Exception { + InitialContextFactory factory = new ActiveMQSslInitialContextFactory(); + Hashtable<String, String> environment = new Hashtable<String, String>(); + environment.put("java.naming.provider.url", "vm://0"); + environment.put("connection.ConnectionFactory.userName", "user"); + environment.put("connection.ConnectionFactory.userPassword", "test"); + environment.put("connection.ConnectionFactory.keyStore", "keystore.jks"); + environment.put("connection.ConnectionFactory.keyStorePassword", "test"); + environment.put("connection.ConnectionFactory.keyStoreType", "JKS"); + environment.put("connection.ConnectionFactory.trustStore", "truststore.jks"); + environment.put("connection.ConnectionFactory.trustStorePassword", "test"); + environment.put("connection.ConnectionFactory.trustStoreType", "JKS"); + + context = factory.getInitialContext(environment); + assertTrue("No context created", context != null); + } + + @Test + public void testCreateConnectionFactory() throws NamingException { + assertTrue(context.lookup("ConnectionFactory") instanceof ActiveMQSslConnectionFactory); + } + + @Test + public void testAssertConnectionFactoryProperties() throws NamingException { + Object c = context.lookup("ConnectionFactory"); + if (c instanceof ActiveMQSslConnectionFactory) { + ActiveMQSslConnectionFactory factory = (ActiveMQSslConnectionFactory)c; + assertEquals(factory.getKeyStore(), "keystore.jks"); + assertEquals(factory.getKeyStorePassword(), "test"); + assertEquals(factory.getKeyStoreType(), "JKS"); + assertEquals(factory.getTrustStore(), "truststore.jks"); + assertEquals(factory.getTrustStorePassword(), "test"); + assertEquals(factory.getTrustStoreType(), "JKS"); + } else { + fail("Did not find an ActiveMQSslConnectionFactory"); + } + } + +}
