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");
}
}
Aggregations