Search in sources :

Example 31 with NameCallback

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);
    }
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 32 with NameCallback

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;
    }
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) OathDeviceSettings(org.forgerock.openam.core.rest.devices.OathDeviceSettings) InvalidPasswordException(com.sun.identity.authentication.spi.InvalidPasswordException)

Example 33 with NameCallback

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);
}
Also used : HttpCallback(com.sun.identity.authentication.spi.HttpCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 34 with NameCallback

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;
        }
    }
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 35 with NameCallback

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("");
        }
    }
}
Also used : NameCallback(javax.security.auth.callback.NameCallback)

Aggregations

NameCallback (javax.security.auth.callback.NameCallback)203 PasswordCallback (javax.security.auth.callback.PasswordCallback)161 Callback (javax.security.auth.callback.Callback)140 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)101 IOException (java.io.IOException)60 LoginException (javax.security.auth.login.LoginException)51 CallbackHandler (javax.security.auth.callback.CallbackHandler)27 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)22 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)22 RealmCallback (javax.security.sasl.RealmCallback)22 Subject (javax.security.auth.Subject)19 FailedLoginException (javax.security.auth.login.FailedLoginException)19 LoginContext (javax.security.auth.login.LoginContext)18 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)18 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)17 Test (org.testng.annotations.Test)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 IdRepoException (com.sun.identity.idm.IdRepoException)13 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)11