Example usage for com.amazonaws.services.identitymanagement AmazonIdentityManagementClient listAccessKeys

List of usage examples for com.amazonaws.services.identitymanagement AmazonIdentityManagementClient listAccessKeys

Introduction

In this page you can find the example usage for com.amazonaws.services.identitymanagement AmazonIdentityManagementClient listAccessKeys.

Prototype

@Override
public ListAccessKeysResult listAccessKeys(ListAccessKeysRequest request) 

Source Link

Document

Returns information about the access key IDs associated with the specified IAM user.

Usage

From source file:ch.cyberduck.core.iam.AmazonIdentityConfiguration.java

License:Open Source License

@Override
public void delete(final String username, final LoginCallback prompt) throws BackgroundException {
    if (log.isInfoEnabled()) {
        log.info(String.format("Delete user %s", username));
    }//from  w ww . ja  v  a 2 s  .  c  o m
    this.authenticated(new Authenticated<Void>() {
        @Override
        public Void call() throws BackgroundException {
            PreferencesFactory.get().deleteProperty(String.format("%s%s", prefix, username));
            // Create new IAM credentials
            final AmazonIdentityManagementClient client = new AmazonIdentityManagementClient(
                    new com.amazonaws.auth.AWSCredentials() {
                        @Override
                        public String getAWSAccessKeyId() {
                            return host.getCredentials().getUsername();
                        }

                        @Override
                        public String getAWSSecretKey() {
                            return host.getCredentials().getPassword();
                        }
                    }, configuration);
            try {
                final ListAccessKeysResult keys = client
                        .listAccessKeys(new ListAccessKeysRequest().withUserName(username));

                for (AccessKeyMetadata key : keys.getAccessKeyMetadata()) {
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Delete access key %s for user %s", key, username));
                    }
                    client.deleteAccessKey(new DeleteAccessKeyRequest(username, key.getAccessKeyId()));
                }

                final ListUserPoliciesResult policies = client
                        .listUserPolicies(new ListUserPoliciesRequest(username));
                for (String policy : policies.getPolicyNames()) {
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Delete policy %s for user %s", policy, username));
                    }
                    client.deleteUserPolicy(new DeleteUserPolicyRequest(username, policy));
                }
                client.deleteUser(new DeleteUserRequest(username));
            } catch (NoSuchEntityException e) {
                log.warn(String.format("User %s already removed", username));
            } catch (AmazonClientException e) {
                throw new AmazonServiceExceptionMappingService().map("Cannot write user configuration", e);
            } finally {
                client.shutdown();
            }
            return null;
        }
    }, prompt);
}

From source file:com.denismo.aws.iam.LDAPIAMPoller.java

License:Apache License

private String getUserAccessKey(AmazonIdentityManagementClient client, User user) {
    ListAccessKeysResult res = client
            .listAccessKeys(new ListAccessKeysRequest().withUserName(user.getUserName()));
    for (AccessKeyMetadata meta : res.getAccessKeyMetadata()) {
        if ("Active".equals(meta.getStatus())) {
            return meta.getAccessKeyId();
        }// w w  w  .j  a  v  a  2 s.c  o m
    }
    return null;
}