Interface IamPolicyReader
- All Known Implementing Classes:
DefaultIamPolicyReader
The
IamPolicyReader converts a JSON policy into an IamPolicy.
Usage Examples
Log the number of statements in a policy downloaded from IAM.// IamClient requires a dependency on software.amazon.awssdk:iam
try (IamClient iam = IamClient.builder().region(Region.AWS_GLOBAL).build()) {
String policyArn = "arn:aws:iam::123456789012:policy/AllowWriteBookMetadata";
GetPolicyResponse getPolicyResponse = iam.getPolicy(r -> r.policyArn(policyArn));
String policyVersion = getPolicyResponse.defaultVersionId();
GetPolicyVersionResponse getPolicyVersionResponse =
iam.getPolicyVersion(r -> r.policyArn(policyArn).versionId(policyVersion));
IamPolicy policy = IamPolicyReader.create().read(getPolicyVersionResponse.policyVersion().document());
System.out.println("Number of statements in the " + policyArn + ": " + policy.statements().size());
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic IamPolicyReadercreate()Create a newIamPolicyReader.read(byte[] policy) Read a policy from abytearray.read(InputStream policy) Read a policy from anInputStream.Read a policy from aString.
-
Method Details
-
create
Create a newIamPolicyReader.This method is inexpensive, allowing the creation of readers wherever they are needed.
-
read
Read a policy from aString.This only performs minimal validation on the provided policy.
- Throws:
RuntimeException- If the provided policy is not valid JSON or is missing a minimal set of required fields.
-
read
Read a policy from anInputStream.The stream must provide a UTF-8 encoded string representing the policy. This only performs minimal validation on the provided policy.
- Throws:
RuntimeException- If the provided policy is not valid JSON or is missing a minimal set of required fields.
-
read
Read a policy from abytearray.The stream must provide a UTF-8 encoded string representing the policy. This only performs minimal validation on the provided policy.
- Throws:
RuntimeException- If the provided policy is not valid JSON or is missing a minimal set of required fields.
-