activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject [1/2] activemq git commit: https://issues.apache.org/jira/browse/AMQ-6489
Date Mon, 31 Oct 2016 16:47:38 GMT
Repository: activemq
Updated Branches:
  refs/heads/master c53131d70 -> 1a0af86c0


https://issues.apache.org/jira/browse/AMQ-6489

Add support for SSL configurations using JNDI.


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/11541e86
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/11541e86
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/11541e86

Branch: refs/heads/master
Commit: 11541e8608807d900f0fd66ef48bbc7c5590ee4c
Parents: c53131d
Author: Michael L. Bloom <bloommi@gmail.com>
Authored: Mon Oct 31 11:32:34 2016 -0400
Committer: Michael L. Bloom <bloommi@gmail.com>
Committed: Mon Oct 31 12:03:33 2016 -0400

----------------------------------------------------------------------
 .../jndi/ActiveMQSslInitialContextFactory.java  | 40 +++++++++++
 .../ActiveMQSslInitialContextFactoryTest.java   | 75 ++++++++++++++++++++
 2 files changed, 115 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/11541e86/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/11541e86/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");
+        }
+    }
+
+}


Mime
View raw message