Search in sources :

Example 51 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class AMQStackOverFlowTest method createBrokerService.

private BrokerService createBrokerService(final String brokerName, final String uri1, final String uri2) throws Exception {
    final BrokerService brokerService = new BrokerService();
    brokerService.setBrokerName(brokerName);
    brokerService.setPersistent(false);
    brokerService.setUseJmx(true);
    final SystemUsage memoryManager = new SystemUsage();
    // memoryManager.getMemoryUsage().setLimit(10);
    brokerService.setSystemUsage(memoryManager);
    final List<PolicyEntry> policyEntries = new ArrayList<>();
    final PolicyEntry entry = new PolicyEntry();
    entry.setQueue(">");
    // entry.setMemoryLimit(1);
    policyEntries.add(entry);
    final PolicyMap policyMap = new PolicyMap();
    policyMap.setPolicyEntries(policyEntries);
    brokerService.setDestinationPolicy(policyMap);
    final TransportConnector tConnector = new TransportConnector();
    tConnector.setUri(new URI(uri1));
    tConnector.setName(brokerName + ".transportConnector");
    brokerService.addConnector(tConnector);
    if (uri2 != null) {
        final NetworkConnector nc = new DiscoveryNetworkConnector(new URI("static:" + uri2));
        nc.setBridgeTempDestinations(true);
        nc.setBrokerName(brokerName);
        // nc.setPrefetchSize(1);
        brokerService.addNetworkConnector(nc);
    }
    return brokerService;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) PolicyMap(org.apache.activemq.broker.region.policy.PolicyMap) ArrayList(java.util.ArrayList) SystemUsage(org.apache.activemq.usage.SystemUsage) NetworkConnector(org.apache.activemq.network.NetworkConnector) DiscoveryNetworkConnector(org.apache.activemq.network.DiscoveryNetworkConnector) BrokerService(org.apache.activemq.broker.BrokerService) PolicyEntry(org.apache.activemq.broker.region.policy.PolicyEntry) URI(java.net.URI) DiscoveryNetworkConnector(org.apache.activemq.network.DiscoveryNetworkConnector)

Example 52 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class NIOSSLWindowSizeTest method setUp.

@Override
protected void setUp() throws Exception {
    System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
    System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
    System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
    System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
    System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
    System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(false);
    TransportConnector connector = broker.addConnector("nio+ssl://localhost:0?transport.needClientAuth=true");
    broker.start();
    broker.waitUntilStarted();
    messageData = new byte[MESSAGE_SIZE];
    for (int i = 0; i < MESSAGE_SIZE; i++) {
        messageData[i] = (byte) (i & 0xff);
    }
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("nio+ssl://localhost:" + connector.getConnectUri().getPort());
    connection = factory.createConnection();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    connection.start();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TransportConnector(org.apache.activemq.broker.TransportConnector) BrokerService(org.apache.activemq.broker.BrokerService)

Example 53 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class SslBrokerServiceTest method createBroker.

@Override
protected BrokerService createBroker() throws Exception {
    // http://java.sun.com/javase/javaseforbusiness/docs/TLSReadme.html
    // work around: javax.net.ssl.SSLHandshakeException: renegotiation is not allowed
    System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
    SslBrokerService service = new SslBrokerService();
    service.setPersistent(false);
    String baseUri = getBindLocation();
    String uri0 = baseUri + "?" + TransportConstants.SSL_ENABLED_PROP_NAME + "=true&" + TransportConstants.KEYSTORE_PATH_PROP_NAME + "=" + SslTransportBrokerTest.SERVER_KEYSTORE + "&" + TransportConstants.KEYSTORE_PASSWORD_PROP_NAME + "=" + SslTransportBrokerTest.PASSWORD + "&" + TransportConstants.KEYSTORE_PROVIDER_PROP_NAME + "=" + SslTransportBrokerTest.KEYSTORE_TYPE;
    String uri1 = uri0 + "&" + TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME + "=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,SSL_DH_anon_WITH_3DES_EDE_CBC_SHA";
    String uri2 = uri0 + "&" + TransportConstants.NEED_CLIENT_AUTH_PROP_NAME + "=true&" + TransportConstants.TRUSTSTORE_PATH_PROP_NAME + "=" + SslTransportBrokerTest.TRUST_KEYSTORE + "&" + TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME + "=" + SslTransportBrokerTest.PASSWORD + "&" + TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME + "=" + SslTransportBrokerTest.KEYSTORE_TYPE;
    // broker side
    TransportConnector serverConnector0 = service.addConnector(new URI(uri0));
    connector = new FakeTransportConnector(new URI("ssl://localhost:" + serverConnector0.getUri().getPort()));
    TransportConnector serverConnector1 = service.addConnector(new URI(uri1));
    limitedCipherSuites = new FakeTransportConnector(new URI("ssl://localhost:" + serverConnector1.getUri().getPort() + "?transport.enabledCipherSuites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,SSL_DH_anon_WITH_3DES_EDE_CBC_SHA"));
    TransportConnector serverConnector2 = service.addConnector(new URI(uri2));
    needClientAuthConnector = new FakeTransportConnector(new URI("ssl://localhost:" + serverConnector2.getUri().getPort() + "?transport.needClientAuth=true"));
    KeyManager[] km = getKeyManager();
    TrustManager[] tm = getTrustManager();
    // for client side
    SslTransportFactory sslFactory = new SslTransportFactory();
    SslContext ctx = new SslContext(km, tm, null);
    SslContext.setCurrentSslContext(ctx);
    TransportFactory.registerTransportFactory("ssl", sslFactory);
    return service;
}
Also used : FakeTransportConnector(org.apache.activemq.broker.FakeTransportConnector) TransportConnector(org.apache.activemq.broker.TransportConnector) FakeTransportConnector(org.apache.activemq.broker.FakeTransportConnector) SslBrokerService(org.apache.activemq.broker.SslBrokerService) URI(java.net.URI) KeyManager(javax.net.ssl.KeyManager) TrustManager(javax.net.ssl.TrustManager) SslContext(org.apache.activemq.broker.SslContext)

Example 54 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class SslContextNBrokerServiceTest method verifySslCredentials.

private boolean verifySslCredentials(BrokerService broker) throws Exception {
    TransportConnector connector = broker.getTransportConnectors().get(0);
    URI brokerUri = connector.getConnectUri();
    SSLContext context = SSLContext.getInstance("TLS");
    CertChainCatcher catcher = new CertChainCatcher();
    context.init(null, new TrustManager[] { catcher }, null);
    SSLSocketFactory factory = context.getSocketFactory();
    LOG.info("Connecting to broker: " + broker.getBrokerName() + " on: " + brokerUri.getHost() + ":" + brokerUri.getPort());
    SSLSocket socket = (SSLSocket) factory.createSocket(brokerUri.getHost(), brokerUri.getPort());
    socket.setSoTimeout(2 * 60 * 1000);
    socket.startHandshake();
    socket.close();
    boolean matches = false;
    if (catcher.serverCerts != null) {
        for (int i = 0; i < catcher.serverCerts.length; i++) {
            X509Certificate cert = catcher.serverCerts[i];
            LOG.info(" " + (i + 1) + " Issuer " + cert.getIssuerDN());
        }
        if (catcher.serverCerts.length > 0) {
            String issuer = catcher.serverCerts[0].getIssuerDN().toString();
            if (issuer.indexOf(broker.getBrokerName()) != -1) {
                matches = true;
            }
        }
    }
    return matches;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) SSLSocket(javax.net.ssl.SSLSocket) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) URI(java.net.URI) X509Certificate(java.security.cert.X509Certificate)

Example 55 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class JaasDualAuthenticationBrokerTest method testSecureConnector.

public void testSecureConnector() {
    Connector connector = new TransportConnector(sslTransportServer);
    connectionContext.setConnector(connector);
    connectionInfo.setTransportContext(new StubX509Certificate[] {});
    try {
        authBroker.addConnection(connectionContext, connectionInfo);
    } catch (Exception e) {
        fail("Call to addConnection failed: " + e.getMessage());
    }
    assertEquals("Number of addConnection calls to underlying Broker must match number of calls made to " + "AuthenticationBroker.", 1, receiveBroker.addConnectionData.size());
    ConnectionContext receivedContext = receiveBroker.addConnectionData.getFirst().connectionContext;
    assertEquals("The SecurityContext's userName must be set to that of the UserPrincipal.", DN_USERNAME, receivedContext.getSecurityContext().getUserName());
    Set<Principal> receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
    assertEquals("2 Principals received", 2, receivedPrincipals.size());
    for (Iterator<Principal> iter = receivedPrincipals.iterator(); iter.hasNext(); ) {
        Principal currentPrincipal = iter.next();
        if (currentPrincipal instanceof UserPrincipal) {
            assertEquals("UserPrincipal is '" + DN_USERNAME + "'", DN_USERNAME, currentPrincipal.getName());
        } else if (currentPrincipal instanceof GroupPrincipal) {
            assertEquals("GroupPrincipal is '" + DN_GROUP + "'", DN_GROUP, currentPrincipal.getName());
        } else {
            fail("Unexpected Principal subclass found.");
        }
    }
    try {
        authBroker.removeConnection(connectionContext, connectionInfo, null);
    } catch (Exception e) {
        fail("Call to removeConnection failed: " + e.getMessage());
    }
    assertEquals("Number of removeConnection calls to underlying Broker must match number of calls made to " + "AuthenticationBroker.", 1, receiveBroker.removeConnectionData.size());
}
Also used : Connector(org.apache.activemq.broker.Connector) TransportConnector(org.apache.activemq.broker.TransportConnector) TransportConnector(org.apache.activemq.broker.TransportConnector) GroupPrincipal(org.apache.activemq.jaas.GroupPrincipal) ConnectionContext(org.apache.activemq.broker.ConnectionContext) UserPrincipal(org.apache.activemq.jaas.UserPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.activemq.jaas.GroupPrincipal) UserPrincipal(org.apache.activemq.jaas.UserPrincipal)

Aggregations

TransportConnector (org.apache.activemq.broker.TransportConnector)59 URI (java.net.URI)31 BrokerService (org.apache.activemq.broker.BrokerService)31 NetworkConnector (org.apache.activemq.network.NetworkConnector)10 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)9 DiscoveryNetworkConnector (org.apache.activemq.network.DiscoveryNetworkConnector)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Connection (javax.jms.Connection)4 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)4 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)4 JMSException (javax.jms.JMSException)3 Session (javax.jms.Session)3 File (java.io.File)2 Principal (java.security.Principal)2 MessageProducer (javax.jms.MessageProducer)2 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)2 ConnectionContext (org.apache.activemq.broker.ConnectionContext)2 Connector (org.apache.activemq.broker.Connector)2 StubConnection (org.apache.activemq.broker.StubConnection)2