use of javax.security.auth.callback.PasswordCallback 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.PasswordCallback 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");
}
use of javax.security.auth.callback.PasswordCallback 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.PasswordCallback 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.PasswordCallback 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();
}
Aggregations