Example usage for com.amazonaws.services.cognitoidp.model ConfirmDeviceResult isUserConfirmationNecessary

List of usage examples for com.amazonaws.services.cognitoidp.model ConfirmDeviceResult isUserConfirmationNecessary

Introduction

In this page you can find the example usage for com.amazonaws.services.cognitoidp.model ConfirmDeviceResult isUserConfirmationNecessary.

Prototype


public Boolean isUserConfirmationNecessary() 

Source Link

Document

Indicates whether the user confirmation is necessary to confirm the device response.

Usage

From source file:io.fineo.client.auth.cognito.CognitoUser.java

License:Open Source License

/**
 * Find the next step from the challenge.
 * This is an important step in the generic authentication flow. After the responding to a challenge,
 * the results are analyzed here to determine the next step in the authentication process.
 * Like all other methods in this SDK, this is designed to work with Continuation objects.
 * This method returns a {@link Runnable} with the code to be executed, for the next step, to the invoking Continuation.
 * The possible steps are/*from   ww w.j av  a  2 s. c o  m*/
 *  1) Authentication was successful and we have the tokens, in this case we call {@code onSuccess()} to return the tokens.
 *  2) User password is required, an AuthenticationContinuation is created.
 *  3) MFA validation is required, a MultiFactorAuthenticationContinuation object is created.
 *  4) Other generic challenge, the challenge details are passed to the user.
 *
 * @param challenge                 REQUIRED: Current challenge details, {@link RespondToAuthChallengeResult}.
 * @param callback                  REQUIRED: {@link AuthenticationDetails} callback.
 * @param runInBackground           REQUIRED: Boolean to indicate the current threading.
 * @return {@link Runnable} for the next step in user authentication.
 */
private Runnable handleChallenge(final RespondToAuthChallengeResult challenge,
        final AuthenticationHandler callback, final boolean runInBackground) {
    Runnable nextTask;
    final CognitoUser cognitoUser = this;
    nextTask = new Runnable() {
        @Override
        public void run() {
            callback.onFailure(
                    new CognitoInternalErrorException("Authentication failed due to an internal error"));
        }
    };

    if (challenge == null) {
        return nextTask;
    }

    updateInternalUsername(challenge.getChallengeParameters());
    String challengeName = challenge.getChallengeName();
    if (challengeName == null) {
        LOG.debug("Got challenge: {}", challenge);
        final CognitoUserSession cognitoUserSession = getCognitoUserSession(
                challenge.getAuthenticationResult());
        cacheTokens(cognitoUserSession);
        NewDeviceMetadataType newDeviceMetadata = challenge.getAuthenticationResult().getNewDeviceMetadata();
        if (newDeviceMetadata == null) {
            nextTask = new Runnable() {
                @Override
                public void run() {
                    callback.onSuccess(cognitoUserSession, null);
                }
            };
        } else {
            ConfirmDeviceResult confirmDeviceResult = confirmDevice(newDeviceMetadata);
            if (confirmDeviceResult != null && confirmDeviceResult.isUserConfirmationNecessary()) {
                final CognitoDevice newDevice = new CognitoDevice(newDeviceMetadata.getDeviceKey(), null, null,
                        null, null, cognitoUser);
                nextTask = new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess(cognitoUserSession, newDevice);
                    }
                };
            } else {
                nextTask = new Runnable() {
                    @Override
                    public void run() {
                        callback.onSuccess(cognitoUserSession, null);
                    }
                };
            }
        }
    } else if (challengeName.equals("PASSWORD_VERIFIER")) {
        return nextTask;
    } else if (challengeName.equals("SMS_MFA")) {
        throw new UnsupportedOperationException("MFA challenges not supported!");
    } else if (challengeName.equals("DEVICE_SRP_AUTH")) {
        nextTask = deviceSrpAuthentication(challenge, callback, runInBackground);
    } else {
        throw new RuntimeException("Generic challenge continuation no supported!");
        //            final ChallengeContinuation challengeContinuation =
        //                    new ChallengeContinuation(cognitoUser, context, clientId, challenge, runInBackground, callback);
        //            nextTask = new Runnable() {
        //                @Override
        //                public void run() {
        //                    callback.authenticationChallenge(challengeContinuation);
        //                }
        //            };
    }
    return nextTask;
}