Skip to content

Commit

Permalink
NIFI-9261: Make ActiveMQ client configurable via SSL Context Service …
Browse files Browse the repository at this point in the history
…in JMSConnectionFactoryProvider

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #5425.
  • Loading branch information
turcsanyip authored and pvillard31 committed Oct 1, 2021
1 parent 4943560 commit 24c0c39
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Expand Up @@ -175,7 +175,19 @@ void setConnectionFactoryProperties() {
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)
Expand Down
Expand Up @@ -402,6 +402,55 @@ public void propertiesSetOnMultipleActiveMqBrokersConnectionFactory() throws Ini
assertEquals(ImmutableMap.of("brokerURL", MULTIPLE_ACTIVEMQ_BROKERS), cfProvider.getConfiguredProperties());
}

@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));
Expand Down

0 comments on commit 24c0c39

Please sign in to comment.