use of com.amazonaws.auth.policy.Policy in project glacier-cli by carlossg.
the class Glacier method setupSQS.
// ==============
// Helper methods
// ==============
private QueueConfig setupSQS(String sqsQueueName) {
QueueConfig config = new QueueConfig();
CreateQueueRequest request = new CreateQueueRequest().withQueueName(sqsQueueName);
CreateQueueResult result = sqsClient.createQueue(request);
config.sqsQueueURL = result.getQueueUrl();
GetQueueAttributesRequest qRequest = new GetQueueAttributesRequest().withQueueUrl(config.sqsQueueURL).withAttributeNames("QueueArn");
GetQueueAttributesResult qResult = sqsClient.getQueueAttributes(qRequest);
config.sqsQueueARN = qResult.getAttributes().get("QueueArn");
Policy sqsPolicy = new Policy().withStatements(new Statement(Effect.Allow).withPrincipals(Principal.AllUsers).withActions(SQSActions.SendMessage).withResources(new Resource(config.sqsQueueARN)));
Map<String, String> queueAttributes = new HashMap<String, String>();
queueAttributes.put("Policy", sqsPolicy.toJson());
sqsClient.setQueueAttributes(new SetQueueAttributesRequest(config.sqsQueueURL, queueAttributes));
return config;
}
use of com.amazonaws.auth.policy.Policy in project aws-doc-sdk-examples by awsdocs.
the class SetBucketPolicy method getBucketPolicyFromFile.
// Loads a JSON-formatted policy from a file, verifying it with the Policy
// class.
private static String getBucketPolicyFromFile(String policy_file) {
StringBuilder file_text = new StringBuilder();
try {
List<String> lines = Files.readAllLines(Paths.get(policy_file), Charset.forName("UTF-8"));
for (String line : lines) {
file_text.append(line);
}
} catch (IOException e) {
System.out.format("Problem reading file: \"%s\"", policy_file);
System.out.println(e.getMessage());
}
// Verify the policy by trying to load it into a Policy object.
Policy bucket_policy = null;
try {
bucket_policy = Policy.fromJson(file_text.toString());
} catch (IllegalArgumentException e) {
System.out.format("Invalid policy text in file: \"%s\"", policy_file);
System.out.println(e.getMessage());
}
return bucket_policy.toJson();
}
Aggregations