Search in sources :

Example 6 with ActiveMQSslConnectionFactory

use of org.apache.activemq.ActiveMQSslConnectionFactory in project syndesis by syndesisio.

the class ActiveMQUtil method createActiveMQConnectionFactory.

@SuppressWarnings("PMD.CyclomaticComplexity")
public static ActiveMQConnectionFactory createActiveMQConnectionFactory(String brokerUrl, String username, String password, String brokerCertificate, String clientCertificate, boolean skipCertificateCheck) {
    if (brokerUrl.contains("ssl:")) {
        final ActiveMQSslConnectionFactory connectionFactory;
        if (ObjectHelper.isEmpty(username)) {
            connectionFactory = new ActiveMQSslConnectionFactory(brokerUrl);
        } else {
            connectionFactory = new ActiveMQSslConnectionFactory(brokerUrl);
            connectionFactory.setUserName(username);
            connectionFactory.setPassword(password);
        }
        try {
            // create client key manager
            final KeyManager[] keyManagers;
            if (ObjectHelper.isEmpty(clientCertificate)) {
                keyManagers = null;
            } else {
                keyManagers = CertificateUtil.createKeyManagers(clientCertificate, "amq-client");
            }
            // create client trust manager
            final TrustManager[] trustManagers;
            if (ObjectHelper.isEmpty(brokerCertificate)) {
                if (skipCertificateCheck) {
                    // use a trust all TrustManager
                    LOG.warn("Skipping Certificate check for Broker {}", brokerUrl);
                    trustManagers = CertificateUtil.createTrustAllTrustManagers();
                } else {
                    LOG.debug("Using default JVM Trust Manager for Broker {}", brokerUrl);
                    trustManagers = null;
                }
            } else {
                trustManagers = CertificateUtil.createTrustManagers(brokerCertificate, "amq-broker");
            }
            connectionFactory.setKeyAndTrustManagers(keyManagers, trustManagers, new SecureRandom());
            return connectionFactory;
        } catch (GeneralSecurityException | IOException e) {
            throw new IllegalArgumentException("SSL configuration error: " + e.getMessage(), e);
        }
    } else {
        // non-ssl connection
        return ObjectHelper.isEmpty(username) ? new ActiveMQConnectionFactory(brokerUrl) : new ActiveMQConnectionFactory(username, password, brokerUrl);
    }
}
Also used : ActiveMQSslConnectionFactory(org.apache.activemq.ActiveMQSslConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) GeneralSecurityException(java.security.GeneralSecurityException) SecureRandom(java.security.SecureRandom) IOException(java.io.IOException) KeyManager(javax.net.ssl.KeyManager) TrustManager(javax.net.ssl.TrustManager)

Example 7 with ActiveMQSslConnectionFactory

use of org.apache.activemq.ActiveMQSslConnectionFactory in project alfresco-repository by Alfresco.

the class ConnectionFactoryConfiguration method createSecureConnectionFactory.

protected ConnectionFactory createSecureConnectionFactory() {
    ActiveMQSslConnectionFactory factory = new ActiveMQSslConnectionFactory(brokerUrl);
    factory.setKeyAndTrustManagers(keyStore.createKeyManagers(), trustStore.createTrustManagers(), new SecureRandom());
    factory.setUserName(username);
    factory.setPassword(password);
    return factory;
}
Also used : ActiveMQSslConnectionFactory(org.apache.activemq.ActiveMQSslConnectionFactory) SecureRandom(java.security.SecureRandom)

Aggregations

ActiveMQSslConnectionFactory (org.apache.activemq.ActiveMQSslConnectionFactory)7 SecureRandom (java.security.SecureRandom)2 HashMap (java.util.HashMap)2 Session (javax.jms.Session)2 KeyManager (javax.net.ssl.KeyManager)2 TrustManager (javax.net.ssl.TrustManager)2 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 HashSet (java.util.HashSet)1 MessageProducer (javax.jms.MessageProducer)1 QueueBrowser (javax.jms.QueueBrowser)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1