use of org.apache.activemq.jaas.GroupPrincipal 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());
}
use of org.apache.activemq.jaas.GroupPrincipal 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");
}
}
use of org.apache.activemq.jaas.GroupPrincipal in project activemq-artemis by apache.
the class LDAPAuthorizationMapTest method testGetWriteACLs.
/*
* Test method for 'org.apache.activemq.security.LDAPAuthorizationMap.getWriteACLs(ActiveMQDestination)'
*/
@Test
public void testGetWriteACLs() {
ActiveMQDestination q1 = new ActiveMQQueue("queue1");
Set<GroupPrincipal> aclsq1 = authMap.getWriteACLs(q1);
assertEquals(2, aclsq1.size());
assertTrue(aclsq1.contains(new GroupPrincipal("role1")));
assertTrue(aclsq1.contains(new GroupPrincipal("role2")));
ActiveMQDestination t1 = new ActiveMQTopic("topic1");
Set<GroupPrincipal> aclst1 = authMap.getWriteACLs(t1);
assertEquals(1, aclst1.size());
assertTrue(aclst1.contains(new GroupPrincipal("role3")));
}
Aggregations