{"id":23773851,"url":"https://github.com/StyraOSS/opa-java-wasm","last_synced_at":"2025-09-05T18:31:26.712Z","repository":{"id":251220394,"uuid":"835901199","full_name":"StyraOSS/opa-java-wasm","owner":"StyraOSS","description":"OPA Wasm rules using Chicory as the runtime (experimental)","archived":false,"fork":false,"pushed_at":"2025-08-25T11:56:23.000Z","size":408,"stargazers_count":21,"open_issues_count":2,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-25T13:31:46.072Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StyraOSS.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-30T18:46:39.000Z","updated_at":"2025-08-25T11:56:27.000Z","dependencies_parsed_at":"2025-02-15T00:31:35.728Z","dependency_job_id":"acd50bf1-3026-4921-bb35-dc3ca9238336","html_url":"https://github.com/StyraOSS/opa-java-wasm","commit_stats":null,"previous_names":["andreatp/opa-chicory","styrainc/opa-java-wasm","styraoss/opa-java-wasm"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/StyraOSS/opa-java-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StyraOSS%2Fopa-java-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StyraOSS%2Fopa-java-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StyraOSS%2Fopa-java-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StyraOSS%2Fopa-java-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StyraOSS","download_url":"https://codeload.github.com/StyraOSS/opa-java-wasm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StyraOSS%2Fopa-java-wasm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273799052,"owners_count":25170305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-01T05:45:57.334Z","updated_at":"2025-09-05T18:31:26.696Z","avatar_url":"https://github.com/StyraOSS.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI](https://github.com/StyraInc/opa-java-wasm/workflows/CI/badge.svg)](https://github.com/StyraInc/opa-java-wasm)\n[![GitHub Release](https://img.shields.io/github/tag/StyraInc/opa-java-wasm.svg?style=flat\u0026color=green)](https://github.com/StyraInc/opa-java-wasm/tags)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.styra.opa/opa-java-wasm/badge.svg?style=flat\u0026color=green)](https://central.sonatype.com/artifact/com.styra.opa/opa-java-wasm)\n\n# Open Policy Agent WebAssembly Java SDK\n\nThis is an SDK for using WebAssembly(wasm) compiled [Open Policy Agent](https://www.openpolicyagent.org/) policies\nwith Java powered by [Chicory](https://github.com/dylibso/chicory), a pure Java Wasm interpreter.\n\nInitial implementation was based\non [Open Policy Agent WebAssembly NPM Module](https://github.com/open-policy-agent/npm-opa-wasm)\nand [Open Policy Agent WebAssembly dotnet core SDK](https://github.com/me-viper/OpaDotNet)\n\n## Why\n\nWe want **fast**, **in-process** and **secure** OPA policies evaluation, and avoid network bottlenecks when using [opa-java](https://github.com/StyraInc/opa-java).\n\nUsing this integration for policy evaluation you can switch from the traditional integration pattern:\n\n\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003cimg width=\"50%\" src=\"imgs/traditional.png\"\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\nto a fully embedded:\n\n\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003cimg width=\"50%\" src=\"imgs/with-wasm.png\"\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n# Getting Started\n\n## Install the module\n\nWith Maven add the core module dependency:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.styra.opa\u003c/groupId\u003e\n    \u003cartifactId\u003eopa-java-wasm\u003c/artifactId\u003e\n    \u003cversion\u003elatest_release\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n\u003c!--\n```java\n//DEPS com.styra.opa:opa-java-wasm:999-SNAPSHOT\n\nvar policyPath = Path.of(\"core/src/main/resources/demo-policy.wasm\");\nvar targetPath = Path.of(\"policy.wasm\");\nFiles.copy(policyPath, targetPath, StandardCopyOption.REPLACE_EXISTING);\n\nvar policyWasm = new File(\"policy.wasm\");\n```\n--\u003e\n\n## Usage\n\nThere are only a couple of steps required to start evaluating the policy.\n\n### Import the module\n\n```java\nimport com.styra.opa.wasm.OpaPolicy;\n```\n\n### Load the policy\n\n```java\nvar policy = OpaPolicy.builder().withPolicy(policyWasm).build();\n```\n\nThe `policyWasm` can be a variety of things, including raw byte array, `InputStream`, `Path`, `File`.\nThe content should be the compiled policy Wasm file, a valid WebAssembly module.\n\nFor example:\n\n```java\nvar policy = OpaPolicy.builder().withPolicy(new File(\"policy.wasm\")).build();\n```\n\n### Evaluate the Policy\n\nThe `OpaPolicy` object returned from `loadPolicy()` has a couple of important\nAPIs for policy evaluation:\n\n`data(data)` -- Provide an external `data` document for policy evaluation.\n\n- `data` MUST be a `String`, which assumed to be a well-formed stringified JSON\n\n`evaluate(input)` -- Evaluates the policy using any loaded data and the supplied\n`input` document.\n\n- `input` parameter MUST be a `String` serialized `object`, `array` or primitive literal which assumed to be a well-formed stringified JSON\n\nExample:\n\n```java\nvar input = \"{\\\"path\\\": \\\"/\\\", \\\"role\\\": \\\"admin\\\"}\";\n\nvar policy = OpaPolicy.builder().withPolicy(policyWasm).build();\nvar result = policy.evaluate(input);\nSystem.out.println(\"Result is: \" + result);\n```\n\n\u003c!--\n```java\nFiles.write(Paths.get(\"TestReadme.result\"), (result + \"\\n\").getBytes());\n```\n--\u003e\n\n\u003e For any `opa build` created WASM binaries the result set, when defined, will\n\u003e contain a `result` key with the value of the compiled entrypoint. See\n\u003e [https://www.openpolicyagent.org/docs/latest/wasm/](https://www.openpolicyagent.org/docs/latest/wasm/)\n\u003e for more details.\n\n## Builtins support:\n\nAt the moment the following builtins are supported(and, by default, automatically injected when needed):\n\n- String\n  - `sprintf` **NOTE:** this implementation is [SDK-dependent](https://www.openpolicyagent.org/docs/latest/policy-reference/#builtin-strings-sprintf) and might generate different results depending on the runtime, please, limit the usage to trivial use-cases.\n\n- Json\n  - `json.is_valid`\n\n- Yaml\n  - `yaml.is_valid`\n  - `yaml.marshal`\n  - `yaml.unmarshal`\n\n### Writing the policy\n\nSee\n[https://www.openpolicyagent.org/docs/latest/how-do-i-write-policies/](https://www.openpolicyagent.org/docs/latest/how-do-i-write-policies/)\n\n### Compiling the policy\n\nEither use the\n[Compile REST API](https://www.openpolicyagent.org/docs/latest/rest-api/#compile-api)\nor `opa build` CLI tool.\n\nFor example:\n\n```bash\nopa build -t wasm -e example/allow example.rego\n```\n\nWhich is compiling the `example.rego` policy file with the result set to\n`data.example.allow`. The result will be an OPA bundle with the `policy.wasm`\nbinary included. See [./examples](./examples) for a more comprehensive example.\n\nSee `opa build --help` for more details.\n\n## Support\n\nThis SDK is community supported and maintained and is not under the umbrella of SDKs eligible for Enterprise support from Styra. For bug reports and feature requests, please use Github issues. For real-time support, please join the Open Policy Agent or Styra Community slack organizations.\n\n## Development\n\nTo develop this library you need to have installed the following tools:\n\n- Java 11+\n- Maven\n- the `opa` cli\n- `tar`\n\nthe typical command to build and run the tests is:\n\n```bash\nmvn spotless:apply clean install\n```\n\nto disable the tests based on the Opa testsuite:\n\n```bash\nOPA_TESTSUITE=disabled mvn spotless:apply install\n```\n\n## Releases\n\nThe versions in `core/pom.xml` are updated as part of the release process.\nNew releases are manually triggered by running the\n[release workflow](https://github.com/StyraInc/opa-java-wasm/blob/main/.github/workflows/release.yaml).\n\nThis workflow requires a number of secrets to be set, while `OSSRH_PASSWORD` and\nusername should not need to be rotated, `JAVA_GPG_SECRET_KEY` should be updated\nif the key has expired and has been removed from the\n[keyserver](https://keyserver.ubuntu.com). This secret is **not** base64\nencoded.\n\nAn example error from a release run where they key has expired, note that this\nis not the final error about `Remote staging failed: Staging rules failure!`.\n\n```\nNo public key: Key with id: (78fe9b032725616c) was not able to be located on \u0026lt;a href=http://keyserver.ubuntu.com:11371/\u0026gt;http://keyserver.ubuntu.com:11371/\u0026lt;/a\u0026gt;. Upload your public key and try the operation again.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStyraOSS%2Fopa-java-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FStyraOSS%2Fopa-java-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStyraOSS%2Fopa-java-wasm/lists"}