List of usage examples for com.amazonaws.services.identitymanagement AmazonIdentityManagement deleteUserPolicy
DeleteUserPolicyResult deleteUserPolicy(DeleteUserPolicyRequest deleteUserPolicyRequest);
Deletes the specified inline policy that is embedded in the specified IAM user.
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 {/* w ww . j a v a2 s .co 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); } }