use of org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal in project activemq-artemis by apache.
the class ActiveMQJAASSecurityManager method getUserFromSubject.
public String getUserFromSubject(Subject subject) {
String validatedUser = "";
Set<UserPrincipal> users = subject.getPrincipals(UserPrincipal.class);
// should only ever be 1 UserPrincipal
for (UserPrincipal userPrincipal : users) {
validatedUser = userPrincipal.getName();
}
return validatedUser;
}
use of org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal in project activemq-artemis by apache.
the class CertificateLoginModuleTest method checkPrincipalsMatch.
private void checkPrincipalsMatch(Subject subject) {
boolean nameFound = false;
boolean[] rolesFound = new boolean[ROLE_NAMES.size()];
for (int i = 0; i < rolesFound.length; ++i) {
rolesFound[i] = false;
}
for (Principal currentPrincipal : subject.getPrincipals()) {
if (currentPrincipal instanceof UserPrincipal) {
if (currentPrincipal.getName().equals(USER_NAME)) {
if (!nameFound) {
nameFound = true;
} else {
fail("UserPrincipal found twice.");
}
} else {
fail("Unknown UserPrincipal found.");
}
} else if (currentPrincipal instanceof RolePrincipal) {
int principalIdx = ROLE_NAMES.indexOf(((RolePrincipal) currentPrincipal).getName());
if (principalIdx < 0) {
fail("Unknown RolePrincipal found.");
}
if (!rolesFound[principalIdx]) {
rolesFound[principalIdx] = true;
} else {
fail("RolePrincipal found twice.");
}
} else {
fail("Unknown Principal type found.");
}
}
}
use of org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal in project activemq-artemis by apache.
the class GuestLoginModuleTest method testLoginWithDefaults.
@Test
public void testLoginWithDefaults() throws LoginException {
LoginContext context = new LoginContext("GuestLoginWithDefaults", new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
assertEquals("Should have no Callbacks", 0, callbacks.length);
}
});
context.login();
Subject subject = context.getSubject();
assertEquals("Should have two principals", 2, subject.getPrincipals().size());
assertEquals("Should have one user principal", 1, subject.getPrincipals(UserPrincipal.class).size());
assertTrue("User principal is 'guest'", subject.getPrincipals(UserPrincipal.class).contains(new UserPrincipal("guest")));
assertEquals("Should have one group principal", 1, subject.getPrincipals(RolePrincipal.class).size());
assertTrue("Role principal is 'guests'", subject.getPrincipals(RolePrincipal.class).contains(new RolePrincipal("guests")));
context.logout();
assertEquals("Should have zero principals", 0, subject.getPrincipals().size());
}
use of org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal in project activemq-artemis by apache.
the class GuestLoginModuleTest method testLogin.
@Test
public void testLogin() throws LoginException {
LoginContext context = new LoginContext("GuestLogin", new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
assertEquals("Should have no Callbacks", 0, callbacks.length);
}
});
context.login();
Subject subject = context.getSubject();
assertEquals("Should have two principals", 2, subject.getPrincipals().size());
assertEquals("Should have one user principal", 1, subject.getPrincipals(UserPrincipal.class).size());
assertTrue("User principal is 'foo'", subject.getPrincipals(UserPrincipal.class).contains(new UserPrincipal("foo")));
assertEquals("Should have one group principal", 1, subject.getPrincipals(RolePrincipal.class).size());
assertTrue("Role principal is 'bar'", subject.getPrincipals(RolePrincipal.class).contains(new RolePrincipal("bar")));
context.logout();
assertEquals("Should have zero principals", 0, subject.getPrincipals().size());
}
use of org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal in project activemq-artemis by apache.
the class UserPrincipalTest method testArguments.
@Test
public void testArguments() {
UserPrincipal principal = new UserPrincipal("FOO");
assertEquals("FOO", principal.getName());
try {
new UserPrincipal(null);
fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException ignore) {
}
}
Aggregations