You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by pv...@apache.org on 2021/10/01 07:29:14 UTC

[nifi] branch main updated: NIFI-9261: Make ActiveMQ client configurable via SSL Context Service in JMSConnectionFactoryProvider

This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 24c0c39  NIFI-9261: Make ActiveMQ client configurable via SSL Context Service in JMSConnectionFactoryProvider
24c0c39 is described below

commit 24c0c39ebb84648ae753e0e9756d7dcce08abfeb
Author: Peter Turcsanyi <tu...@apache.org>
AuthorDate: Wed Sep 29 17:23:05 2021 +0200

    NIFI-9261: Make ActiveMQ client configurable via SSL Context Service in JMSConnectionFactoryProvider
    
    Signed-off-by: Pierre Villard <pi...@gmail.com>
    
    This closes #5425.
---
 .../nifi/jms/cf/JMSConnectionFactoryHandler.java   | 14 ++++++-
 .../jms/cf/JMSConnectionFactoryProviderTest.java   | 49 ++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryHandler.java b/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryHandler.java
index 6e36921..44de835 100644
--- a/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryHandler.java
+++ b/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryHandler.java
@@ -175,7 +175,19 @@ public class JMSConnectionFactoryHandler implements IJMSConnectionFactoryProvide
         SSLContextService sslContextService = context.getProperty(JMS_SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
         if (sslContextService != null) {
             SSLContext sslContext = sslContextService.createContext();
-            if (connectionFactoryValue.startsWith("org.apache.qpid.jms")) {
+            if (connectionFactoryValue.startsWith("org.apache.activemq")) {
+                if (sslContextService.isTrustStoreConfigured()) {
+                    setProperty("trustStore", sslContextService.getTrustStoreFile());
+                    setProperty("trustStorePassword", sslContextService.getTrustStorePassword());
+                    setProperty("trustStoreType", sslContextService.getTrustStoreType());
+                }
+                if (sslContextService.isKeyStoreConfigured()) {
+                    setProperty("keyStore", sslContextService.getKeyStoreFile());
+                    setProperty("keyStorePassword", sslContextService.getKeyStorePassword());
+                    setProperty("keyStoreKeyPassword", sslContextService.getKeyPassword());
+                    setProperty("keyStoreType", sslContextService.getKeyStoreType());
+                }
+            } else if (connectionFactoryValue.startsWith("org.apache.qpid.jms")) {
                 setProperty("sslContext", sslContext);
             } else {
                 // IBM MQ (and others)
diff --git a/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProviderTest.java b/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProviderTest.java
index 1dcdbb3..725ed01 100644
--- a/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProviderTest.java
+++ b/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/test/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProviderTest.java
@@ -403,6 +403,55 @@ public class JMSConnectionFactoryProviderTest {
     }
 
     @Test
+    public void propertiesSetOnSingleActiveMqBrokerWithSslConnectionFactory() throws Exception {
+        TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
+
+        JMSConnectionFactoryProviderForTest cfProvider = new JMSConnectionFactoryProviderForTest();
+        runner.addControllerService(CF_PROVIDER_SERVICE_ID, cfProvider);
+
+        runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_BROKER_URI, SINGLE_ACTIVEMQ_BROKER);
+        runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CLIENT_LIBRARIES, dummyResource);
+        runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_CONNECTION_FACTORY_IMPL, ACTIVEMQ_CONNECTION_FACTORY_IMPL);
+
+        String trustStoreFile = "/path/to/truststore";
+        String trustStorePassword = "truststore_password";
+        String trustStoreType = "JKS";
+        String keyStoreFile = "/path/to/keystore";
+        String keyStorePassword = "keystore_password";
+        String keyPassword = "key_password";
+        String keyStoreType = "PKCS12";
+
+        SSLContextService sslContextService = mock(SSLContextService.class);
+        when(sslContextService.getIdentifier()).thenReturn(SSL_CONTEXT_SERVICE_ID);
+        when(sslContextService.isTrustStoreConfigured()).thenReturn(true);
+        when(sslContextService.getTrustStoreFile()).thenReturn(trustStoreFile);
+        when(sslContextService.getTrustStorePassword()).thenReturn(trustStorePassword);
+        when(sslContextService.getTrustStoreType()).thenReturn(trustStoreType);
+        when(sslContextService.isKeyStoreConfigured()).thenReturn(true);
+        when(sslContextService.getKeyStoreFile()).thenReturn(keyStoreFile);
+        when(sslContextService.getKeyStorePassword()).thenReturn(keyStorePassword);
+        when(sslContextService.getKeyPassword()).thenReturn(keyPassword);
+        when(sslContextService.getKeyStoreType()).thenReturn(keyStoreType);
+
+        runner.addControllerService(SSL_CONTEXT_SERVICE_ID, sslContextService);
+        runner.setProperty(cfProvider, JMSConnectionFactoryProperties.JMS_SSL_CONTEXT_SERVICE, SSL_CONTEXT_SERVICE_ID);
+
+        runner.enableControllerService(cfProvider);
+
+        assertEquals(ImmutableMap.builder()
+                        .put("brokerURL", SINGLE_ACTIVEMQ_BROKER)
+                        .put("trustStore", trustStoreFile)
+                        .put("trustStorePassword", trustStorePassword)
+                        .put("trustStoreType", trustStoreType)
+                        .put("keyStore", keyStoreFile)
+                        .put("keyStorePassword", keyStorePassword)
+                        .put("keyStoreKeyPassword", keyPassword)
+                        .put("keyStoreType", keyStoreType)
+                        .build(),
+                cfProvider.getConfiguredProperties());
+    }
+
+    @Test
     public void propertiesSetOnSingleTibcoBrokerConnectionFactory() throws InitializationException {
         TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));