Skip to content

Comments

Exposes policy effect for static policies and templates#275

Merged
shaobo-he-aws merged 5 commits intocedar-policy:mainfrom
muditchaudhary:main
Jan 10, 2025
Merged

Exposes policy effect for static policies and templates#275
shaobo-he-aws merged 5 commits intocedar-policy:mainfrom
muditchaudhary:main

Conversation

@muditchaudhary
Copy link
Contributor

Description of Changes

This PR adds functionality to expose the effect of Cedar policies, aligning with the capabilities available in Cedar Rust's Policy and Template implementations.

Changes

  • Implements effect() method to determine if a policy is a "permit" or "forbid" policy
  • Exposes effect for both static policies and templates
  • Adds unit tests

Implementation Note

Cedar Java currently uses a unified Policy class for both static policies and templates, unlike Cedar Rust which separates these concerns into distinct Policy and Template structs. To maintain compatibility while exposing this functionality:

  1. The effect() method first attempts to parse the input as a static policy and gets the effect
  2. If getting the effect as static policy fails, it attempts to parse as a template
  3. Returns the appropriate effect based on the successful parse

Future Considerations

Refactor Cedar Java to mirror Cedar Rust's separation of Policy and Template into distinct classes, allowing for better handling of each policy type.

Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
@shaobo-he-aws shaobo-he-aws merged commit 94ef885 into cedar-policy:main Jan 10, 2025
4 checks passed
muditchaudhary added a commit to muditchaudhary/cedar-java that referenced this pull request Jan 13, 2025
muditchaudhary added a commit to muditchaudhary/cedar-java that referenced this pull request Jan 13, 2025
shaobo-he-aws pushed a commit that referenced this pull request Jan 14, 2025
…275) (#277)

Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
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.

5 participants