use of javax.security.auth.callback.UnsupportedCallbackException in project atlas by apache.
the class AtlasAuthenticationKerberosFilterTest method loginTestUser.
protected Subject loginTestUser() throws LoginException, IOException {
LoginContext lc = new LoginContext(TEST_USER_JAAS_SECTION, new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof PasswordCallback) {
PasswordCallback passwordCallback = (PasswordCallback) callback;
passwordCallback.setPassword(TESTPASS.toCharArray());
}
if (callback instanceof NameCallback) {
NameCallback nameCallback = (NameCallback) callback;
nameCallback.setName(TESTUSER);
}
}
}
});
// attempt authentication
lc.login();
return lc.getSubject();
}
use of javax.security.auth.callback.UnsupportedCallbackException 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.UnsupportedCallbackException 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.UnsupportedCallbackException in project activemq-artemis by apache.
the class TextFileCertificateLoginModuleTest method getJaasCertificateCallbackHandler.
private JaasCallbackHandler getJaasCertificateCallbackHandler(String user) {
JMXPrincipal principal = new JMXPrincipal(user);
X509Certificate cert = new StubX509Certificate(principal);
return new JaasCallbackHandler(null, null, null) {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof CertificateCallback) {
CertificateCallback certCallback = (CertificateCallback) callback;
certCallback.setCertificates(new X509Certificate[] { cert });
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
};
}
use of javax.security.auth.callback.UnsupportedCallbackException in project activemq-artemis by apache.
the class LDAPLoginModuleMaskPasswordTest method testLoginExternalCodecUnauthenticated.
@Test
public void testLoginExternalCodecUnauthenticated() throws LoginException {
LoginContext context = new LoginContext("LDAPLoginExternalPasswordCodec", 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");
}
Aggregations