mirror of https://github.com/apache/nifi.git
NIFI-9261: Make ActiveMQ client configurable via SSL Context Service in JMSConnectionFactoryProvider
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #5425.
This commit is contained in:
parent
4943560521
commit
24c0c39ebb
|
@ -175,7 +175,19 @@ public class JMSConnectionFactoryHandler implements IJMSConnectionFactoryProvide
|
||||||
SSLContextService sslContextService = context.getProperty(JMS_SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
|
SSLContextService sslContextService = context.getProperty(JMS_SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
|
||||||
if (sslContextService != null) {
|
if (sslContextService != null) {
|
||||||
SSLContext sslContext = sslContextService.createContext();
|
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);
|
setProperty("sslContext", sslContext);
|
||||||
} else {
|
} else {
|
||||||
// IBM MQ (and others)
|
// IBM MQ (and others)
|
||||||
|
|
|
@ -402,6 +402,55 @@ public class JMSConnectionFactoryProviderTest {
|
||||||
assertEquals(ImmutableMap.of("brokerURL", MULTIPLE_ACTIVEMQ_BROKERS), cfProvider.getConfiguredProperties());
|
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
|
@Test
|
||||||
public void propertiesSetOnSingleTibcoBrokerConnectionFactory() throws InitializationException {
|
public void propertiesSetOnSingleTibcoBrokerConnectionFactory() throws InitializationException {
|
||||||
TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
|
TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
|
||||||
|
|
Loading…
Reference in New Issue