List of usage examples for com.amazonaws.services.identitymanagement.model GetRoleResult getRole
public Role getRole()
A structure containing details about the IAM role.
From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.IamRoleDetail.java
License:Open Source License
private void buildUI(GetRoleResult detail) { this.add(primaryScrollPane, BorderLayout.CENTER); if (detail.getRole() != null) { Role role = detail.getRole(); if (role.getCreateDate() != null) { primaryTableModel.addRow(new Object[] { "Created", getDateString(role.getCreateDate()) }); }/* w w w . jav a2s.c o m*/ if (role.getArn() != null) { primaryTableModel.addRow(new Object[] { "Arn", role.getArn() }); } if (role.getAssumeRolePolicyDocument() != null) { primaryTableModel .addRow(new Object[] { "Assume Role Policy Document", role.getAssumeRolePolicyDocument() }); } if (role.getPath() != null) { primaryTableModel.addRow(new Object[] { "Path", role.getPath() }); } if (role.getRoleId() != null) { primaryTableModel.addRow(new Object[] { "Role Id", role.getRoleId() }); } if (role.getRoleName() != null) { primaryTableModel.addRow(new Object[] { "Role Name", role.getRoleName() }); } } }
From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.CreateServerGroupAtomicOperation.java
License:Apache License
private void checkRoleTrustRelations(String roleName) { updateTaskStatus("Checking role trust relations for: " + roleName); AmazonIdentityManagement iamClient = getAmazonIdentityManagementClient(); GetRoleResult response = iamClient.getRole(new GetRoleRequest().withRoleName(roleName)); Role role = response.getRole(); Set<IamTrustRelationship> trustedEntities = iamPolicyReader .getTrustedEntities(role.getAssumeRolePolicyDocument()); Set<String> trustedServices = trustedEntities.stream() .filter(trustRelation -> trustRelation.getType().equals("Service")) .map(IamTrustRelationship::getValue).collect(Collectors.toSet()); if (!trustedServices.contains(NECESSARY_TRUSTED_SERVICE)) { throw new IllegalArgumentException( "The " + roleName + " role does not have a trust relationship to ecs-tasks.amazonaws.com."); }// w w w . j av a 2 s. co m }
From source file:com.okta.tools.awscli.java
License:Open Source License
private static void GetRoleToAssume(String roleName) { if (roleName != null && !roleName.equals("") && awsIamKey != null && awsIamSecret != null && !awsIamKey.equals("") && !awsIamSecret.equals("")) { logger.debug("Creating the AWS Identity Management client"); AmazonIdentityManagementClient identityManagementClient = new AmazonIdentityManagementClient( new BasicAWSCredentials(awsIamKey, awsIamSecret)); logger.debug("Getting role: " + roleName); GetRoleResult roleresult = identityManagementClient .getRole(new GetRoleRequest().withRoleName(roleName)); logger.debug("GetRoleResult: " + roleresult.toString()); Role role = roleresult.getRole(); logger.debug("getRole: " + role.toString()); ListAttachedRolePoliciesResult arpr = identityManagementClient .listAttachedRolePolicies(new ListAttachedRolePoliciesRequest().withRoleName(roleName)); logger.debug("ListAttachedRolePoliciesResult: " + arpr.toString()); ListRolePoliciesResult lrpr = identityManagementClient .listRolePolicies(new ListRolePoliciesRequest().withRoleName(roleName)); logger.debug("ListRolePoliciesResult: " + lrpr.toString()); List<String> inlinePolicies = lrpr.getPolicyNames(); if (inlinePolicies.size() == 0) { logger.debug("There are no inlines policies"); }//from w w w . ja va 2 s. com List<AttachedPolicy> managedPolicies = arpr.getAttachedPolicies(); if (managedPolicies.size() == 0) { logger.debug("There are no managed policies"); } if (managedPolicies.size() >= 1) //we prioritize managed policies over inline policies { List<String> lstManagedPolicies = new ArrayList<String>(); for (AttachedPolicy managedPolicy : managedPolicies) { lstManagedPolicies.add(managedPolicy.getPolicyName()); } logger.debug("Managed Policies: " + managedPolicies.toString()); //TODO: handle more than 1 policy (ask the user to choose it?) AttachedPolicy attachedPolicy = managedPolicies.get(0); logger.debug("First Attached Policy " + attachedPolicy.toString()); GetPolicyRequest gpr = new GetPolicyRequest().withPolicyArn(attachedPolicy.getPolicyArn()); GetPolicyResult rpr = identityManagementClient.getPolicy(gpr); logger.debug("GetPolicyResult: " + attachedPolicy.toString()); Policy policy = rpr.getPolicy(); GetPolicyVersionResult pvr = identityManagementClient.getPolicyVersion(new GetPolicyVersionRequest() .withPolicyArn(policy.getArn()).withVersionId(policy.getDefaultVersionId())); logger.debug("GetPolicyVersionResult: " + pvr.toString()); String policyDoc = pvr.getPolicyVersion().getDocument(); roleToAssume = ProcessPolicyDocument(policyDoc); } else if (inlinePolicies.size() >= 1) //if we only have one policy, then use it by default { logger.debug("Inline Policies " + inlinePolicies.toString()); if (inlinePolicies.size() > 1) { //there are more than one policy } //Have to set the role name and the policy name (both are mandatory fields //TODO: handle more than 1 policy (ask the user to choose it?) GetRolePolicyRequest grpr = new GetRolePolicyRequest().withRoleName(roleName) .withPolicyName(inlinePolicies.get(0)); GetRolePolicyResult rpr = identityManagementClient.getRolePolicy(grpr); String policyDoc = rpr.getPolicyDocument(); roleToAssume = ProcessPolicyDocument(policyDoc); } } }