Example usage for com.amazonaws.services.identitymanagement.model DeleteUserPolicyRequest DeleteUserPolicyRequest

List of usage examples for com.amazonaws.services.identitymanagement.model DeleteUserPolicyRequest DeleteUserPolicyRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.identitymanagement.model DeleteUserPolicyRequest DeleteUserPolicyRequest.

Prototype

public DeleteUserPolicyRequest() 

Source Link

Document

Default constructor for DeleteUserPolicyRequest object.

Usage

From source file:mail.server.storage.AWSStorageDelete.java

License:GNU General Public License

protected void deleteUser(AmazonIdentityManagement im, String group, String user, String policy, boolean force)
        throws Exception {
    try {/*from  w ww .  jav a 2 s  .c  o m*/
        log.debug("deleting user policy", user, policy);
        im.deleteUserPolicy(new DeleteUserPolicyRequest().withUserName(user).withPolicyName(policy));
    } catch (Exception e) {
        if (!force)
            throw e;

        log.exception(e);
    }

    try {
        log.debug("deleting access keys", user);
        ListAccessKeysResult accessKeys = im.listAccessKeys(new ListAccessKeysRequest().withUserName(user));
        for (AccessKeyMetadata i : accessKeys.getAccessKeyMetadata()) {
            log.debug("deleting access key", user, i.getAccessKeyId());
            im.deleteAccessKey(
                    new DeleteAccessKeyRequest().withUserName(user).withAccessKeyId(i.getAccessKeyId()));
        }
    } catch (Exception e) {
        if (!force)
            throw e;

        log.exception(e);
    }

    try {
        log.debug("removing user from group", group, user);
        im.removeUserFromGroup(new RemoveUserFromGroupRequest().withGroupName(group).withUserName(user));
    } catch (Exception e) {
        if (!force)
            throw e;

        log.exception(e);
    }

    try {
        log.debug("deleting user", user);
        im.deleteUser(new DeleteUserRequest().withUserName(user));
    } catch (Exception e) {
        if (!force)
            throw e;

        log.exception(e);
    }
}