Java Code Examples for com.amazonaws.auth.policy.Policy#fromJson()

The following examples show how to use com.amazonaws.auth.policy.Policy#fromJson() . 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 7 votes vote down vote up
/**
 * Gets the inline user policy.
 *
 * @param userName
 *            the user name
 * @param policyName
 *            the policy name
 * @param amazonIdentityManagement
 *            the amazon identity management
 * @return the inline user policy
 */
private static Policy getInlineUserPolicy(String userName, String policyName,
		AmazonIdentityManagement amazonIdentityManagement) {
	Policy policy = new Policy();
	try {
		GetUserPolicyRequest policyRequest = new GetUserPolicyRequest();
		policyRequest.setUserName(userName);
		policyRequest.setPolicyName(policyName);
		GetUserPolicyResult policyResult = amazonIdentityManagement.getUserPolicy(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: IAMUtils.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: AwsIamService.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the role assume role policy document as a Policy object
 *
 * @param role Role to evaluate
 * @return assume role Policy object
 */
public Policy getAssumeRolePolicy(Role role) {
    Policy policy = null;
    String assumeRolePolicyDocument = role.getAssumeRolePolicyDocument();
    if (assumeRolePolicyDocument != null) {
        try {
            String decodedAssumeRolePolicyDocument = URLDecoder.decode(assumeRolePolicyDocument,
                    StandardCharsets.UTF_8);
            policy = Policy.fromJson(decodedAssumeRolePolicyDocument);
        } catch (IllegalArgumentException e) {
            LOGGER.error(String.format("Unable to get policy from role (%s)", role.getArn()), e);
        }
    }

    return policy;
}
 
Example 4
Source File: AwsIamService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a Policy object that has replacements made to the template json
 *
 * @param policyFileName Policy template file name
 * @param replacements   map of simple replacements to make to policy template json
 * @return Policy with replacements made
 */
public Policy getPolicy(String policyFileName, Map<String, String> replacements) {
    Policy policy = null;
    try {
        String policyJsonTemplate = getResourceFileAsString(POLICY_BASE_LOCATION + policyFileName);
        String policyJson = handleTemplateReplacements(policyJsonTemplate, replacements);
        if (policyJson != null) {
            policy = Policy.fromJson(policyJson);
        }
    } catch (IOException e) {
        LOGGER.debug("Unable to load policy json", e);
    }

    return policy;
}