use of javax.security.auth.callback.UnsupportedCallbackException in project activemq-artemis by apache.
the class LDAPLoginModuleMaskPasswordTest method testLoginExternalCodec2.
@Test
public void testLoginExternalCodec2() throws LoginException {
LoginContext context = new LoginContext("LDAPLoginExternalPasswordCodec2", callbacks -> {
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.UnsupportedCallbackException in project activemq-artemis by apache.
the class LDAPLoginModuleMaskPasswordTest method testLoginMaskedPasswordUnauthenticated.
@Test
public void testLoginMaskedPasswordUnauthenticated() throws LoginException {
LoginContext context = new LoginContext("LDAPLoginMaskedPassword", callbacks -> {
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("nosecret".toCharArray());
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
}
});
try {
context.login();
} catch (FailedLoginException le) {
assertEquals(le.getMessage(), "Password does not match for user: first");
return;
}
fail("Should have failed authenticating");
}
use of javax.security.auth.callback.UnsupportedCallbackException 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.UnsupportedCallbackException 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.UnsupportedCallbackException 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