cedar-policy / cedar-java

Java bindings for the Cedar language
https://www.cedarpolicy.com
Apache License 2.0
42 stars 19 forks source link

Adding toJson JNI method for Policy object #187

Closed mark-creamer-amazon closed 2 months ago

mark-creamer-amazon commented 2 months ago

https://github.com/cedar-policy/cedar-java/issues/171

Backporting changes from https://github.com/cedar-policy/cedar-java/pull/172

Tested these changes locally with the tip of cedar-java-hello-world 3.2.x

// permit(principal == User::"Alice", action == Action::"View_Photo", resource in Album::"Vacation");
Set<Policy> policySet = buildPolicySlice();
Policy policy = policySet.iterator().next();
System.out.println(policy.toJson());

{"effect":"permit","principal":{"op":"==","entity":{"type":"User","id":"Alice"}},"action":{"op":"==","entity":{"type":"Action","id":"View_Photo"}},"resource":{"op":"in","entity":{"type":"Album","id":"Vacation"}},"conditions":[]}