com.amazonaws.services.kms.model.PutKeyPolicyRequest Java Examples

The following examples show how to use com.amazonaws.services.kms.model.PutKeyPolicyRequest. 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: SetKeyPolicy.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    AWSKMS kmsClient = AWSKMSClientBuilder.standard().build();
    // Set a key policy for a CMK
    //
    // Replace the following fictitious CMK ARN with a valid CMK ID or ARN
    String keyId = "1234abcd-12ab-34cd-56ef-1234567890ab";
    String policyName = "default";
    String policy = "{" +
            "  \"Version\": \"2012-10-17\"," +
            "  \"Statement\": [{" +
            "    \"Sid\": \"Allow access for ExampleUser\"," +
            "    \"Effect\": \"Allow\"," +
            // Replace the following user ARN with one for a real user.
            "    \"Principal\": {\"AWS\": \"arn:aws:iam::111122223333:user/ExampleUser\"}," +
            "    \"Action\": [" +
            "      \"kms:Encrypt\"," +
            "      \"kms:GenerateDataKey*\"," +
            "      \"kms:Decrypt\"," +
            "      \"kms:DescribeKey\"," +
            "      \"kms:ReEncrypt*\"" +
            "    ]," +
            "    \"Resource\": \"*\"" +
            "  }]" +
            "}";

    PutKeyPolicyRequest req = new PutKeyPolicyRequest().withKeyId(keyId).withPolicy(policy).withPolicyName(policyName);
    kmsClient.putKeyPolicy(req);

}
 
Example #2
Source File: MockKMSClient.java    From aws-encryption-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public PutKeyPolicyResult putKeyPolicy(PutKeyPolicyRequest arg0) throws AmazonServiceException, AmazonClientException {
    throw new java.lang.UnsupportedOperationException();
}