Search in sources :

Example 1 with ListUsersRequest

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

the class AWSMobileClientTest method deleteAllUsers.

public static void deleteAllUsers(final String userpoolId) {
    ListUsersResult listUsersResult;
    do {
        ListUsersRequest listUsersRequest = new ListUsersRequest().withUserPoolId(userpoolId).withLimit(60);
        listUsersResult = getUserpoolLL().listUsers(listUsersRequest);
        for (UserType user : listUsersResult.getUsers()) {
            if (USERNAME.equals(user.getUsername()) || "bimin".equals(user.getUsername()) || "customAuthTestUser".equals(user.getUsername())) {
                // This user is saved to test the identity id permanence
                continue;
            }
            boolean retryConfirmSignUp = false;
            do {
                try {
                    Log.d(TAG, "deleteAllUsers: " + user.getUsername());
                    getUserpoolLL().adminDeleteUser(new AdminDeleteUserRequest().withUsername(user.getUsername()).withUserPoolId(userpoolId));
                } catch (UserNotConfirmedException e) {
                    if (!retryConfirmSignUp) {
                        AdminConfirmSignUpRequest adminConfirmSignUpRequest = new AdminConfirmSignUpRequest();
                        adminConfirmSignUpRequest.withUsername(user.getUsername()).withUserPoolId(userpoolId);
                        getUserpoolLL().adminConfirmSignUp(adminConfirmSignUpRequest);
                        retryConfirmSignUp = true;
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e1) {
                            e1.printStackTrace();
                        }
                    } else {
                        retryConfirmSignUp = false;
                    }
                } catch (Exception e) {
                    Log.e(TAG, "deleteAllUsers: Some error trying to delete user", e);
                }
            } while (retryConfirmSignUp);
        }
    } while (listUsersResult.getPaginationToken() != null);
}
Also used : AdminDeleteUserRequest(com.amazonaws.services.cognitoidentityprovider.model.AdminDeleteUserRequest) ListUsersRequest(com.amazonaws.services.cognitoidentityprovider.model.ListUsersRequest) AdminConfirmSignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.AdminConfirmSignUpRequest) UserType(com.amazonaws.services.cognitoidentityprovider.model.UserType) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) UsernameExistsException(com.amazonaws.services.cognitoidentityprovider.model.UsernameExistsException) JSONException(org.json.JSONException) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) ListUsersResult(com.amazonaws.services.cognitoidentityprovider.model.ListUsersResult)

Example 2 with ListUsersRequest

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

the class AWSMobileClientPersistenceTest method deleteAllUsers.

public static void deleteAllUsers(final String userpoolId) {
    ListUsersResult listUsersResult;
    do {
        ListUsersRequest listUsersRequest = new ListUsersRequest().withUserPoolId(userpoolId).withLimit(60);
        listUsersResult = getUserpoolLL().listUsers(listUsersRequest);
        for (UserType user : listUsersResult.getUsers()) {
            if (USERNAME.equals(user.getUsername()) || "bimin".equals(user.getUsername())) {
                // This user is saved to test the identity id permanence
                continue;
            }
            boolean retryConfirmSignUp = false;
            do {
                try {
                    Log.d(TAG, "deleteAllUsers: " + user.getUsername());
                    getUserpoolLL().adminDeleteUser(new AdminDeleteUserRequest().withUsername(user.getUsername()).withUserPoolId(userpoolId));
                } catch (UserNotConfirmedException e) {
                    if (!retryConfirmSignUp) {
                        AdminConfirmSignUpRequest adminConfirmSignUpRequest = new AdminConfirmSignUpRequest();
                        adminConfirmSignUpRequest.withUsername(user.getUsername()).withUserPoolId(userpoolId);
                        getUserpoolLL().adminConfirmSignUp(adminConfirmSignUpRequest);
                        retryConfirmSignUp = true;
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e1) {
                            e1.printStackTrace();
                        }
                    } else {
                        retryConfirmSignUp = false;
                    }
                } catch (Exception e) {
                    Log.e(TAG, "deleteAllUsers: Some error trying to delete user", e);
                }
            } while (retryConfirmSignUp);
        }
    } while (listUsersResult.getPaginationToken() != null);
}
Also used : AdminDeleteUserRequest(com.amazonaws.services.cognitoidentityprovider.model.AdminDeleteUserRequest) ListUsersRequest(com.amazonaws.services.cognitoidentityprovider.model.ListUsersRequest) AdminConfirmSignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.AdminConfirmSignUpRequest) UserType(com.amazonaws.services.cognitoidentityprovider.model.UserType) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) ListUsersResult(com.amazonaws.services.cognitoidentityprovider.model.ListUsersResult)

Example 3 with ListUsersRequest

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

the class AWSMobileClientPersistenceWithRestartabilityTest method deleteAllUsers.

public static void deleteAllUsers(final String userPoolId) {
    ListUsersResult listUsersResult;
    do {
        ListUsersRequest listUsersRequest = new ListUsersRequest().withUserPoolId(userPoolId).withLimit(60);
        listUsersResult = getCognitoUserPoolLowLevelClient().listUsers(listUsersRequest);
        for (UserType user : listUsersResult.getUsers()) {
            if (USERNAME.equals(user.getUsername()) || "bimin".equals(user.getUsername())) {
                // This user is saved to test the identity id permanence
                continue;
            }
            boolean retryConfirmSignUp = false;
            do {
                try {
                    Log.d(TAG, "deleteAllUsers: " + user.getUsername());
                    getCognitoUserPoolLowLevelClient().adminDeleteUser(new AdminDeleteUserRequest().withUsername(user.getUsername()).withUserPoolId(userPoolId));
                } catch (UserNotConfirmedException e) {
                    if (!retryConfirmSignUp) {
                        AdminConfirmSignUpRequest adminConfirmSignUpRequest = new AdminConfirmSignUpRequest();
                        adminConfirmSignUpRequest.withUsername(user.getUsername()).withUserPoolId(userPoolId);
                        getCognitoUserPoolLowLevelClient().adminConfirmSignUp(adminConfirmSignUpRequest);
                        retryConfirmSignUp = true;
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e1) {
                            e1.printStackTrace();
                        }
                    } else {
                        retryConfirmSignUp = false;
                    }
                } catch (Exception e) {
                    Log.e(TAG, "deleteAllUsers: Some error trying to delete user", e);
                }
            } while (retryConfirmSignUp);
        }
    } while (listUsersResult.getPaginationToken() != null);
}
Also used : AdminDeleteUserRequest(com.amazonaws.services.cognitoidentityprovider.model.AdminDeleteUserRequest) ListUsersRequest(com.amazonaws.services.cognitoidentityprovider.model.ListUsersRequest) AdminConfirmSignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.AdminConfirmSignUpRequest) UserType(com.amazonaws.services.cognitoidentityprovider.model.UserType) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) JSONException(org.json.JSONException) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException) ListUsersResult(com.amazonaws.services.cognitoidentityprovider.model.ListUsersResult)

Aggregations

AdminConfirmSignUpRequest (com.amazonaws.services.cognitoidentityprovider.model.AdminConfirmSignUpRequest)3 AdminDeleteUserRequest (com.amazonaws.services.cognitoidentityprovider.model.AdminDeleteUserRequest)3 ListUsersRequest (com.amazonaws.services.cognitoidentityprovider.model.ListUsersRequest)3 ListUsersResult (com.amazonaws.services.cognitoidentityprovider.model.ListUsersResult)3 UserNotConfirmedException (com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException)3 UserType (com.amazonaws.services.cognitoidentityprovider.model.UserType)3 JSONException (org.json.JSONException)2 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)1 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)1 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)1 UsernameExistsException (com.amazonaws.services.cognitoidentityprovider.model.UsernameExistsException)1