Package com.amazonaws.auth.policy

Examples of com.amazonaws.auth.policy.Policy


        }

        JsonNode policyNode;
        JsonNode idNode;
        JsonNode statementNodes;
        Policy policy = new Policy();
        List<Statement> statements = new LinkedList<Statement>();

        try {
            policyNode = Jackson.jsonNodeOf(jsonString);

            idNode = policyNode.get(JsonDocumentFields.POLICY_ID);
            if (isNotNull(idNode)) {
                policy.setId(idNode.asText());
            }

            statementNodes = policyNode.get(JsonDocumentFields.STATEMENT);
            if (isNotNull(statementNodes)) {
                for (JsonNode node : statementNodes) {
                    statements.add(statementOf(node));
                }
            }

        } catch (Exception e) {
            String message = "Unable to generate policy object fron JSON string "
                    + e.getMessage();
            throw new IllegalArgumentException(message, e);
        }
        policy.setStatements(statements);
        return policy;
    }
View Full Code Here


        queueUrl = sqs.createQueue(new CreateQueueRequest(queueName)).getQueueUrl();
        topicArn = sns.createTopic(new CreateTopicRequest(topicName)).getTopicArn();
        String queueARN = sqs.getQueueAttributes(new GetQueueAttributesRequest(queueUrl).withAttributeNames("QueueArn")).getAttributes().get("QueueArn");

        Policy sqsPolicy =
            new Policy().withStatements(
                    new Statement(Effect.Allow)
                    .withPrincipals(Principal.AllUsers)
                    .withActions(SQSActions.SendMessage)
                    .withResources(new Resource(queueARN))
                    .withConditions(ConditionFactory.newSourceArnCondition(topicArn)));
        sqs.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, newAttributes("Policy", sqsPolicy.toJson())));

        sns.subscribe(new SubscribeRequest(topicArn, "sqs", queueARN));
    }
View Full Code Here

     
        queueUrl = sqs.createQueue(new CreateQueueRequest(queueName)).getQueueUrl();
        topicArn = sns.createTopic(new CreateTopicRequest(topicName)).getTopicArn();
        String queueARN = sqs.getQueueAttributes(new GetQueueAttributesRequest(queueUrl).withAttributeNames("QueueArn")).getAttributes().get("QueueArn");
       
        Policy sqsPolicy =
            new Policy().withStatements(
                    new Statement(Effect.Allow)
                    .withPrincipals(Principal.AllUsers)
                    .withActions(SQSActions.SendMessage)
                    .withResources(new Resource(queueARN))
                    .withConditions(ConditionFactory.newSourceArnCondition(topicArn)));
        sqs.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, newAttributes("Policy", sqsPolicy.toJson())));
       
        sns.subscribe(new SubscribeRequest(topicArn, "sqs", queueARN));
    }
View Full Code Here

                throws AmazonClientException, AmazonServiceException {
        Map<String, String> queueAttributes = sqs.getQueueAttributes(new GetQueueAttributesRequest(sqsQueueUrl)
                .withAttributeNames(QueueAttributeName.QueueArn.toString())).getAttributes();
        String sqsQueueArn = queueAttributes.get(QueueAttributeName.QueueArn.toString());

        Policy policy = new Policy().withStatements(
                new Statement(Effect.Allow)
                    .withId("topic-subscription-" + snsTopicArn)
                    .withPrincipals(Principal.AllUsers)
                    .withActions(SQSActions.SendMessage)
                    .withResources(new Resource(sqsQueueArn))
                    .withConditions(ConditionFactory.newSourceArnCondition(snsTopicArn)));

        System.out.println("Policy: " + policy.toJson());

        queueAttributes = new HashMap<String, String>();
        queueAttributes.put(QueueAttributeName.Policy.toString(), policy.toJson());
        sqs.setQueueAttributes(new SetQueueAttributesRequest(sqsQueueUrl, queueAttributes));

        SubscribeResult subscribeResult =
                sns.subscribe(new SubscribeRequest()
                    .withEndpoint(sqsQueueArn)
View Full Code Here

        }

        JsonNode policyNode;
        JsonNode idNode;
        JsonNode statementNodes;
        Policy policy = new Policy();
        List<Statement> statements = new LinkedList<Statement>();

        try {
            policyNode = Jackson.jsonNodeOf(jsonString);

            idNode = policyNode.get(JsonDocumentFields.POLICY_ID);
            if (isNotNull(idNode)) {
                policy.setId(idNode.asText());
            }

            statementNodes = policyNode.get(JsonDocumentFields.STATEMENT);
            if (isNotNull(statementNodes)) {
                for (JsonNode node : statementNodes) {
                    statements.add(statementOf(node));
                }
            }

        } catch (Exception e) {
            String message = "Unable to generate policy object fron JSON string "
                    + e.getMessage();
            throw new IllegalArgumentException(message, e);
        }
        policy.setStatements(statements);
        return policy;
    }
View Full Code Here

                throws AmazonClientException, AmazonServiceException {
        Map<String, String> queueAttributes = sqs.getQueueAttributes(new GetQueueAttributesRequest(sqsQueueUrl)
                .withAttributeNames(QueueAttributeName.QueueArn.toString())).getAttributes();
        String sqsQueueArn = queueAttributes.get(QueueAttributeName.QueueArn.toString());

        Policy policy = new Policy().withStatements(
                new Statement(Effect.Allow)
                    .withId("topic-subscription-" + snsTopicArn)
                    .withPrincipals(Principal.AllUsers)
                    .withActions(SQSActions.SendMessage)
                    .withResources(new Resource(sqsQueueArn))
                    .withConditions(ConditionFactory.newSourceArnCondition(snsTopicArn)));

        System.out.println("Policy: " + policy.toJson());

        queueAttributes = new HashMap<String, String>();
        queueAttributes.put(QueueAttributeName.Policy.toString(), policy.toJson());
        sqs.setQueueAttributes(new SetQueueAttributesRequest(sqsQueueUrl, queueAttributes));

        SubscribeResult subscribeResult =
                sns.subscribe(new SubscribeRequest()
                    .withEndpoint(sqsQueueArn)
View Full Code Here

        if (jsonString == null) {
            throw new IllegalArgumentException("JSON string cannot be null");
        }

        Policy policy = new Policy();
        List<Statement> statements = new LinkedList<Statement>();
        try {
            JSONObject jPolicy = new JSONObject(jsonString);

            if (Arrays.asList(JSONObject.getNames(jPolicy)).contains(JsonDocumentFields.POLICY_ID)) {
                policy.setId(jPolicy.getString(JsonDocumentFields.POLICY_ID));
            }

            JSONArray jStatements = jPolicy.getJSONArray(JsonDocumentFields.STATEMENT);

            for (int index = 0 ; index < jStatements.length() ; index++) {
                Statement statement = convertStatement(jStatements.getJSONObject(index));
                if (statement != null) {
                statements.add(statement);
                }
            }
        } catch (Exception e) {
            String message = "Unable to generate policy object fron JSON string " + e.getMessage();
            throw new IllegalArgumentException(message, e);
        }
        policy.setStatements(statements);
        return policy;
    }
View Full Code Here

        queueUrl = sqs.createQueue(new CreateQueueRequest(queueName)).getQueueUrl();
        topicArn = sns.createTopic(new CreateTopicRequest(topicName)).getTopicArn();
        String queueARN = sqs.getQueueAttributes(new GetQueueAttributesRequest(queueUrl).withAttributeNames("QueueArn")).getAttributes().get("QueueArn");

        Policy sqsPolicy =
            new Policy().withStatements(
                    new Statement(Effect.Allow)
                    .withPrincipals(Principal.AllUsers)
                    .withActions(SQSActions.SendMessage)
                    .withResources(new Resource(queueARN))
                    .withConditions(ConditionFactory.newSourceArnCondition(topicArn)));
        sqs.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, newAttributes("Policy", sqsPolicy.toJson())));

        sns.subscribe(new SubscribeRequest(topicArn, "sqs", queueARN));
    }
View Full Code Here

          .withResources(new Resource(queueArn))
          .withConditions(
              new ArnCondition(ArnComparisonType.ArnEquals,
                  ConditionFactory.SOURCE_ARN_CONDITION_KEY,
                  topicArn));
      Policy policy = new Policy();
      policy.setId(publishPolicyKey);
      policy.setStatements(Collections.singletonList(statement));

      SetQueueAttributesRequest request = new SetQueueAttributesRequest();
      request.setQueueUrl(queueUrl);
      String policyJSON = (new JsonPolicyWriter())
          .writePolicyToString(policy);
View Full Code Here

        queueUrl = sqs.createQueue(new CreateQueueRequest(queueName)).getQueueUrl();
        topicArn = sns.createTopic(new CreateTopicRequest(topicName)).getTopicArn();
        String queueARN = sqs.getQueueAttributes(new GetQueueAttributesRequest(queueUrl).withAttributeNames("QueueArn")).getAttributes().get("QueueArn");

        Policy sqsPolicy =
            new Policy().withStatements(
                    new Statement(Effect.Allow)
                    .withPrincipals(Principal.AllUsers)
                    .withActions(SQSActions.SendMessage)
                    .withResources(new Resource(queueARN))
                    .withConditions(ConditionFactory.newSourceArnCondition(topicArn)));
        sqs.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, newAttributes("Policy", sqsPolicy.toJson())));

        sns.subscribe(new SubscribeRequest(topicArn, "sqs", queueARN));
    }
View Full Code Here

TOP

Related Classes of com.amazonaws.auth.policy.Policy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.