List of usage examples for com.amazonaws.services.cognitoidp.model RespondToAuthChallengeResult getChallengeParameters
public java.util.Map<String, String> getChallengeParameters()
The challenge parameters.
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 w w w . java2 s .com * 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; }