use of javax.security.auth.callback.NameCallback in project OpenAM by OpenRock.
the class UserPrivilegeTest method addLoginCallbackMessage.
static void addLoginCallbackMessage(Callback[] callbacks, String userId, String password) throws UnsupportedCallbackException {
int i = 0;
try {
for (i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
// prompt the user for a username
NameCallback nc = (NameCallback) callbacks[i];
//System.out.println("userName=" + userId);
nc.setName(userId);
} else if (callbacks[i] instanceof PasswordCallback) {
// prompt the user for sensitive information
PasswordCallback pc = (PasswordCallback) callbacks[i];
//System.out.println("password=" + password);
pc.setPassword(password.toCharArray());
} else {
}
}
} catch (Exception e) {
//throw new UnsupportedCallbackException(callbacks[i],
//"Callback exception: " + e);
}
}
use of javax.security.auth.callback.NameCallback in project OpenAM by OpenRock.
the class AuthenticatorOATH method doLoginSavedDevice.
private int doLoginSavedDevice(final Callback[] callbacks, final int state, final OathDeviceSettings settings) throws AuthLoginException, IOException, IdRepoException, SSOException {
OathDeviceSettings deviceToAuthAgainst = settings;
if (null == deviceToAuthAgainst && null != newDevice) {
deviceToAuthAgainst = newDevice;
}
//get OTP
String OTP = ((NameCallback) callbacks[0]).getName();
if (OTP.length() == 0) {
debug.error("OATH.process() : invalid OTP code");
if (++attempt >= TOTAL_ATTEMPTS) {
setFailureID(userName);
throw new InvalidPasswordException("amAuth", "invalidPasswd", null);
}
replaceHeader(state, MODULE_NAME + "Attempt " + (attempt + 1) + " of " + TOTAL_ATTEMPTS);
return state;
}
//get Arrival time of the OTP
time = System.currentTimeMillis() / 1000L;
if (isRecoveryCode(OTP, deviceToAuthAgainst, id)) {
return RECOVERY_USED;
} else if (checkOTP(OTP, id, deviceToAuthAgainst)) {
if (isOptional) {
//if it's optional and you log in, config not skippable
realmOathService.setUserSkipOath(id, AuthenticatorOathService.NOT_SKIPPABLE);
}
if (null == settings) {
// this is the first time we have authorised against this device - we can now save it.
deviceFactory.saveDeviceProfile(id.getName(), id.getRealm(), deviceToAuthAgainst);
}
return ISAuthConstants.LOGIN_SUCCEED;
} else {
//the OTP is out of the window or incorrect
if (++attempt >= TOTAL_ATTEMPTS) {
setFailureID(userName);
throw new InvalidPasswordException("amAuth", "invalidPasswd", null);
}
replaceHeader(state, MODULE_NAME + "Attempt " + (attempt + 1) + " of " + TOTAL_ATTEMPTS);
return state;
}
}
use of javax.security.auth.callback.NameCallback in project OpenAM by OpenRock.
the class HTTPBasic method authenticateToBackEndModule.
private int authenticateToBackEndModule() throws LoginException {
Callback[] callbacks = new Callback[2];
NameCallback nameCallback = new NameCallback("dummy");
nameCallback.setName(userName);
callbacks[0] = nameCallback;
PasswordCallback passwordCallback = new PasswordCallback("dummy", false);
passwordCallback.setPassword(userPassword.toCharArray());
callbacks[1] = passwordCallback;
return amLoginModule.process(callbacks, ISAuthConstants.LOGIN_START);
}
use of javax.security.auth.callback.NameCallback in project OpenAM by OpenRock.
the class Membership method updateRegistrationCallbackFields.
private void updateRegistrationCallbackFields(Callback[] submittedCallbacks) throws AuthLoginException {
Callback[] origCallbacks = getCallback(ModuleState.REGISTRATION.intValue());
for (int c = 0; c < origCallbacks.length; c++) {
if (origCallbacks[c] instanceof NameCallback) {
NameCallback nc = (NameCallback) origCallbacks[c];
nc.setName(((NameCallback) submittedCallbacks[c]).getName());
replaceCallback(ModuleState.REGISTRATION.intValue(), c, nc);
} else if (origCallbacks[c] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) origCallbacks[c];
pc.setPassword(((PasswordCallback) submittedCallbacks[c]).getPassword());
replaceCallback(ModuleState.REGISTRATION.intValue(), c, pc);
} else {
continue;
}
}
}
use of javax.security.auth.callback.NameCallback in project OpenAM by OpenRock.
the class Membership method clearCallbacks.
/**
* User input value will be store in the callbacks[].
* When user click cancel button, these input field should be reset
* to blank.
*/
private void clearCallbacks(Callback[] callbacks) {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback nc = (NameCallback) callbacks[i];
nc.setName("");
}
}
}
Aggregations