List of usage examples for com.amazonaws.services.identitymanagement AmazonIdentityManagementClient AmazonIdentityManagementClient
AmazonIdentityManagementClient(AwsSyncClientParams clientParams, boolean endpointDiscoveryEnabled)
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 .j a v a2 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:ch.cyberduck.core.iam.AmazonIdentityConfiguration.java
License:Open Source License
@Override public void create(final String username, final String policy, final LoginCallback prompt) throws BackgroundException { if (log.isInfoEnabled()) { log.info(String.format("Create user %s with policy %s", username, policy)); }//from w w w . j av a 2 s . c om this.authenticated(new Authenticated<Void>() { @Override public Void call() throws BackgroundException { // 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 { // Create new IAM credentials User user; try { user = client.createUser(new CreateUserRequest().withUserName(username)).getUser(); } catch (EntityAlreadyExistsException e) { user = client.getUser(new GetUserRequest().withUserName(username)).getUser(); } final CreateAccessKeyResult key = client .createAccessKey(new CreateAccessKeyRequest().withUserName(user.getUserName())); if (log.isDebugEnabled()) { log.debug(String.format("Created access key %s for user %s", key, username)); } // Write policy document to get read access client.putUserPolicy(new PutUserPolicyRequest(user.getUserName(), "Policy", policy)); // Map virtual user name to IAM access key final String id = key.getAccessKey().getAccessKeyId(); if (log.isInfoEnabled()) { log.info(String.format("Map user %s to access key %s", String.format("%s%s", prefix, username), id)); } PreferencesFactory.get().setProperty(String.format("%s%s", prefix, username), id); // Save secret PasswordStoreFactory.get().addPassword(host.getProtocol().getScheme(), host.getPort(), host.getHostname(), id, key.getAccessKey().getSecretAccessKey()); } catch (AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot write user configuration", e); } finally { client.shutdown(); } return null; } }, prompt); }
From source file:com.cloudera.director.aws.AWSProvider.java
License:Apache License
@Override protected ConfigurationValidator getResourceProviderConfigurationValidator( ResourceProviderMetadata resourceProviderMetadata) { ClientConfiguration clientConfiguration = getClientConfiguration(); ConfigurationValidator providerSpecificValidator; if (resourceProviderMetadata.getId().equals(EC2Provider.METADATA.getId())) { AmazonEC2Client client = new AmazonEC2Client(credentialsProvider, clientConfiguration); AmazonIdentityManagementClient identityManagementClient = new AmazonIdentityManagementClient( credentialsProvider, clientConfiguration); AWSKMSClient kmsClient = new AWSKMSClient(credentialsProvider, clientConfiguration); providerSpecificValidator = new EC2ProviderConfigurationValidator(client, identityManagementClient, kmsClient);//from w w w .java2 s . c o m } else if (resourceProviderMetadata.getId().equals(RDSProvider.METADATA.getId())) { AmazonRDSClient client = new AmazonRDSClient(credentialsProvider, clientConfiguration); providerSpecificValidator = new RDSProviderConfigurationValidator(client, rdsEndpoints); } else { throw new IllegalArgumentException("No such provider: " + resourceProviderMetadata.getId()); } return new CompositeConfigurationValidator(METADATA.getProviderConfigurationValidator(), providerSpecificValidator); }
From source file:com.cloudera.director.aws.AWSProvider.java
License:Apache License
/** * Creates an EC2 provider with the specified configuration. * * @param target the configuration/*from w ww . j av a2 s.c om*/ * @return the EC2 provider */ protected EC2Provider createEC2Provider(Configured target) { ClientConfiguration clientConfiguration = getClientConfiguration(); return new EC2Provider(target, ephemeralDeviceMappings, ebsMetadata, virtualizationMappings, awsFilters, awsTimeouts, new AmazonEC2Client(credentialsProvider, clientConfiguration), new AmazonIdentityManagementClient(credentialsProvider, clientConfiguration), new AWSKMSClient(credentialsProvider, clientConfiguration), getLocalizationContext()); }
From source file:com.cloudera.director.aws.AWSProvider.java
License:Apache License
/** * Creates an RDS provider with the specified configuration. * * @param target the configuration/*from ww w .j av a 2 s.c om*/ * @return the RDS provider */ protected RDSProvider createRDSProvider(Configured target) { ClientConfiguration clientConfiguration = getClientConfiguration(); return new RDSProvider(target, rdsEndpoints, rdsEncryptionInstanceClasses, new AmazonRDSClient(credentialsProvider, clientConfiguration), new AmazonIdentityManagementClient(credentialsProvider, clientConfiguration), getLocalizationContext()); }
From source file:de.is24.aws.instancemetadataserver.AwsClientFactory.java
License:Apache License
public AmazonIdentityManagement amazonIdentityManagement() { return new AmazonIdentityManagementClient(credentials, CLIENT_CONFIGURATION); }
From source file:org.cloudfoundry.community.servicebroker.s3.config.BrokerConfiguration.java
License:Apache License
@Bean public AmazonIdentityManagement amazonIdentityManagement() { return new AmazonIdentityManagementClient(awsCredentials(), awsClientConfiguration.toClientConfiguration()); }