Example usage for com.amazonaws.auth.policy.actions SNSActions Subscribe

List of usage examples for com.amazonaws.auth.policy.actions SNSActions Subscribe

Introduction

In this page you can find the example usage for com.amazonaws.auth.policy.actions SNSActions Subscribe.

Prototype

SNSActions Subscribe

To view the source code for com.amazonaws.auth.policy.actions SNSActions Subscribe.

Click Source Link

Document

Action for the Subscribe operation.

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);/* w w w  . j  a  v a2s.  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);
}