Example usage for com.amazonaws.auth.policy Action Action

List of usage examples for com.amazonaws.auth.policy Action Action

Introduction

In this page you can find the example usage for com.amazonaws.auth.policy Action Action.

Prototype

Action

Source Link

Usage

From source file:com.clicktravel.infrastructure.messaging.aws.sns.DefaultSnsTopicResourceFactory.java

License:Apache License

private Policy allowAllQueuesPolicy(final SnsTopicResource snsTopicResource) {
    final String topicArn = snsTopicResource.getTopicArn();
    final String[] topicArnParts = topicArn.split(":");
    final String sourceOwner = topicArnParts[topicArnParts.length - 2];
    final Condition condition = new Condition().withType("StringEquals").withConditionKey("AWS:SourceOwner")
            .withValues(sourceOwner);//from w ww. jav a 2s .c  o m
    final Action receiveAction = new Action() {
        @Override
        public String getActionName() {
            return "sns:Receive";
        }
    };
    final Statement recieveStatement = new Statement(Effect.Allow).withPrincipals(Principal.AllUsers)
            .withActions(receiveAction).withResources(new Resource(topicArn)).withConditions(condition);
    final Statement subscribeStatement = new Statement(Effect.Allow).withPrincipals(Principal.AllUsers)
            .withActions(SNSActions.Subscribe);
    return new Policy().withStatements(recieveStatement, subscribeStatement);
}