use of com.amazonaws.auth.policy.Action in project conductor by Netflix.
the class SQSObservableQueue method getPolicy.
private String getPolicy(List<String> accountIds) {
Policy policy = new Policy("AuthorizedWorkerAccessPolicy");
Statement stmt = new Statement(Effect.Allow);
Action action = SQSActions.SendMessage;
stmt.getActions().add(action);
stmt.setResources(new LinkedList<>());
for (String accountId : accountIds) {
Principal principal = new Principal(accountId);
stmt.getPrincipals().add(principal);
}
stmt.getResources().add(new Resource(getQueueARN()));
policy.getStatements().add(stmt);
return policy.toJson();
}
use of com.amazonaws.auth.policy.Action in project aws-sdk-android by aws-amplify.
the class JsonPolicyWriter method jsonStringOf.
/**
* Converts the given <code>Policy</code> into a JSON String.
*
* @param policy the policy to be converted.
* @return a JSON String of the specified policy object.
*/
private String jsonStringOf(Policy policy) throws IOException {
jsonWriter.beginObject();
writeJsonKeyValue(JsonDocumentFields.VERSION, policy.getVersion());
if (isNotNull(policy.getId()))
writeJsonKeyValue(JsonDocumentFields.POLICY_ID, policy.getId());
writeJsonArrayStart(JsonDocumentFields.STATEMENT);
for (Statement statement : policy.getStatements()) {
jsonWriter.beginObject();
if (isNotNull(statement.getId())) {
writeJsonKeyValue(JsonDocumentFields.STATEMENT_ID, statement.getId());
}
writeJsonKeyValue(JsonDocumentFields.STATEMENT_EFFECT, statement.getEffect().toString());
List<Principal> principals = statement.getPrincipals();
if (isNotNull(principals) && !principals.isEmpty())
writePrincipals(principals);
List<Action> actions = statement.getActions();
if (isNotNull(actions) && !actions.isEmpty())
writeActions(actions);
List<Resource> resources = statement.getResources();
if (isNotNull(resources) && !resources.isEmpty())
writeResources(resources);
List<Condition> conditions = statement.getConditions();
if (isNotNull(conditions) && !conditions.isEmpty())
writeConditions(conditions);
jsonWriter.endObject();
}
writeJsonArrayEnd();
jsonWriter.endObject();
jsonWriter.flush();
return writer.toString();
}
use of com.amazonaws.auth.policy.Action in project cloudbreak by hortonworks.
the class AwsCredentialVerifier method getRequiredActions.
private List<RequiredAction> getRequiredActions(String policies) throws IOException {
List<RequiredAction> requiredActions = new ArrayList<>();
Policy policy = new JsonPolicyReader().createPolicyFromJsonString(policies);
for (Statement statement : policy.getStatements()) {
RequiredAction requiredAction = new RequiredAction();
List<Action> actions = statement.getActions();
if (actions != null) {
List<String> actionNames = actions.stream().map(e -> e.getActionName()).collect(Collectors.toList());
requiredAction.setActionNames(actionNames);
}
List<Condition> conditions = statement.getConditions();
if (conditions != null) {
for (Condition condition : conditions) {
ContextEntry contextEntry = new ContextEntry();
contextEntry.setContextKeyName(condition.getConditionKey());
contextEntry.setContextKeyType(ContextKeyTypeEnum.String);
contextEntry.setContextKeyValues(condition.getValues());
requiredAction.getConditions().add(contextEntry);
}
}
String resourceString = statement.getResources().stream().findFirst().get().getId();
requiredAction.setResourceArn(resourceString);
Optional<RequiredAction> first = requiredActions.stream().filter(e -> e.getConditions().equals(requiredAction.getConditions()) && e.getResourceArn().equals(requiredAction.getResourceArn())).findFirst();
if (first.isPresent()) {
requiredActions.remove(first.get());
requiredAction.getActionNames().addAll(first.get().getActionNames());
requiredAction.getConditions().addAll(first.get().getConditions());
requiredActions.add(requiredAction);
} else {
requiredActions.add(requiredAction);
}
}
return requiredActions;
}
use of com.amazonaws.auth.policy.Action in project aws-sdk-android by aws-amplify.
the class JsonPolicyWriter method writeActions.
/**
* Writes the list of <code>Action</code>s to the JSONGenerator.
*
* @param actions the list of the actions to be written.
*/
private void writeActions(List<Action> actions) throws IOException {
List<String> actionStrings = new ArrayList<String>();
for (Action action : actions) {
actionStrings.add(action.getActionName());
}
writeJsonArray(JsonDocumentFields.ACTION, actionStrings);
}
use of com.amazonaws.auth.policy.Action in project cerberus by Nike-Inc.
the class KmsPolicyServiceTest method test_that_overwriteCMSPolicy_returns_policy_that_includes_missing_actions.
@Test
public void test_that_overwriteCMSPolicy_returns_policy_that_includes_missing_actions() throws IOException {
InputStream policy = getClass().getClassLoader().getResourceAsStream("com/nike/cerberus/service/invalid-cerberus-kms-key-policy-cms-cannot-delete.json");
String policyJsonAsString = IOUtils.toString(policy, "UTF-8");
Action actionNotIncludedInInvalidJson1 = KMSActions.ScheduleKeyDeletion;
Action actionNotIncludedInInvalidJson2 = KMSActions.CancelKeyDeletion;
String result = kmsPolicyService.overwriteCMSPolicy(policyJsonAsString);
assertFalse(StringUtils.equals(policyJsonAsString, result));
assertTrue(StringUtils.contains(result, actionNotIncludedInInvalidJson1.getActionName()));
assertTrue(StringUtils.contains(result, actionNotIncludedInInvalidJson2.getActionName()));
assertTrue(kmsPolicyService.cmsHasKeyDeletePermissions(result));
policy.close();
}
Aggregations