List of usage examples for com.amazonaws.services.identitymanagement AmazonIdentityManagement listAccessKeys
ListAccessKeysResult listAccessKeys(ListAccessKeysRequest listAccessKeysRequest);
Returns information about the access key IDs associated with the specified IAM user.
From source file:aws.example.iam.ListAccessKeys.java
License:Open Source License
public static void main(String[] args) { final String USAGE = "To run this example, supply an IAM username\n" + "Ex: ListAccessKeys <username>\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1);//from w w w . j a v a 2 s . c om } String username = args[0]; final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient(); boolean done = false; while (!done) { ListAccessKeysRequest request = new ListAccessKeysRequest().withUserName(username); ListAccessKeysResult response = iam.listAccessKeys(request); for (AccessKeyMetadata metadata : response.getAccessKeyMetadata()) { System.out.format("Retrieved access key %s", metadata.getAccessKeyId()); } request.setMarker(response.getMarker()); if (!response.getIsTruncated()) { done = true; } } }
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 w w. j a va 2 s . c om 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); } }