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);
}
});
}
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);
}
}
};
}
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;
}
Aggregations