use of javax.security.auth.callback.Callback in project alluxio by Alluxio.
the class PlainSaslClientCallbackHandlerTest method clientCallbackHandler.
/**
* Tests that the callback is handled correctly.
*/
@Test
public void clientCallbackHandler() throws Exception {
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("Username:");
callbacks[1] = new PasswordCallback("Password:", true);
String user = "alluxio-user-1";
String password = "alluxio-user-1-password";
CallbackHandler clientCBHandler = new PlainSaslClientCallbackHandler(user, password);
clientCBHandler.handle(callbacks);
validateCallbacks(user, password, callbacks);
}
use of javax.security.auth.callback.Callback in project alluxio by Alluxio.
the class PlainSaslClientCallbackHandlerTest method unsupportCallback.
/**
* Tests that an exception is thrown in case an unsupported callback is used.
*/
@Test
public void unsupportCallback() throws Exception {
mThrown.expect(UnsupportedCallbackException.class);
mThrown.expectMessage(RealmCallback.class + " is unsupported.");
Callback[] callbacks = new Callback[3];
callbacks[0] = new NameCallback("Username:");
callbacks[1] = new PasswordCallback("Password:", true);
callbacks[2] = new RealmCallback("Realm:");
String user = "alluxio-user-2";
String password = "alluxio-user-2-password";
CallbackHandler clientCBHandler = new PlainSaslClientCallbackHandler(user, password);
clientCBHandler.handle(callbacks);
}
use of javax.security.auth.callback.Callback in project alluxio by Alluxio.
the class PlainSaslServerCallbackHandlerTest method authenticateNameMatch.
/**
* Tests that the authentication callbacks matches.
*
* @throws Exception thrown if the handler fails
*/
@Test
public void authenticateNameMatch() throws Exception {
String authenticateId = "alluxio-1";
NameCallback ncb = new NameCallback(" authentication id: ");
ncb.setName(authenticateId);
PasswordCallback pcb = new PasswordCallback(" password: ", false);
pcb.setPassword("password".toCharArray());
Callback[] callbacks = new Callback[] { ncb, pcb, new AuthorizeCallback(authenticateId, authenticateId) };
mPlainServerCBHandler.handle(callbacks);
}
use of javax.security.auth.callback.Callback in project nhin-d by DirectProject.
the class TestUtils method setupSafeNetToken.
/**
* used for testing with a pkcs11 token
* @return The Security provider name if the token is loaded successfully... an empty string other wise
* @throws Exception
*/
public static String setupSafeNetToken() throws Exception {
final CallbackHandler handler = new CallbackHandler() {
public void handle(Callback[] callbacks) {
for (Callback callback : callbacks) {
if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword("1Kingpuff".toCharArray());
}
}
}
};
sun.security.pkcs11.SunPKCS11 p = null;
final String configName = "./src/test/resources/pkcs11Config/pkcs11.cfg";
try {
p = new sun.security.pkcs11.SunPKCS11(configName);
Security.addProvider(p);
p.login(null, handler);
} catch (Exception e) {
return "";
}
return p.getName();
}
use of javax.security.auth.callback.Callback in project AuthMeReloaded by AuthMe.
the class OAuth2SaslClient method evaluateChallenge.
public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
if (isComplete) {
// Empty final response from server, just ignore it.
return new byte[] {};
}
NameCallback nameCallback = new NameCallback("Enter name");
Callback[] callbacks = new Callback[] { nameCallback };
try {
callbackHandler.handle(callbacks);
} catch (UnsupportedCallbackException e) {
throw new SaslException("Unsupported callback: " + e);
} catch (IOException e) {
throw new SaslException("Failed to execute callback: " + e);
}
String email = nameCallback.getName();
byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", email, oauthToken).getBytes();
isComplete = true;
return response;
}
Aggregations