Search in sources :

Example 11 with TransportConnector

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

the class JaasDualAuthenticationBrokerTest method testInsecureConnector.

public void testInsecureConnector() {
    Connector connector = new TransportConnector(nonSslTransportServer);
    connectionContext.setConnector(connector);
    connectionInfo.setUserName(INSECURE_USERNAME);
    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.", INSECURE_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 '" + INSECURE_USERNAME + "'", INSECURE_USERNAME, currentPrincipal.getName());
        } else if (currentPrincipal instanceof GroupPrincipal) {
            assertEquals("GroupPrincipal is '" + INSECURE_GROUP + "'", INSECURE_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)

Example 12 with TransportConnector

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

the class ThreeBrokerStompTemporaryQueueTest method bridgeBrokers.

@Override
protected NetworkConnector bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker, boolean dynamicOnly, int networkTTL, boolean conduit, boolean failover) throws Exception {
    List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
    URI remoteURI;
    if (!transportConnectors.isEmpty()) {
        remoteURI = transportConnectors.get(0).getConnectUri();
        NetworkConnector connector = new DiscoveryNetworkConnector(new URI("static:" + remoteURI));
        connector.setName(localBroker.getBrokerName() + remoteBroker.getBrokerName());
        localBroker.addNetworkConnector(connector);
        maxSetupTime = 2000;
        return connector;
    } else {
        throw new Exception("Remote broker has no registered connectors.");
    }
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) NetworkConnector(org.apache.activemq.network.NetworkConnector) DiscoveryNetworkConnector(org.apache.activemq.network.DiscoveryNetworkConnector) URI(java.net.URI) DiscoveryNetworkConnector(org.apache.activemq.network.DiscoveryNetworkConnector) IOException(java.io.IOException)

Example 13 with TransportConnector

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

the class ThreeBrokerQueueNetworkUsingTcpTest method bridgeBrokers.

protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception {
    List<TransportConnector> remoteTransports = remoteBroker.getTransportConnectors();
    List<TransportConnector> localTransports = localBroker.getTransportConnectors();
    URI remoteURI;
    URI localURI;
    if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) {
        remoteURI = remoteTransports.get(0).getConnectUri();
        localURI = localTransports.get(0).getConnectUri();
        // Ensure that we are connecting using tcp
        if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) {
            NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
            config.setBrokerName(localBroker.getBrokerName());
            DemandForwardingBridge bridge = new DemandForwardingBridge(config, TransportFactory.connect(localURI), TransportFactory.connect(remoteURI));
            bridge.setBrokerService(localBroker);
            bridges.add(bridge);
            bridge.start();
        } else {
            throw new Exception("Remote broker or local broker is not using tcp connectors");
        }
    } else {
        throw new Exception("Remote broker or local broker has no registered connectors.");
    }
    maxSetupTime = 2000;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) NetworkBridgeConfiguration(org.apache.activemq.network.NetworkBridgeConfiguration) DemandForwardingBridge(org.apache.activemq.network.DemandForwardingBridge) URI(java.net.URI)

Example 14 with TransportConnector

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

the class RequestReplyNoAdvisoryNetworkTest method bridge.

private NetworkConnector bridge(BrokerService from, BrokerService to) throws Exception {
    TransportConnector toConnector = to.getTransportConnectors().get(0);
    NetworkConnector bridge = from.addNetworkConnector("static://" + toConnector.getPublishableConnectString());
    bridge.addStaticallyIncludedDestination(sendQ);
    bridge.addStaticallyIncludedDestination(replyQWildcard);
    return bridge;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) NetworkConnector(org.apache.activemq.network.NetworkConnector)

Example 15 with TransportConnector

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

the class TwoBrokerTempQueueAdvisoryTest method testSendToRemovedTemp.

public void testSendToRemovedTemp() throws Exception {
    ActiveMQQueue requestReplyDest = new ActiveMQQueue("RequestReply");
    NetworkConnector nc = bridgeBrokers("BrokerA", "BrokerB");
    if (useDuplex) {
        nc.setDuplex(true);
    } else {
        bridgeBrokers("BrokerB", "BrokerA");
    }
    // way
    if (!useDuplex) {
        brokers.get("BrokerB").broker.setAllowTempAutoCreationOnSend(true);
    }
    TransportConnector forClient = brokers.get("BrokerA").broker.addConnector("tcp://localhost:0");
    startAllBrokers();
    waitForBridgeFormation();
    waitForMinTopicRegionConsumerCount("BrokerB", 1);
    waitForMinTopicRegionConsumerCount("BrokerA", 1);
    ConnectionFactory factory = new ActiveMQConnectionFactory(forClient.getConnectUri());
    ActiveMQConnection conn = (ActiveMQConnection) factory.createConnection();
    conn.setWatchTopicAdvisories(false);
    conn.start();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ConnectionFactory replyFactory = getConnectionFactory("BrokerB");
    for (int i = 0; i < 500; i++) {
        TemporaryQueue tempDest = session.createTemporaryQueue();
        MessageProducer producer = session.createProducer(requestReplyDest);
        javax.jms.Message message = session.createTextMessage("req-" + i);
        message.setJMSReplyTo(tempDest);
        ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(tempDest);
        producer.send(message);
        ActiveMQConnection replyConnection = (ActiveMQConnection) replyFactory.createConnection();
        replyConnection.setWatchTopicAdvisories(false);
        replyConnection.start();
        Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        ActiveMQMessageConsumer replyConsumer = (ActiveMQMessageConsumer) replySession.createConsumer(requestReplyDest);
        javax.jms.Message msg = replyConsumer.receive(10000);
        assertNotNull("request message not null: " + i, msg);
        MessageProducer replyProducer = replySession.createProducer(msg.getJMSReplyTo());
        replyProducer.send(session.createTextMessage("reply-" + i));
        replyConnection.close();
        javax.jms.Message reply = consumer.receive(10000);
        assertNotNull("reply message : " + i + ", to: " + tempDest + ", by consumer:" + consumer.getConsumerId(), reply);
        consumer.close();
        tempDest.delete();
    }
}
Also used : ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TransportConnector(org.apache.activemq.broker.TransportConnector) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) NetworkConnector(org.apache.activemq.network.NetworkConnector) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

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