Search in sources :

Example 26 with Callback

use of javax.security.auth.callback.Callback 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 27 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class LDAP method processLoginScreen.

private void processLoginScreen(ModuleState newState) throws AuthLoginException {
    try {
        switch(newState) {
            case SUCCESS:
                validatedUserID = ldapUtil.getUserId();
                createProfile();
                currentState = ISAuthConstants.LOGIN_SUCCEED;
                setForceCallbacksRead(false);
                break;
            case PASSWORD_EXPIRING:
                {
                    String fmtMsg = bundle.getString("PasswordExp");
                    String msg = com.sun.identity.shared.locale.Locale.formatMessage(fmtMsg, ldapUtil.getExpTime());
                    /**
                     * In case of sharedstate if the chain breaks in ldap
                     * because of abnormal condition like pwd expiring
                     * then the callbacks has to be read fresh so that new
                     * screen appears for the user.
                     */
                    setForceCallbacksRead(true);
                    forceCallbacksInit();
                    replaceHeader(LoginScreen.PASSWORD_CHANGE.intValue(), msg);
                }
                currentState = LoginScreen.PASSWORD_CHANGE.intValue();
                break;
            case PASSWORD_RESET_STATE:
            case CHANGE_AFTER_RESET:
                isReset = true;
                String resetMsg = bundle.getString("PasswordReset");
                /**
                     * In case of sharedstate if the chain breaks in ldap
                     * because of abnormal condition like pwd reset
                     * then the callbacks has to be read fresh so that new
                     * screen appears for the user.
                     */
                setForceCallbacksRead(true);
                forceCallbacksInit();
                replaceHeader(LoginScreen.PASSWORD_CHANGE.intValue(), resetMsg);
                currentState = LoginScreen.PASSWORD_CHANGE.intValue();
                break;
            case PASSWORD_EXPIRED_STATE:
                setFailureID(ldapUtil.getUserId(userName));
                currentState = LoginScreen.PASSWORD_EXPIRED_SCREEN.intValue();
                break;
            case ACCOUNT_LOCKED:
                setFailureID(ldapUtil.getUserId(userName));
                currentState = LoginScreen.ACCOUNT_LOCKED.intValue();
                break;
            case GRACE_LOGINS:
                {
                    String fmtMsg = bundle.getString("GraceLogins");
                    String msg = com.sun.identity.shared.locale.Locale.formatMessage(fmtMsg, ldapUtil.getGraceLogins());
                    setForceCallbacksRead(true);
                    forceCallbacksInit();
                    if (ldapUtil.getGraceLogins() == 1) {
                        Callback[] callback = getCallback(LoginScreen.PASSWORD_CHANGE.intValue());
                        for (int i = 0; i < callback.length; i++) {
                            Callback cbk = callback[i];
                            if (cbk instanceof ConfirmationCallback) {
                                ConfirmationCallback confirm = (ConfirmationCallback) cbk;
                                String[] options = confirm.getOptions();
                                String[] newOptions = new String[1];
                                System.arraycopy(options, 0, newOptions, 0, 1);
                                ConfirmationCallback newConfirm = new ConfirmationCallback(confirm.getMessageType(), newOptions, confirm.getDefaultOption());
                                replaceCallback(LoginScreen.PASSWORD_CHANGE.intValue(), i, newConfirm);
                            }
                        }
                    }
                    replaceHeader(LoginScreen.PASSWORD_CHANGE.intValue(), msg);
                }
                currentState = LoginScreen.PASSWORD_CHANGE.intValue();
                break;
            case TIME_BEFORE_EXPIRATION:
                {
                    String fmtMsg = bundle.getString("TimeBeforeExpiration");
                    String msg = com.sun.identity.shared.locale.Locale.formatMessage(fmtMsg, ldapUtil.getExpTime());
                    setForceCallbacksRead(true);
                    forceCallbacksInit();
                    replaceHeader(LoginScreen.PASSWORD_CHANGE.intValue(), msg);
                }
                currentState = LoginScreen.PASSWORD_CHANGE.intValue();
            case USER_NOT_FOUND:
                throw new LDAPUtilException("noUserMatchFound", (Object[]) null);
            case SERVER_DOWN:
                throw new AuthLoginException(AM_AUTH, "LDAPex", null);
            default:
        }
    } catch (LDAPUtilException ex) {
        if (getCredentialsFromSharedState && !isUseFirstPassEnabled()) {
            getCredentialsFromSharedState = false;
            currentState = LoginScreen.LOGIN_START.intValue();
            return;
        }
        if (newState != ModuleState.USER_NOT_FOUND) {
            debug.error("Unknown Login State:", ex);
        }
        throw new AuthLoginException(AM_AUTH, "LDAPex", null, ex);
    }
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) LDAPUtilException(org.forgerock.openam.ldap.LDAPUtilException)

Example 28 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class LDAPCallbacks method chgPwdCallback.

private void chgPwdCallback() throws LoginException {
    char[] pwd = null;
    if (callbackHandler == null) {
        throw new LoginException(bundle.getString("NoCallbackHandler"));
    }
    Callback[] callbacks = new Callback[4];
    callbacks[0] = new TextOutputCallback(TextOutputCallback.INFORMATION, "Change Password");
    callbacks[1] = new PasswordCallback("EnterOld Password", false);
    callbacks[2] = new PasswordCallback("Enter New Password", false);
    callbacks[3] = new PasswordCallback("Confirm Password", false);
    try {
        callbackHandler.handle(callbacks);
        oldPassword = charToString(((PasswordCallback) callbacks[1]).getPassword(), callbacks[1]);
        newPassword = charToString(((PasswordCallback) callbacks[2]).getPassword(), callbacks[2]);
        confirmPassword = charToString(((PasswordCallback) callbacks[3]).getPassword(), callbacks[3]);
    } catch (java.io.IOException ioe) {
        throw new LoginException(ioe.toString());
    } catch (UnsupportedCallbackException uce) {
        throw new LoginException(bundle.getString("NoCallbackHandler"));
    }
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) Callback(javax.security.auth.callback.Callback) LoginException(javax.security.auth.login.LoginException) PasswordCallback(javax.security.auth.callback.PasswordCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 29 with Callback

use of javax.security.auth.callback.Callback 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 30 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class Membership method loginUser.

private ModuleState loginUser(Callback[] callbacks) throws AuthLoginException {
    String password = null;
    Callback[] idCallbacks = new Callback[2];
    try {
        if (callbacks != null && callbacks.length == 0) {
            userName = (String) sharedState.get(getUserKey());
            password = (String) sharedState.get(getPwdKey());
            if (userName == null || password == null) {
                return ModuleState.LOGIN_START;
            }
            getCredentialsFromSharedState = true;
            NameCallback nameCallback = new NameCallback("dummy");
            nameCallback.setName(userName);
            idCallbacks[0] = nameCallback;
            PasswordCallback passwordCallback = new PasswordCallback("dummy", false);
            passwordCallback.setPassword(password.toCharArray());
            idCallbacks[1] = passwordCallback;
        } else {
            idCallbacks = callbacks;
            //callbacks is not null
            userName = ((NameCallback) callbacks[0]).getName();
            password = String.valueOf(((PasswordCallback) callbacks[1]).getPassword());
        }
        if (password == null || password.length() == 0) {
            if (debug.messageEnabled()) {
                debug.message("Membership.loginUser: Password is null/empty");
            }
            throw new InvalidPasswordException("amAuth", "invalidPasswd", null);
        }
        //store username password both in success and failure case
        storeUsernamePasswd(userName, password);
        initAuthConfig();
        AMIdentityRepository idrepo = getAMIdentityRepository(getRequestOrg());
        boolean success = idrepo.authenticate(idCallbacks);
        if (success) {
            validatedUserID = userName;
            return ModuleState.COMPLETE;
        } else {
            throw new AuthLoginException(amAuthMembership, "authFailed", null);
        }
    } catch (IdRepoException ex) {
        if (getCredentialsFromSharedState && !isUseFirstPassEnabled()) {
            getCredentialsFromSharedState = false;
            return ModuleState.LOGIN_START;
        }
        if (debug.warningEnabled()) {
            debug.warning("idRepo Exception");
        }
        setFailureID(userName);
        throw new AuthLoginException(amAuthMembership, "authFailed", null, ex);
    }
}
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) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) PasswordCallback(javax.security.auth.callback.PasswordCallback) InvalidPasswordException(com.sun.identity.authentication.spi.InvalidPasswordException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException)

Aggregations

Callback (javax.security.auth.callback.Callback)390 NameCallback (javax.security.auth.callback.NameCallback)250 PasswordCallback (javax.security.auth.callback.PasswordCallback)245 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)210 IOException (java.io.IOException)141 LoginException (javax.security.auth.login.LoginException)89 CallbackHandler (javax.security.auth.callback.CallbackHandler)76 Subject (javax.security.auth.Subject)52 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)52 Test (org.testng.annotations.Test)42 FailedLoginException (javax.security.auth.login.FailedLoginException)41 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)38 Principal (java.security.Principal)37 HashMap (java.util.HashMap)37 LoginContext (javax.security.auth.login.LoginContext)37 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)31 Test (org.junit.Test)31 RealmCallback (javax.security.sasl.RealmCallback)30 AuthorizeCallback (javax.security.sasl.AuthorizeCallback)29 HttpServletRequest (javax.servlet.http.HttpServletRequest)28