Search in sources :

Example 1 with GroupPrincipal

use of org.apache.activemq.jaas.GroupPrincipal 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 GroupPrincipal

use of org.apache.activemq.jaas.GroupPrincipal in project activemq-artemis by apache.

the class LDAPAuthorizationMapTest method testComposite.

@Test
public void testComposite() {
    ActiveMQDestination q1 = new ActiveMQQueue("queue1,topic://topic1");
    Set<GroupPrincipal> aclsq1 = authMap.getWriteACLs(q1);
    assertEquals(0, aclsq1.size());
}
Also used : GroupPrincipal(org.apache.activemq.jaas.GroupPrincipal) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Test(org.junit.Test)

Example 3 with GroupPrincipal

use of org.apache.activemq.jaas.GroupPrincipal in project activemq-artemis by apache.

the class LDAPAuthorizationMapTest method testGetAdminACLs.

/*
    * Test method for 'org.apache.activemq.security.LDAPAuthorizationMap.getAdminACLs(ActiveMQDestination)'
    */
@Test
public void testGetAdminACLs() {
    ActiveMQDestination q1 = new ActiveMQQueue("queue1");
    Set<GroupPrincipal> aclsq1 = authMap.getAdminACLs(q1);
    assertEquals(1, aclsq1.size());
    assertTrue(aclsq1.contains(new GroupPrincipal("role1")));
    ActiveMQDestination t1 = new ActiveMQTopic("topic1");
    Set<GroupPrincipal> aclst1 = authMap.getAdminACLs(t1);
    assertEquals(1, aclst1.size());
    assertTrue(aclst1.contains(new GroupPrincipal("role1")));
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) GroupPrincipal(org.apache.activemq.jaas.GroupPrincipal) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Test(org.junit.Test)

Example 4 with GroupPrincipal

use of org.apache.activemq.jaas.GroupPrincipal in project activemq-artemis by apache.

the class LDAPAuthorizationMapTest method testAdvisory.

@Test
public void testAdvisory() {
    ActiveMQDestination dest = AdvisorySupport.getConnectionAdvisoryTopic();
    Set<GroupPrincipal> acls = authMap.getWriteACLs(dest);
    assertEquals(1, acls.size());
    assertTrue(acls.contains(new GroupPrincipal("role3")));
}
Also used : GroupPrincipal(org.apache.activemq.jaas.GroupPrincipal) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Test(org.junit.Test)

Example 5 with GroupPrincipal

use of org.apache.activemq.jaas.GroupPrincipal in project activemq-artemis by apache.

the class LDAPAuthorizationMapTest method testGetReadACLs.

/*
    * Test method for 'org.apache.activemq.security.LDAPAuthorizationMap.getReadACLs(ActiveMQDestination)'
    */
@Test
public void testGetReadACLs() {
    ActiveMQDestination q1 = new ActiveMQQueue("queue1");
    Set<GroupPrincipal> aclsq1 = authMap.getReadACLs(q1);
    assertEquals(1, aclsq1.size());
    assertTrue(aclsq1.contains(new GroupPrincipal("role1")));
    ActiveMQDestination t1 = new ActiveMQTopic("topic1");
    Set<GroupPrincipal> aclst1 = authMap.getReadACLs(t1);
    assertEquals(1, aclst1.size());
    assertTrue(aclst1.contains(new GroupPrincipal("role2")));
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) GroupPrincipal(org.apache.activemq.jaas.GroupPrincipal) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Test(org.junit.Test)

Aggregations

GroupPrincipal (org.apache.activemq.jaas.GroupPrincipal)8 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)5 Test (org.junit.Test)5 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 Principal (java.security.Principal)3 ConnectionContext (org.apache.activemq.broker.ConnectionContext)3 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)3 UserPrincipal (org.apache.activemq.jaas.UserPrincipal)3 Connector (org.apache.activemq.broker.Connector)2 TransportConnector (org.apache.activemq.broker.TransportConnector)2 HashSet (java.util.HashSet)1