Search in sources :

Example 1 with ConnectionContext

use of org.apache.activemq.broker.ConnectionContext 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 2 with ConnectionContext

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

the class JaasDualAuthenticationBrokerTest method setUp.

@Override
protected void setUp() throws Exception {
    receiveBroker = new StubBroker();
    authBroker = new JaasDualAuthenticationBroker(receiveBroker, "activemq-domain", "activemq-ssl-domain");
    connectionContext = new ConnectionContext();
    SSLServerSocket sslServerSocket = new StubSSLServerSocket();
    StubSSLSocketFactory socketFactory = new StubSSLSocketFactory(sslServerSocket);
    try {
        sslTransportServer = new SslTransportServer(null, new URI("ssl://localhost:61616?needClientAuth=true"), socketFactory);
    } catch (Exception e) {
        fail("Unable to create SslTransportServer.");
    }
    sslTransportServer.setNeedClientAuth(true);
    sslTransportServer.bind();
    try {
        nonSslTransportServer = new TcpTransportServer(null, new URI("tcp://localhost:61613"), socketFactory);
    } catch (Exception e) {
        fail("Unable to create TcpTransportServer.");
    }
    connectionInfo = new ConnectionInfo();
    createLoginConfig();
}
Also used : StubSSLServerSocket(org.apache.activemq.transport.tcp.StubSSLServerSocket) ConnectionContext(org.apache.activemq.broker.ConnectionContext) SslTransportServer(org.apache.activemq.transport.tcp.SslTransportServer) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) StubSSLServerSocket(org.apache.activemq.transport.tcp.StubSSLServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket) TcpTransportServer(org.apache.activemq.transport.tcp.TcpTransportServer) URI(java.net.URI) StubSSLSocketFactory(org.apache.activemq.transport.tcp.StubSSLSocketFactory) StubBroker(org.apache.activemq.broker.StubBroker)

Example 3 with ConnectionContext

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

the class JaasCertificateAuthenticationBrokerTest method setUp.

@Override
protected void setUp() throws Exception {
    receiveBroker = new StubBroker();
    authBroker = new JaasCertificateAuthenticationBroker(receiveBroker, "");
    connectionContext = new ConnectionContext();
    connectionInfo = new ConnectionInfo();
    connectionInfo.setTransportContext(new StubX509Certificate[] {});
}
Also used : ConnectionContext(org.apache.activemq.broker.ConnectionContext) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) StubBroker(org.apache.activemq.broker.StubBroker)

Example 4 with ConnectionContext

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

the class QueueOptimizedDispatchExceptionTest method TestOptimizedDispatchCME.

@Test
public void TestOptimizedDispatchCME() throws Exception {
    final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
    final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
    final ConnectionContext contextNotInTx = new ConnectionContext();
    contextNotInTx.setConnection(new Connection() {

        @Override
        public void stop() throws Exception {
        }

        @Override
        public void start() throws Exception {
        }

        @Override
        public void updateClient(ConnectionControl control) {
        }

        @Override
        public void serviceExceptionAsync(IOException e) {
        }

        @Override
        public void serviceException(Throwable error) {
        }

        @Override
        public Response service(Command command) {
            return null;
        }

        @Override
        public boolean isSlow() {
            return false;
        }

        @Override
        public boolean isNetworkConnection() {
            return false;
        }

        @Override
        public boolean isManageable() {
            return false;
        }

        @Override
        public boolean isFaultTolerantConnection() {
            return false;
        }

        @Override
        public boolean isConnected() {
            return true;
        }

        @Override
        public boolean isBlocked() {
            return false;
        }

        @Override
        public boolean isActive() {
            return false;
        }

        @Override
        public ConnectionStatistics getStatistics() {
            return null;
        }

        @Override
        public String getRemoteAddress() {
            return null;
        }

        @Override
        public int getDispatchQueueSize() {
            return 0;
        }

        @Override
        public Connector getConnector() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getConnectionId() {
            return null;
        }

        @Override
        public void dispatchSync(Command message) {
        }

        @Override
        public void dispatchAsync(Command command) {
        }

        @Override
        public int getActiveTransactionCount() {
            return 0;
        }

        @Override
        public Long getOldestActiveTransactionDuration() {
            return null;
        }
    });
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    final Queue queue = new Queue(broker, destination, queueMessageStore, destinationStatistics, broker.getTaskRunnerFactory());
    final MockMemoryUsage usage = new MockMemoryUsage();
    queue.setOptimizedDispatch(true);
    queue.initialize();
    queue.start();
    queue.memoryUsage = usage;
    ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
    ProducerInfo producerInfo = new ProducerInfo();
    ProducerState producerState = new ProducerState(producerInfo);
    producerExchange.setProducerState(producerState);
    producerExchange.setConnectionContext(contextNotInTx);
    // populate the queue store, exceed memory limit so that cache is disabled
    for (int i = 0; i < count; i++) {
        Message message = getMessage(i);
        queue.send(producerExchange, message);
    }
    usage.setFull(false);
    try {
        queue.wakeup();
    } catch (Exception e) {
        LOG.error("Queue threw an unexpected exception: " + e.toString());
        fail("Should not throw an exception.");
    }
}
Also used : MessageStore(org.apache.activemq.store.MessageStore) Connector(org.apache.activemq.broker.Connector) ProducerBrokerExchange(org.apache.activemq.broker.ProducerBrokerExchange) ProducerInfo(org.apache.activemq.command.ProducerInfo) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message) Connection(org.apache.activemq.broker.Connection) IOException(java.io.IOException) IOException(java.io.IOException) Response(org.apache.activemq.command.Response) ConnectionControl(org.apache.activemq.command.ConnectionControl) Command(org.apache.activemq.command.Command) ProducerState(org.apache.activemq.state.ProducerState) ConnectionContext(org.apache.activemq.broker.ConnectionContext) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) Test(org.junit.Test)

Example 5 with ConnectionContext

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

the class MessageAuthenticationTest method createBroker.

@Override
protected BrokerService createBroker() throws Exception {
    BrokerService answer = new BrokerService();
    answer.setPersistent(false);
    answer.setMessageAuthorizationPolicy(new MessageAuthorizationPolicy() {

        @Override
        public boolean isAllowedToConsume(ConnectionContext context, Message message) {
            try {
                Object value = message.getProperty("myHeader");
                return "abc".equals(value);
            } catch (IOException e) {
                System.out.println("Caught: " + e);
                e.printStackTrace();
                return false;
            }
        }
    });
    answer.addConnector(bindAddress);
    return answer;
}
Also used : TextMessage(javax.jms.TextMessage) Message(org.apache.activemq.command.Message) MessageAuthorizationPolicy(org.apache.activemq.security.MessageAuthorizationPolicy) ConnectionContext(org.apache.activemq.broker.ConnectionContext) IOException(java.io.IOException) BrokerService(org.apache.activemq.broker.BrokerService)

Aggregations

ConnectionContext (org.apache.activemq.broker.ConnectionContext)16 Queue (org.apache.activemq.broker.region.Queue)4 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)4 Principal (java.security.Principal)3 Connection (javax.jms.Connection)3 Message (javax.jms.Message)3 MessageProducer (javax.jms.MessageProducer)3 Session (javax.jms.Session)3 Connector (org.apache.activemq.broker.Connector)3 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)3 Message (org.apache.activemq.command.Message)3 NonCachedMessageEvaluationContext (org.apache.activemq.filter.NonCachedMessageEvaluationContext)3 GroupPrincipal (org.apache.activemq.jaas.GroupPrincipal)3 UserPrincipal (org.apache.activemq.jaas.UserPrincipal)3 MessageStore (org.apache.activemq.store.MessageStore)3 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)3 IOException (java.io.IOException)2 ProducerBrokerExchange (org.apache.activemq.broker.ProducerBrokerExchange)2 StubBroker (org.apache.activemq.broker.StubBroker)2