Example usage for javax.security.auth.callback ConfirmationCallback getSelectedIndex

List of usage examples for javax.security.auth.callback ConfirmationCallback getSelectedIndex

Introduction

In this page you can find the example usage for javax.security.auth.callback ConfirmationCallback getSelectedIndex.

Prototype

public int getSelectedIndex() 

Source Link

Document

Get the selected confirmation option.

Usage

From source file:org.forgerock.openam.authentication.modules.duosecurity.DuoSecurityModule.java

/**
 * {@inheritDoc}//ww  w .j a  v  a2s .co  m
 */
@Override
public int process(Callback[] callbacks, int state) throws LoginException {

    debug.message("INSIDE process of DuoSecurityModule, state: " + state);

    if (debug.messageEnabled()) {
        debug.message("DuoSecurity::process state: " + state);
    }

    ConfirmationCallback cc = (ConfirmationCallback) callbacks[0];
    int button = cc.getSelectedIndex();

    int nextState = STATE_AUTH;

    if (button == 1)
        return CANCELED;

    switch (state) {
    case ISAuthConstants.LOGIN_START:

        if (auto_push) {
            //Auto-push is enabled so callback 1 becomes callback 2
            debug.message("auto-push enabled, skipping first callback");

            // String new_hdr = ssa + " " + bundle.getString("sampleauth-ui-login-header");
            //    substituteHeader(STATE_AUTH, new_hdr);

            //    Callback[] cbs_phone = getCallback(STATE_AUTH);

            //    replaceCallback(STATE_AUTH, 0,
            //                new NameCallback(bundle.getString("sampleauth-ui-username-prompt")));

            //    replaceCallback(STATE_AUTH, 1,
            //                new PasswordCallback(bundle.getString("sampleauth-ui-password-prompt"), false));

            try {
                debug.message("polling with txid: " + txid);
                String result = pollDuoPushAuthStatus(txid);
                if (result.equals("waiting")) {
                    nextState = STATE_AUTH;
                } else if (result.equals("allow")) {
                    nextState = ISAuthConstants.LOGIN_SUCCEED;
                } else if (result.equals("deny")) {
                    throw new AuthLoginException("Duo Push denied: " + status_detail);
                } else {
                    debug.error("not expecting this result: " + result);
                    throw new AuthLoginException("Bad result from Duo Push: " + result);
                }
            } catch (Exception ex) {
                debug.error("Exception polling for result!!");
                throw new AuthLoginException(ex);
            }

        } else {
            try {
                txid = invokeDuoSecurityAuthAPI(1);
                nextState = STATE_AUTH;
            } catch (Exception ex) {
                debug.message("Exception submitting AuthAPI request to Duo!!");
                throw new AuthLoginException(ex);
            }
        }
        break;
    case STATE_AUTH:
        try {
            debug.message("polling with txid: " + txid);
            String result = pollDuoPushAuthStatus(txid);
            if (result.equals("waiting")) {
                nextState = STATE_AUTH;
            } else if (result.equals("allow")) {
                nextState = ISAuthConstants.LOGIN_SUCCEED;
            } else if (result.equals("deny")) {
                throw new AuthLoginException("Duo Push denied: " + status_detail);
            } else {
                debug.error("not expecting this result: " + result);
                throw new AuthLoginException("Bad result from Duo Push: " + result);
            }
        } catch (Exception ex) {
            debug.error("Exception polling for result!!");
            throw new AuthLoginException(ex);
        }
        break;
    default:
        throw new AuthLoginException("invalid state");

    }
    return nextState;
}