public static ConnectionFactory createSslConnectionFactory(final String url, final int timeoutMillis, final String jmsProvider, final String keystore, final String keystorePassword, final String truststore, final String truststorePassword) throws JMSException { switch (jmsProvider) { case ACTIVEMQ_PROVIDER: { final ActiveMQSslConnectionFactory factory = new ActiveMQSslConnectionFactory(url); try { factory.setKeyStore(keystore); } catch (Exception e) { throw new JMSException("Problem Setting the KeyStore: " + e.getMessage()); } factory.setKeyStorePassword(keystorePassword); try { factory.setTrustStore(truststore); } catch (Exception e) { throw new JMSException("Problem Setting the TrustStore: " + e.getMessage()); } factory.setTrustStorePassword(truststorePassword); factory.setSendTimeout(timeoutMillis); return factory; } default: throw new IllegalArgumentException("Unknown JMS Provider: " + jmsProvider); } }
ActiveMQSslConnectionFactory connectionFactory = new ActiveMQSslConnectionFactory(url); try { connectionFactory.setTrustStore(CLIENT_TS_FILE); connectionFactory.setTrustStorePassword("PASSWORD asked while TS file made"); connectionFactory.setKeyStore(CLIENT_KS_FILE); connectionFactory.setKeyStorePassword("PASSWORD asked while KS file made"); } catch (Exception e) { throw new MotorException( "JMS Connection Failed (Trust store or key store weren't found) : ", e); }
private ConnectionFactory createSslConnectionFactory() throws Exception { ActiveMQSslConnectionFactory jmsConnectFactory = new ActiveMQSslConnectionFactory(); jmsConnectFactory.setKeyStore( OpenwireProducerConsumerExample.class.getResource("/serverKeystore.jks").toURI().getPath()); jmsConnectFactory.setKeyStoreKeyPassword("changeit"); jmsConnectFactory.setKeyStorePassword("changeit"); jmsConnectFactory.setTrustStore( OpenwireProducerConsumerExample.class .getResource("/serverTruststore.jks") .toURI() .getPath()); jmsConnectFactory.setTrustStorePassword("changeit"); jmsConnectFactory.setBrokerURL("failover://(ssl://localhost:61616,ssl://localhost:61617)"); jmsConnectFactory.setWatchTopicAdvisories(false); return jmsConnectFactory; }
public static ConnectionFactory createSslConnectionFactory(final String url, final int timeoutMillis, final String jmsProvider, final String keystore, final String keystorePassword, final String truststore, final String truststorePassword) throws JMSException { switch (jmsProvider) { case ACTIVEMQ_PROVIDER: { final ActiveMQSslConnectionFactory factory = new ActiveMQSslConnectionFactory(url); try { factory.setKeyStore(keystore); } catch (Exception e) { throw new JMSException("Problem Setting the KeyStore: " + e.getMessage()); } factory.setKeyStorePassword(keystorePassword); try { factory.setTrustStore(truststore); } catch (Exception e) { throw new JMSException("Problem Setting the TrustStore: " + e.getMessage()); } factory.setTrustStorePassword(truststorePassword); factory.setSendTimeout(timeoutMillis); return factory; } default: throw new IllegalArgumentException("Unknown JMS Provider: " + jmsProvider); } }
@Test public void testJAASSecurityManagerAuthenticationWithCertsAndOpenWire() throws Exception { ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("CertLogin"); ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false)); Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true); params.put(TransportConstants.KEYSTORE_PATH_PROP_NAME, "server-side-keystore.jks"); params.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "secureexample"); params.put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "server-side-truststore.jks"); params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "secureexample"); params.put(TransportConstants.NEED_CLIENT_AUTH_PROP_NAME, true); server.getConfiguration().addAcceptorConfiguration(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params)); server.start(); ActiveMQSslConnectionFactory factory = new ActiveMQSslConnectionFactory("ssl://localhost:61616"); factory.setTrustStore("client-side-truststore.jks"); factory.setTrustStorePassword("secureexample"); factory.setKeyStore("client-side-keystore.jks"); factory.setKeyStorePassword("secureexample"); try (ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection()) { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); session.close(); } catch (Throwable e) { e.printStackTrace(); Assert.fail("should not throw exception"); } }
factory.setTrustStore("client-side-truststore.jks"); factory.setTrustStorePassword("secureexample"); factory.setKeyStore("client-side-keystore.jks");