Search in sources :

Example 1 with ResourceNotFoundException

use of com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderUserPoolTest method signUpResourceNotFoundException.

// Register with invalid clientId
@Test
public void signUpResourceNotFoundException() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    ResourceNotFoundException exception = new ResourceNotFoundException("registration failed");
    doThrow(exception).when(mockCSIClient).signUp(any(SignUpRequest.class));
    testPool.signUp(TEST_USER_NAME, "null", TEST_IN_USER_ATTRIBUTES_LIST, TEST_IN_VALIDATION_DATA, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            assertNotNull(user);
            assertEquals(TEST_USER_NAME, user.getUserId());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
            assertTrue(exception instanceof ResourceNotFoundException);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Example 2 with ResourceNotFoundException

use of com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException in project aws-sdk-android by aws-amplify.

the class CognitoUser method startWithUserSrpAuth.

/**
 * This method starts the user authentication with user password
 * verification. Restarts authentication if the service cannot find a
 * device-key.
 *
 * @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
 *                       custom workflow.
 * @param authenticationDetails REQUIRED: {@link AuthenticationDetails}
 *            contains user details for authentication.
 * @param callback REQUIRED: {@link AuthenticationHandler} callback.
 * @param runInBackground REQUIRED: Boolean to indicate the current
 *            threading.
 * @return {@link Runnable} for the next step in user authentication.
 */
private Runnable startWithUserSrpAuth(final Map<String, String> clientMetadata, final AuthenticationDetails authenticationDetails, final AuthenticationHandler callback, final boolean runInBackground) {
    return new Runnable() {

        @Override
        public void run() {
            final AuthenticationHelper authenticationHelper = new AuthenticationHelper(pool.getUserPoolId());
            final InitiateAuthRequest initiateAuthRequest = initiateUserSrpAuthRequest(clientMetadata, authenticationDetails, authenticationHelper);
            try {
                final InitiateAuthResult initiateAuthResult = cognitoIdentityProviderClient.initiateAuth(initiateAuthRequest);
                updateInternalUsername(initiateAuthResult.getChallengeParameters());
                if (CognitoServiceConstants.CHLG_TYPE_USER_PASSWORD_VERIFIER.equals(initiateAuthResult.getChallengeName())) {
                    if (authenticationDetails.getPassword() == null) {
                        throw new IllegalStateException("Failed to find password in " + "authentication details to response to PASSWORD_VERIFIER challenge");
                    }
                    final RespondToAuthChallengeRequest challengeRequest = userSrpAuthRequest(clientMetadata, initiateAuthResult.getChallengeParameters(), authenticationDetails.getPassword(), initiateAuthResult.getChallengeName(), initiateAuthResult.getSession(), authenticationHelper);
                    respondToChallenge(clientMetadata, challengeRequest, callback, runInBackground).run();
                } else {
                    handleChallenge(clientMetadata, initiateAuthResult, authenticationDetails, callback, runInBackground).run();
                }
            } catch (final ResourceNotFoundException rna) {
                final CognitoUser cognitoUser = CognitoUser.this;
                if (rna.getMessage().contains("Device")) {
                    CognitoDeviceHelper.clearCachedDevice(usernameInternal, pool.getUserPoolId(), context);
                    final AuthenticationContinuation authenticationContinuation = new AuthenticationContinuation(cognitoUser, context, runInBackground, callback);
                    authenticationContinuation.setClientMetaData(clientMetadata);
                    callback.getAuthenticationDetails(authenticationContinuation, cognitoUser.getUserId());
                } else {
                    callback.onFailure(rna);
                }
            } catch (final Exception e) {
                callback.onFailure(e);
            }
        }
    };
}
Also used : InitiateAuthRequest(com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest) InitiateAuthResult(com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthResult) MultiFactorAuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation) AuthenticationContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation) RespondToAuthChallengeRequest(com.amazonaws.services.cognitoidentityprovider.model.RespondToAuthChallengeRequest) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CognitoInternalErrorException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException) UserNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException) CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)

Example 3 with ResourceNotFoundException

use of com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException in project aws-sdk-android by aws-amplify.

the class ResourceNotFoundExceptionUnmarshaller method unmarshall.

@Override
public AmazonServiceException unmarshall(JsonErrorResponse error) throws Exception {
    ResourceNotFoundException e = (ResourceNotFoundException) super.unmarshall(error);
    e.setErrorCode("ResourceNotFoundException");
    return e;
}
Also used : ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)

Aggregations

ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)3 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)2 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)1 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)1 AuthenticationContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation)1 MultiFactorAuthenticationContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation)1 CognitoInternalErrorException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException)1 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)1 CognitoParameterInvalidException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException)1 SignUpHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler)1 InitiateAuthRequest (com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest)1 InitiateAuthResult (com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthResult)1 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)1 RespondToAuthChallengeRequest (com.amazonaws.services.cognitoidentityprovider.model.RespondToAuthChallengeRequest)1 SignUpRequest (com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest)1 SignUpResult (com.amazonaws.services.cognitoidentityprovider.model.SignUpResult)1 UnexpectedLambdaException (com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException)1 UserNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Test (org.junit.Test)1