com.amazonaws.services.identitymanagement.model.GetRolePolicyResult Java Examples
The following examples show how to use
com.amazonaws.services.identitymanagement.model.GetRolePolicyResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IAMUtils.java From pacbot with Apache License 2.0 | 6 votes |
/** * Gets the inline role policy. * * @param roleName * the role name * @param policyName * the policy name * @param amazonIdentityManagement * the amazon identity management * @return the inline role policy */ private static Policy getInlineRolePolicy(String roleName, String policyName, AmazonIdentityManagement amazonIdentityManagement) { Policy policy = new Policy(); try { GetRolePolicyRequest policyRequest = new GetRolePolicyRequest(); policyRequest.setRoleName(roleName); policyRequest.setPolicyName(policyName); GetRolePolicyResult policyResult = amazonIdentityManagement.getRolePolicy(policyRequest); String policyAsString = policyResult.getPolicyDocument(); policyAsString = java.net.URLDecoder.decode(policyAsString, "UTF-8"); policy = Policy.fromJson(policyAsString); } catch (Exception e) { logger.error(e.getMessage()); } return policy; }
Example #2
Source File: PolicyProviderTest.java From fullstop with Apache License 2.0 | 6 votes |
@Test public void testGetRolePolicies() throws Exception { when(clientMock.listAttachedRolePolicies(any())) .thenReturn(new ListAttachedRolePoliciesResult().withAttachedPolicies( new AttachedPolicy().withPolicyName("bar1"), new AttachedPolicy().withPolicyName("bar2"))); when(clientMock.listRolePolicies(any())) .thenReturn(new ListRolePoliciesResult().withPolicyNames("foo", "bar")); when(clientMock.getRolePolicy(any())) .thenReturn(new GetRolePolicyResult().withPolicyDocument("%7B%22hello%22%3A%22world%22%7D")); final RolePolicies rolePolicies = policyProvider.getRolePolicies("foo", Region.getRegion(US_EAST_1), "123456789012"); assertThat(rolePolicies).isNotNull(); assertThat(rolePolicies.getAttachedPolicyNames()).containsOnly("bar1", "bar2"); assertThat(rolePolicies.getInlinePolicyNames()).containsOnly("foo", "bar"); assertThat(rolePolicies.getMainPolicy()).isEqualTo("{\"hello\":\"world\"}"); verify(clientMock).listAttachedRolePolicies(any()); verify(clientMock).listRolePolicies(any()); verify(clientMock).getRolePolicy(any()); }
Example #3
Source File: PolicyProviderImpl.java From fullstop with Apache License 2.0 | 5 votes |
private String fetchMainPolicy(String roleName, AmazonIdentityManagementClient iamClient) { return Optional.of(new GetRolePolicyRequest().withRoleName(roleName).withPolicyName(roleName)) .map(iamClient::getRolePolicy) .map(GetRolePolicyResult::getPolicyDocument) .map(PolicyProviderImpl::urlDecode) .orElse(EMPTY_JSON); }
Example #4
Source File: IAMUtilsTest.java From pacbot with Apache License 2.0 | 4 votes |
@SuppressWarnings("static-access") @Test public void getActionsByRolePolicyTest() throws Exception { AttachedPolicy attachedPolicies = new AttachedPolicy(); attachedPolicies.setPolicyName("IAMFullAccess"); List<AttachedPolicy> policies = new ArrayList<>(); policies.add(attachedPolicies); PolicyVersion versions = new PolicyVersion(); versions.setIsDefaultVersion(true); versions.setVersionId("123"); versions.setDocument("{\"ag\":\"aws-all\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iam:*\"],\"Resource\":[\"iam:*\"]}],\"from\":0,\"searchtext\":\"\",\"size\":25}"); ListPolicyVersionsResult policyVersions = new ListPolicyVersionsResult(); policyVersions.setVersions(Arrays.asList(versions)); ListAttachedRolePoliciesResult attachedRolePoliciesResult = new ListAttachedRolePoliciesResult(); attachedRolePoliciesResult.setAttachedPolicies(policies); attachedRolePoliciesResult.setIsTruncated(false); ListRolePoliciesResult rolePoliciesResult = new ListRolePoliciesResult(); rolePoliciesResult.setPolicyNames(Arrays.asList("123")); rolePoliciesResult.setIsTruncated(false); GetRolePolicyResult policyResult = new GetRolePolicyResult(); policyResult.setPolicyName("123"); policyResult.setPolicyDocument("{\"ag\":\"aws-all\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iam:*\"],\"Resource\":[\"iam:*\"]}],\"from\":0,\"searchtext\":\"\",\"size\":25}"); policyResult.setRoleName("123"); GetPolicyVersionResult versionResult = new GetPolicyVersionResult(); versionResult.setPolicyVersion(versions); when(iamClient.listAttachedRolePolicies(anyObject())).thenReturn(attachedRolePoliciesResult); when(iamClient.listRolePolicies(anyObject())).thenReturn(rolePoliciesResult); when(iamClient.getRolePolicy(anyObject())).thenReturn(policyResult); when(iamClient.listPolicyVersions(anyObject())).thenReturn(policyVersions); when(iamClient.getPolicyVersion(anyObject())).thenReturn(versionResult); mockStatic(URLDecoder.class); when(URLDecoder.decode(anyString(),anyString())).thenReturn("qeqwehgj"); assertThat(iamUtils.getAllowedActionsByRolePolicy(iamClient,"133"),is(notNullValue())); }
Example #5
Source File: RolePolicyImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public boolean load(GetRolePolicyRequest request, ResultCapture<GetRolePolicyResult> extractor) { return resource.load(request, extractor); }
Example #6
Source File: RolePolicy.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Makes a call to the service to load this resource's attributes if they * are not loaded yet, and use a ResultCapture to retrieve the low-level * client response * The following request parameters will be populated from the data of this * <code>RolePolicy</code> resource, and any conflicting parameter value set * in the request will be overridden: * <ul> * <li> * <b><code>RoleName</code></b> * - mapped from the <code>RoleName</code> identifier. * </li> * <li> * <b><code>PolicyName</code></b> * - mapped from the <code>Name</code> identifier. * </li> * </ul> * * <p> * * @return Returns {@code true} if the resource is not yet loaded when this * method was invoked, which indicates that a service call has been * made to retrieve the attributes. * @see GetRolePolicyRequest */ boolean load(GetRolePolicyRequest request, ResultCapture<GetRolePolicyResult> extractor);