use of javax.security.auth.callback.CallbackHandler in project activemq-artemis by apache.
the class Krb5LoginModuleTest method loginSuccess.
@Test
public void loginSuccess() throws Exception {
Krb5LoginModule underTest = new Krb5LoginModule();
final Subject subject = new Subject();
underTest.initialize(subject, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
((Krb5Callback) callbacks[0]).setPeerPrincipal(new UserPrincipal("A"));
}
}, null, null);
assertTrue(underTest.login());
}
use of javax.security.auth.callback.CallbackHandler in project activemq-artemis by apache.
the class Krb5LoginModuleTest method loginFail.
@Test
public void loginFail() throws Exception {
Krb5LoginModule underTest = new Krb5LoginModule();
final Subject subject = new Subject();
underTest.initialize(subject, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
}
}, null, null);
assertFalse(underTest.login());
}
use of javax.security.auth.callback.CallbackHandler in project activemq-artemis by apache.
the class LDAPLoginModuleTest method testLogin.
@Test
public void testLogin() throws LoginException {
LoginContext context = new LoginContext("LDAPLogin", new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
((NameCallback) callbacks[i]).setName("first");
} else if (callbacks[i] instanceof PasswordCallback) {
((PasswordCallback) callbacks[i]).setPassword("secret".toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
}
}
});
context.login();
context.logout();
}
use of javax.security.auth.callback.CallbackHandler 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 javax.security.auth.callback.CallbackHandler 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());
}
Aggregations