cedar-policy / cedar-java

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

Support for Policy from_json in CedarJava #222

Closed n-smir closed 3 weeks ago

n-smir commented 4 weeks ago

Category

User level API features/changes

Describe the feature you'd like to request

Currently there's Policy::from_json method available for Rust, but is not exposed to CedarJava bindings.

I'd like to be able to create Cedar policy object in Java from JSON representation of the policy.

Ideally having constructors/builders as suggested by cedar-policy/cedar#366 would be great but to my understanding that is not yet available even in Rust version.

Describe alternatives you've considered

Considered using Cedar text policy representations, but this presents challenges with serializing/de-serializing Java objects, effectively requiring to write a custom Cedar parser. JSON representation would easily converted to and from Java objects.

Additional context

No response

Is this something that you'd be interested in working on?

cdisselkoen commented 3 weeks ago

Ideally having constructors/builders as suggested by cedar-policy/cedar#366 would be great but to my understanding that is not yet available even in Rust version.

This could be done in the Java interface independently of whether it exists in the Rust public API. (The cedar-java package doesn't use the main Rust public API anyways, it uses the interface in the ffi module of the Rust.) Essentially it would be constructors/builders for the Java Policy object, that under-the-hood assemble a JSON policy object that could be sent across the FFI.

n-smir commented 3 weeks ago

Understood, thanks. Seems like it would make more sense to have a separate feature request for constructors/builders approach in Java, and focus this one on Policy.fromJson implementation, since it seems to be a quick thing to add.

shaobo-he-aws commented 3 weeks ago

Implemented via #223. Thank you, @n-smir.