Skip to content

Adding PolicySet parsePoliciesJson method - #365

Merged
mark-creamer-amazon merged 6 commits into
cedar-policy:mainfrom
mark-creamer-amazon:main
Aug 11, 2026
Merged

Adding PolicySet parsePoliciesJson method#365
mark-creamer-amazon merged 6 commits into
cedar-policy:mainfrom
mark-creamer-amazon:main

Conversation

@mark-creamer-amazon

Copy link
Copy Markdown
Contributor

Similar to #165, provides utility functions parsePoliciesJson that parse multiple static policies, policy templates, and policy linked templates in via a EST representation in a JSON string or file.

Unlike the parsePolicies helper, the underlying PolicySet::from_str method can yield template linked policies based on the EST representation via the templateLinks key. So we do resolve template linked policies in this new method, populating templateLinks in the PolicySet POJO

CedarJava

  • Added static PolicySet parsePoliciesJson(Path filePath) and PolicySet parsePoliciesJson(String policiesJsonString) methods to PolicySet.
  • Added tests for these methods to PolicySetTests.java
  • Adding additional test policySet json files in src/test/resources directory to use for testing.
    • CedarJava/src/test/resources/policies.json
    • CedarJava/src/test/resources/template.json

CedarJavaFFI

  • Added JNI method parsePoliciesJsonJni that takes a Java String for policies and templates, uses PolicySet::from_json_str to parse the string into policies and templates and then constructs a Java PolicySet with those parameters.
  • In parse_policies_internal, extracting common code that converts the Rust PolicySet to the Java PolicySet object in new policy_set_to_java helper
  • Creating a new JNI wrapper JLinkValue around the existing LinkValue Java object and JTemplateLink around TemplateLink

Comment thread CedarJavaFFI/src/interface.rs
Comment thread CedarJavaFFI/src/interface.rs Outdated
Comment thread CedarJavaFFI/src/interface.rs Outdated
`policyFormat`/`schemaFormat` support landed in
cedar-policy#366, but `loadPolicySet` still
rejected `policyFormat: json` because there was no Java interface for parsing a
policy set from its JSON (EST) representation. Now that
`PolicySet.parsePoliciesJson` exists, honor the JSON format and add
`tests/example_use_cases/2a_json_policy.json` to the handwritten test list.
Addresses review feedback: `format!("{}", policy.id())` allocates a String just to
recover the id text that `AsRef<str>` already exposes. `PolicyId` also implements
`AsRef<ast::PolicyID>`, so the `let` bindings are annotated `&str` to pick the
intended impl.
The note predates commit b53563e (Aug 2023), which wired up executeJsonValidationTest.
The schema field has been read since then, feeding both the ValidationRequest and
each AuthorizationRequest, and the Java validator interface it waits on exists.
@mark-creamer-amazon
mark-creamer-amazon merged commit 7b65518 into cedar-policy:main Aug 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants