Search in sources :

Example 16 with ConnectionContext

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

the class JaasCertificateAuthenticationBrokerTest method testAddConnectionSuccess.

public void testAddConnectionSuccess() {
    String dnUserName = "dnUserName";
    HashSet<String> userNames = new HashSet<>();
    userNames.add(dnUserName);
    HashSet<String> groupNames = new HashSet<>();
    groupNames.add("testGroup1");
    groupNames.add("testGroup2");
    groupNames.add("tesetGroup3");
    setConfiguration(userNames, groupNames, true);
    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.", dnUserName, receivedContext.getSecurityContext().getUserName());
    Set<Principal> receivedPrincipals = receivedContext.getSecurityContext().getPrincipals();
    for (Iterator<Principal> iter = receivedPrincipals.iterator(); iter.hasNext(); ) {
        Principal currentPrincipal = iter.next();
        if (currentPrincipal instanceof UserPrincipal) {
            if (userNames.remove(currentPrincipal.getName())) {
            // Nothing, we did good.
            } else {
                // Found an unknown userName.
                fail("Unknown UserPrincipal found");
            }
        } else if (currentPrincipal instanceof GroupPrincipal) {
            if (groupNames.remove(currentPrincipal.getName())) {
            // Nothing, we did good.
            } else {
                fail("Unknown GroupPrincipal found.");
            }
        } else {
            fail("Unexpected Principal subclass found.");
        }
    }
    if (!userNames.isEmpty()) {
        fail("Some usernames were not added as UserPrincipals");
    }
    if (!groupNames.isEmpty()) {
        fail("Some group names were not added as GroupPrincipals");
    }
}
Also used : 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) HashSet(java.util.HashSet)

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