use of com.amazonaws.services.identitymanagement.AmazonIdentityManagement in project cloudbreak by hortonworks.
the class AwsSetup method validateInstanceProfileCreation.
private void validateInstanceProfileCreation(AwsCredentialView awsCredentialView) {
GetRoleRequest roleRequest = new GetRoleRequest();
String roleName = awsCredentialView.getRoleArn().split("/")[1];
LOGGER.info("Start validate {} role for S3 access.", roleName);
roleRequest.withRoleName(roleName);
AmazonIdentityManagement client = awsClient.createAmazonIdentityManagement(awsCredentialView);
try {
ListRolePoliciesRequest listRolePoliciesRequest = new ListRolePoliciesRequest();
listRolePoliciesRequest.setRoleName(roleName);
ListRolePoliciesResult listRolePoliciesResult = client.listRolePolicies(listRolePoliciesRequest);
for (String s : listRolePoliciesResult.getPolicyNames()) {
if (checkIamOrS3Statement(roleName, client, s)) {
LOGGER.info("Validation successful for s3 or iam access.");
return;
}
}
ListAttachedRolePoliciesRequest listAttachedRolePoliciesRequest = new ListAttachedRolePoliciesRequest();
listAttachedRolePoliciesRequest.setRoleName(roleName);
ListAttachedRolePoliciesResult listAttachedRolePoliciesResult = client.listAttachedRolePolicies(listAttachedRolePoliciesRequest);
for (AttachedPolicy attachedPolicy : listAttachedRolePoliciesResult.getAttachedPolicies()) {
if (checkIamOrS3Access(client, attachedPolicy)) {
LOGGER.info("Validation successful for s3 or iam access.");
return;
}
}
} catch (AmazonServiceException ase) {
if (ase.getStatusCode() == UNAUTHORIZED) {
String policyMEssage = "Could not get policies on the role because the arn role do not have enough permission: %s";
LOGGER.info(String.format(policyMEssage, ase.getErrorMessage()));
throw new CloudConnectorException(String.format(policyMEssage, ase.getErrorMessage()));
} else {
LOGGER.info(ase.getMessage());
throw new CloudConnectorException(ase.getErrorMessage());
}
} catch (Exception e) {
LOGGER.info(e.getMessage());
throw new CloudConnectorException(e.getMessage());
}
LOGGER.info("Could not get policies on the role because the arn role do not have enough permission.");
throw new CloudConnectorException("Could not get policies on the role because the arn role do not have enough permission.");
}
use of com.amazonaws.services.identitymanagement.AmazonIdentityManagement in project aws-doc-sdk-examples by awsdocs.
the class UpdateUser method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply the current username and a new\n" + "username. Ex:\n\n" + "UpdateUser <current-name> <new-name>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String cur_name = args[0];
String new_name = args[1];
final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient();
UpdateUserRequest request = new UpdateUserRequest().withUserName(cur_name).withNewUserName(new_name);
UpdateUserResult response = iam.updateUser(request);
System.out.printf("Successfully updated user to username %s", new_name);
}
use of com.amazonaws.services.identitymanagement.AmazonIdentityManagement in project aws-doc-sdk-examples by awsdocs.
the class GetPolicy method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply a policy arn\n" + "Ex: GetPolicy <policy-arn>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String policy_arn = args[0];
final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient();
GetPolicyRequest request = new GetPolicyRequest().withPolicyArn(policy_arn);
GetPolicyResult response = iam.getPolicy(request);
System.out.format("Successfully retrieved policy %s", response.getPolicy().getPolicyName());
}
use of com.amazonaws.services.identitymanagement.AmazonIdentityManagement in project aws-doc-sdk-examples by awsdocs.
the class GetServerCertificate method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply a certificate name\n" + "Ex: GetServerCertificate <certificate-name>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String cert_name = args[0];
final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient();
GetServerCertificateRequest request = new GetServerCertificateRequest().withServerCertificateName(cert_name);
GetServerCertificateResult response = iam.getServerCertificate(request);
System.out.format("Successfully retrieved certificate with body %s", response.getServerCertificate().getCertificateBody());
}
use of com.amazonaws.services.identitymanagement.AmazonIdentityManagement in project aws-doc-sdk-examples by awsdocs.
the class ListAccessKeys method main.
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);
}
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;
}
}
}
Aggregations