diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a4d7de..a787c83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +The first Java SDK release carrying these entries sends the PEP capability handshake, which a +platform reads from v10.4.0, and reaches /api/v1/typed-policies, which needs a v11.0.0 platform; +against an older platform it works unchanged. Upgrade the SDK before the platform: from v11.0.0, +Decide under an organization's redact override refuses a caller that does not declare redaction, +and only a release that sends the handshake can declare it. + ### Added - **v11.0.0 decision provenance on every governed response (axonflow-enterprise#3746).** @@ -31,7 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 reported once, as its template (`GET /api/v1/static-policies/{id}`), not once per id. From v11.0.0 the legacy policy routes carry it: the static- and dynamic-policy routes and the policy simulation routes. -- **The v11.0.0 PEP capability handshake (axonflow-enterprise#3746).** An enforcement point +- **The PEP capability handshake, which a platform reads from v10.4.0 + (axonflow-enterprise#3746).** An enforcement point declares the obligation types and schema versions it can discharge with `PEPHandshake.of(...)` and `PEPCapability.of(...)`, presented as `X-Axonflow-PEP-Handshake` on every call to a plane that reads it: `decide` (and `decideAndFulfill` and `fulfillRequest`'s engine round-trip), @@ -50,6 +57,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `Retry-After`; `active()` is empty when nothing is active. A client derived with `asUser` has its own namespace. Rolling back and withdrawing are customer portal operations the agent does not proxy, so the SDK has no method for either. +- **Two runnable examples for the v11 platform (axonflow-enterprise#3746).** `examples/pep-handshake` declares an enforcement + point's capabilities and decides with them, printing each verdict and its reasons; + `examples/typed-policies` reads what the deployment may author, validates a document and, with + `AXONFLOW_TYPED_POLICY_PUBLISH=1`, publishes and activates it. Run the handshake example first: + after a document with an organization-scope constraint is activated, a decide that does not + supply the attribute the constraint conditions on is denied fail-closed with reasons + `["unknown_constraint"]`. ### Deprecated diff --git a/README.md b/README.md index f7bd8df..be4cebd 100644 --- a/README.md +++ b/README.md @@ -366,9 +366,9 @@ This surface does **not** go through the client's `RetryConfig`. That executor i The rest of the package is hand-written and is meant to be edited: `Attribute`, `AttributeValue`, `AttributeMap`, `AuthZENDecision`, `AuthZENEvaluation`, `AuthZENRefusals`, and the six exception types (`AuthZENEvaluationException` and its five subclasses). -### PEP capability handshake +### PEP capability handshake (v10.4.0+) -A v11 platform lets an enforcement point declare, on each call, the exact obligation types and schema versions it can discharge. Build the declaration once and give it to the client: +A platform from v10.4.0 lets an enforcement point declare, on each call, the exact obligation types and schema versions it can discharge. Build the declaration once and give it to the client: ```java PEPHandshake declared = @@ -393,10 +393,24 @@ The client sends it on every call to a plane that reads it: `decide`, the engine One process can be two enforcement points: a request path and a response path that discharge different obligations. `client.withPEPHandshake(other)` derives a client presenting `other` in place of the client's declaration. Like `asUser`, it shares the parent's connection pool, so never close a derived client. -- **There is no default.** A client given no declaration sends no header, and the platform behaves as it did before the handshake existed. `List.of()` declares that the enforcement point discharges nothing; a null list is refused. +- **There is no default.** A client given no declaration sends no header. From v11.0.0 an absent declaration has a consequence: on both editions, a decide under an organization's redact override refuses a caller that does not declare redaction, so declare what your enforcement point discharges. `List.of()` declares that the enforcement point discharges nothing; a null list is refused. - **What a declaration changes.** On an Enterprise deployment, an allow verdict carrying a mandatory obligation the declared set cannot discharge becomes a deny, so declare every obligation your enforcement point carries out, and only those. A Community deployment records the declaration without denying on it, and drops any capability in a family it does not issue. - **Refused before it is sent.** `PEPHandshake.of` and `PEPCapability.of` apply the platform's own rules and throw `PEPHandshakeException` naming the member at fault (`getPointer()` is `/pep_id`, `/audience` or `/capabilities`), instead of the first governed call coming back `400`. A `PEPHandshake` is immutable and computes its header once, so every request carries exactly the value that was validated. +## The v11.0.0 platform + +What each part of this SDK needs from the platform: + +| Chapter | Platform minimum | +|---|---| +| [PEP capability handshake](#pep-capability-handshake-v1040) (`pepHandshake`, `withPEPHandshake`) | v10.4.0: every plane that reads the header records it; an older platform ignores it | +| [Typed policy authoring](#typed-policy-authoring-v1100) (`typedPolicies()`) | v11.0.0 | +| Decision provenance (`getEngine()`, `getSubjectType()`, `getPolicyBundle()`, `getPolicyIdentities()` and the rest) | v11.0.0; against an older platform they read null or empty | +| Route deprecation reports (`onRouteDeprecation`) | v11.0.0 stamps the legacy policy routes | +| The legacy policy write freeze (`LegacyPolicyWriteFrozenException`) | v11.0.0 | + +Upgrade the SDK before the platform: from v11.0.0, a decide under an organization's redact override refuses a caller that does not declare redaction, and only a release that sends the handshake can declare it. Against an older platform the SDK works unchanged. + ## Typed policy authoring (v11.0.0+) A v11 platform authors policy as a typed document: validated, published as a signed artifact pinned by its digest, and promoted to active. `client.typedPolicies()` reaches the six routes the agent proxies under `/api/v1/typed-policies`: @@ -415,6 +429,7 @@ TypedPolicySystemCorpus system = typed.system(); // the platform's own controls - **The organization and the author are the ones your credentials resolve to.** The agent stamps both, and the platform overwrites any author named inside the document. A client derived with `asUser` has its own namespace, and its user token is the caller. - **Refusals are typed.** Every refusal is a `TypedPolicyRefusalException` with the HTTP status, the platform's reason (such as `publication_refused`, `activation_refused` or `tier_limit`), any findings, and `getRetryAfter()` when the refusal is retryable; a 401 is the client's `AuthenticationException`. On an edition with separation of duties, publishing refuses with the finding code `APPROVER_IS_AUTHOR`: the route names no approver, and such a deployment approves in the customer portal. - **The document is the authoring model itself,** a `Map` rather than Java types, so a field the policy vocabulary gains is authorable without an SDK release. A null fixtures list sends none; an empty one sends `[]`. `validate` answers identically on every edition; the edition's boundary is applied when you publish. +- **System controls are changed in the document, not per policy.** A v11.0.0 platform retires per-policy overrides: `createPolicyOverride` and `deletePolicyOverride` answer 409 `LEGACY_POLICY_WRITE_FROZEN` (agent-api's `PerPolicyOverrideRetired` response), and a system control is enabled, disabled or re-actioned in the organization's typed document, in its `system_controls` section. ## v11.0.0 deprecations @@ -725,11 +740,17 @@ Complete working examples for all features are available in the [examples folder Runnable in this repository, against a live agent: ```bash -mvn -q -DskipTests install # put the SDK on the local classpath +mvn -q -DskipTests -DskipUnitTests=true install # put the SDK on the local classpath AXONFLOW_AGENT_URL=http://localhost:8080 \ mvn -q -f examples/authzen/pom.xml compile exec:java # AuthZEN: 9 steps, 4 of them refusals +AXONFLOW_AGENT_URL=http://localhost:8080 \ + mvn -q -f examples/pep-handshake/pom.xml compile exec:java # the PEP capability handshake +AXONFLOW_AGENT_URL=http://localhost:8080 AXONFLOW_TYPED_POLICY_PUBLISH=1 \ + mvn -q -f examples/typed-policies/pom.xml compile exec:java # validate, publish, activate ``` +Run `pep-handshake` before `typed-policies`. After a document with an organization-scope constraint is activated, a decide that does not supply the attribute the constraint conditions on is denied fail-closed with reasons ["unknown_constraint"]; supply the attribute or run the example on a fresh stack. On Enterprise the client id is the organization id and the secret its license key; a Community deployment accepts any credentials. + ### Community Features ```java diff --git a/examples/pep-handshake/pom.xml b/examples/pep-handshake/pom.xml new file mode 100644 index 0000000..54a4d9f --- /dev/null +++ b/examples/pep-handshake/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + com.getaxonflow.examples + pep-handshake + 1.0-SNAPSHOT + jar + + AxonFlow Java SDK — PEP Capability Handshake Example + + Declares an enforcement point's capabilities with the PEP capability handshake and + decides with it against a running AxonFlow agent. Run mvn install on the SDK first to + put the local artifact on the classpath. + + + + + 11 + UTF-8 + + + + + com.getaxonflow + axonflow-sdk + 9.3.0 + + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + com.getaxonflow.examples.PepHandshake + + + + + diff --git a/examples/pep-handshake/src/main/java/com/getaxonflow/examples/PepHandshake.java b/examples/pep-handshake/src/main/java/com/getaxonflow/examples/PepHandshake.java new file mode 100644 index 0000000..5781395 --- /dev/null +++ b/examples/pep-handshake/src/main/java/com/getaxonflow/examples/PepHandshake.java @@ -0,0 +1,135 @@ +// Copyright 2026 AxonFlow +// SPDX-License-Identifier: MIT +package com.getaxonflow.examples; + +import com.getaxonflow.sdk.AxonFlow; +import com.getaxonflow.sdk.AxonFlowConfig; +import com.getaxonflow.sdk.authzen.AuthZENObligationType; +import com.getaxonflow.sdk.exceptions.PEPHandshakeException; +import com.getaxonflow.sdk.types.DecideRequest; +import com.getaxonflow.sdk.types.DecideResponse; +import com.getaxonflow.sdk.types.DecisionTarget; +import com.getaxonflow.sdk.types.PEPCapability; +import com.getaxonflow.sdk.types.PEPHandshake; +import java.util.List; + +/** + * Declaring an enforcement point's capabilities with the PEP capability handshake, which the + * platform reads from v10.4.0. + * + *

An enforcement point (a PEP) declares, on each governed call, the exact obligation types and + * schema versions it can discharge. On an Enterprise deployment an allow verdict carrying a + * mandatory obligation the declared set cannot discharge becomes a deny, so the enforcement point + * is never handed an instruction it would drop; a Community deployment records the declaration. + * From v11.0.0, on both editions, a decide under an organization's redact override refuses a caller + * that does not declare redaction. + * + *

This example builds a declaration once for the client, derives a client presenting another one + * (one process can be two enforcement points), and shows that a declaration the platform would + * refuse fails here, before anything is sent. Each decide prints its verdict and reasons. + * + *

After a document with an organization-scope constraint is activated, a decide that does not + * supply the attribute the constraint conditions on is denied fail-closed with reasons + * ["unknown_constraint"]; supply the attribute or run this example on a fresh stack. Run it before + * the typed-policies example, which publishes and activates such a document. + * + *

On Enterprise the client id is the organization id and the secret its license key; a Community + * deployment accepts any credentials. + * + *

+ * mvn -q -DskipTests -DskipUnitTests=true install   # from the repository root: the SDK on the local classpath
+ * AXONFLOW_AGENT_URL=http://localhost:8080 mvn -q -f examples/pep-handshake/pom.xml compile exec:java
+ * 
+ * + *

Exits non-zero if a step fails, so it is usable as a smoke test. + */ +public final class PepHandshake { + + private static int failures; + + private PepHandshake() {} + + @FunctionalInterface + private interface Step { + void run() throws Exception; + } + + private static void step(String name, Step body) { + System.out.println("\n=== " + name + " ==="); + try { + body.run(); + System.out.println("ok"); + } catch (Exception e) { + System.out.println("FAILED: " + e.getClass().getSimpleName() + ": " + e.getMessage()); + failures++; + } + } + + private static void print(DecideResponse decision) { + System.out.println( + "verdict=" + + decision.getVerdict() + + " reasons=" + + decision.getReasons() + + " obligations=" + + (decision.getObligations() == null ? 0 : decision.getObligations().size())); + } + + public static void main(String[] args) { + String endpoint = System.getenv().getOrDefault("AXONFLOW_AGENT_URL", "http://localhost:8080"); + String clientId = System.getenv("AXONFLOW_CLIENT_ID"); + String clientSecret = System.getenv("AXONFLOW_CLIENT_SECRET"); + + // The request path redacts fields; it declares exactly that. + PEPHandshake requestPath = + PEPHandshake.of( + "checkout-gateway", + "https://pep.example.com", + List.of(PEPCapability.of(AuthZENObligationType.FIELD_REDACT, 1))); + AxonFlowConfig.Builder config = + AxonFlowConfig.builder().endpoint(endpoint).pepHandshake(requestPath); + if (clientId != null && !clientId.isEmpty()) { + config.clientId(clientId).clientSecret(clientSecret); + } + try (AxonFlow client = AxonFlow.create(config.build())) { + DecideRequest decide = + DecideRequest.builder("tool", "look up the weather") + .target(new DecisionTarget("tool", null, null, "search")) + .build(); + + step("decide with the client's declaration", () -> print(client.decide(decide))); + + // The response path masks fields instead. A derived client presents its own declaration in + // place of the client's, and shares the client's connection pool: never close it. + step( + "decide with a derived client's declaration", + () -> { + PEPHandshake responsePath = + PEPHandshake.of( + "checkout-gateway-response", + "https://pep.example.com", + List.of(PEPCapability.of(AuthZENObligationType.FIELD_MASK, 1))); + print(client.withPEPHandshake(responsePath).decide(decide)); + }); + + // A declaration the platform would refuse fails at construction, naming the member at fault, + // instead of the first governed call answering 400. + step( + "a declaration the platform would refuse", + () -> { + try { + PEPHandshake.of("Checkout:Gateway", "https://pep.example.com", List.of()); + throw new IllegalStateException("the declaration was accepted"); + } catch (PEPHandshakeException refusal) { + System.out.println( + "refused at " + refusal.getPointer() + ": " + refusal.getMessage()); + } + }); + } + + if (failures > 0) { + System.out.println("\n" + failures + " step(s) failed"); + System.exit(1); + } + } +} diff --git a/examples/typed-policies/pom.xml b/examples/typed-policies/pom.xml new file mode 100644 index 0000000..4d9bd15 --- /dev/null +++ b/examples/typed-policies/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + com.getaxonflow.examples + typed-policies + 1.0-SNAPSHOT + jar + + AxonFlow Java SDK — Typed Policy Authoring Example + + Typed policy authoring against a running AxonFlow v11 platform: what the deployment may + author, validate, optionally publish and activate, and the document in force. Run mvn + install on the SDK first to put the local artifact on the classpath. + + + + + 11 + UTF-8 + + + + + com.getaxonflow + axonflow-sdk + 9.3.0 + + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + com.getaxonflow.examples.TypedPolicies + + + + + diff --git a/examples/typed-policies/src/main/java/com/getaxonflow/examples/TypedPolicies.java b/examples/typed-policies/src/main/java/com/getaxonflow/examples/TypedPolicies.java new file mode 100644 index 0000000..930b3e4 --- /dev/null +++ b/examples/typed-policies/src/main/java/com/getaxonflow/examples/TypedPolicies.java @@ -0,0 +1,186 @@ +// Copyright 2026 AxonFlow +// SPDX-License-Identifier: MIT +package com.getaxonflow.examples; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.getaxonflow.sdk.AxonFlow; +import com.getaxonflow.sdk.AxonFlowConfig; +import com.getaxonflow.sdk.exceptions.TypedPolicyRefusalException; +import com.getaxonflow.sdk.types.policies.TypedPolicyTypes.ActiveTypedPolicy; +import com.getaxonflow.sdk.types.policies.TypedPolicyTypes.AuthoringFinding; +import com.getaxonflow.sdk.types.policies.TypedPolicyTypes.TypedAuthoringEdition; +import com.getaxonflow.sdk.types.policies.TypedPolicyTypes.TypedPolicyPublication; +import com.getaxonflow.sdk.types.policies.TypedPolicyTypes.TypedPolicyValidation; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * Typed policy authoring against a running AxonFlow v11 platform. + * + *

A v11 platform authors policy as a typed document: validated, published as a signed artifact + * pinned by its digest, and promoted to active. This example reads what the deployment may author, + * validates a document and prints every finding, and shows the document in force. It publishes and + * activates only when {@code AXONFLOW_TYPED_POLICY_PUBLISH=1}, because that changes the + * organization's active policy; a refusal prints the platform's reason and findings. + * + *

After a document with an organization-scope constraint is activated, a decide that does not + * supply the attribute the constraint conditions on is denied fail-closed with reasons + * ["unknown_constraint"]; supply the attribute or run this example on a fresh stack. The default + * document is such a document, so run the pep-handshake example first. + * + *

{@code AXONFLOW_TYPED_POLICY_BODY} names a JSON file holding {@code {"document": ..., + * "fixtures": [...]}}; the default is {@code tests/fixtures/typed_policy_publish_body.json}, read + * from the directory Maven runs in. On an edition with separation of duties, see the README's Typed + * policy authoring section for how a publication is approved. + * + *

+ * mvn -q -DskipTests -DskipUnitTests=true install   # from the repository root: the SDK on the local classpath
+ * AXONFLOW_AGENT_URL=http://localhost:8080 AXONFLOW_TYPED_POLICY_PUBLISH=1 \
+ *   mvn -q -f examples/typed-policies/pom.xml compile exec:java
+ * 
+ * + *

Exits non-zero if a step fails, so it is usable as a smoke test. + */ +public final class TypedPolicies { + + private static int failures; + + private TypedPolicies() {} + + @FunctionalInterface + private interface Step { + void run() throws Exception; + } + + private static void step(String name, Step body) { + System.out.println("\n=== " + name + " ==="); + try { + body.run(); + System.out.println("ok"); + } catch (Exception e) { + System.out.println("FAILED: " + e.getClass().getSimpleName() + ": " + e.getMessage()); + failures++; + } + } + + private static void print(List findings) { + if (findings == null) { + return; + } + for (AuthoringFinding f : findings) { + System.out.println( + " " + + f.getSeverity() + + " " + + f.getCode() + + " " + + f.getPolicyId() + + ": " + + f.getDetail()); + } + } + + public static void main(String[] args) throws Exception { + String endpoint = System.getenv().getOrDefault("AXONFLOW_AGENT_URL", "http://localhost:8080"); + String bodyPath = + System.getenv() + .getOrDefault( + "AXONFLOW_TYPED_POLICY_BODY", "tests/fixtures/typed_policy_publish_body.json"); + Map body = + new ObjectMapper() + .readValue( + Files.readAllBytes(Paths.get(bodyPath)), + new TypeReference>() {}); + @SuppressWarnings("unchecked") + Map document = (Map) body.get("document"); + @SuppressWarnings("unchecked") + List> fixtures = (List>) body.get("fixtures"); + + AxonFlowConfig.Builder config = AxonFlowConfig.builder().endpoint(endpoint); + String clientId = System.getenv("AXONFLOW_CLIENT_ID"); + if (clientId != null && !clientId.isEmpty()) { + config.clientId(clientId).clientSecret(System.getenv("AXONFLOW_CLIENT_SECRET")); + } + try (AxonFlow client = AxonFlow.create(config.build())) { + AxonFlow.TypedPoliciesNamespace typed = client.typedPolicies(); + + // What this deployment may author: consult it before publishing rather than learning the + // edition's boundary from a refusal. + step( + "what this deployment may author", + () -> { + TypedAuthoringEdition edition = typed.edition(); + System.out.println( + "root=" + + edition.getRoot() + + " max_documents=" + + edition.getMaxDocuments() + + " persistence=" + + edition.getPersistence()); + }); + + // Validation reports every finding. A refused document is still a successful validation: read + // isSuccess() and the findings, do not expect an exception. + step( + "validate the document", + () -> { + TypedPolicyValidation validation = typed.validate(document, fixtures); + System.out.println("success=" + validation.isSuccess()); + print(validation.getFindings()); + }); + + if ("1".equals(System.getenv("AXONFLOW_TYPED_POLICY_PUBLISH"))) { + step( + "publish and activate", + () -> { + try { + TypedPolicyPublication published = typed.publish(document, fixtures); + System.out.println( + "published " + + published.getDigest() + + " (version " + + published.getVersion() + + ")"); + typed.activate(published.getDigest(), "examples/typed-policies"); + System.out.println("activated"); + } catch (TypedPolicyRefusalException refusal) { + // A refusal carries the platform's reason and, for a refused document, the findings + // that refused it. + System.out.println( + "refused: HTTP " + + refusal.getStatus() + + " " + + refusal.getReason() + + ": " + + refusal.getMessage()); + print(refusal.getFindings()); + throw refusal; // publishing was asked for, so a refusal fails the step + } + }); + } + + // The document in force is returned as the exact bytes that were signed. + step( + "the document in force", + () -> { + Optional active = typed.active(); + if (!active.isPresent()) { + System.out.println("nothing is active"); + return; + } + Object metadata = active.get().getDocument().get("metadata"); + System.out.println( + active.get().getSource().length() + " signed characters; metadata=" + metadata); + }); + } + + if (failures > 0) { + System.out.println("\n" + failures + " step(s) failed"); + System.exit(1); + } + } +} diff --git a/runtime-e2e/v11_examples/README.md b/runtime-e2e/v11_examples/README.md new file mode 100644 index 0000000..7681e91 --- /dev/null +++ b/runtime-e2e/v11_examples/README.md @@ -0,0 +1,25 @@ +# v11_examples + +Real-stack proof that the two v11 examples run as the README says. `run.sh` builds the SDK from this tree, compiles `examples/pep-handshake` and `examples/typed-policies` against it, and runs them against a live Community agent in the README's order. Nothing is mocked. + +## What it proves + +| Step | Expected | +|---|---| +| `pep-handshake` on a fresh stack | exits 0; the first decide's verdict is `allow`; the declaration the platform would refuse fails in the client at `/pep_id`, before anything is sent | +| `typed-policies` with `AXONFLOW_TYPED_POLICY_PUBLISH=1` | exits 0; the document is published and activated | +| `pep-handshake` again, after the activation | printed as an observation, not asserted (below) | + +## Why the third run is an observation + +After a document with an organization-scope constraint is activated, a decide that does not supply the attribute the constraint conditions on is denied fail-closed with reasons `["unknown_constraint"]`. The example's default document is such a document, so the third run shows that deny; it is the platform's by-design answer, not the SDK's, and this leg prints it rather than pinning it. That deny names no evaluated policy, which is getaxonflow/axonflow-enterprise#4227. It is why the README runs the handshake example first. + +## Run + +Community on the application database role (typed publishing needs an edition that lets a sole author publish). On a fresh stack: + +``` +AXONFLOW_AGENT_URL=http://localhost:8080 ./runtime-e2e/v11_examples/run.sh +``` + +Every step uses `AXONFLOW_CLIENT_ID` and `AXONFLOW_CLIENT_SECRET`, defaulting to `runtime-e2e` / `runtime-e2e-secret`; a Community deployment accepts any credentials. It exits non-zero on any failed assertion, and it changes the organization's active policy. diff --git a/runtime-e2e/v11_examples/run.sh b/runtime-e2e/v11_examples/run.sh new file mode 100755 index 0000000..effb8c2 --- /dev/null +++ b/runtime-e2e/v11_examples/run.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# Runs examples/pep-handshake and examples/typed-policies, built against the LOCAL SDK, against a +# LIVE Community agent, in the order the README gives, and asserts what each proves: +# +# 1. pep-handshake on a fresh stack: exits 0, the first decide is allowed, and +# the declaration the platform would refuse fails in the client at /pep_id. +# 2. typed-policies with AXONFLOW_TYPED_POLICY_PUBLISH=1: exits 0, and the document is activated. +# 3. pep-handshake again: printed as an OBSERVATION, not asserted. After step 2 activates a +# document with an organization-scope constraint, a decide that does not supply the attribute +# the constraint conditions on is denied fail-closed with reasons ["unknown_constraint"]. +# +# It changes the organization's active policy (step 2), so run it on a fresh stack. +# +# AXONFLOW_AGENT_URL=http://localhost:8080 ./runtime-e2e/v11_examples/run.sh +set -euo pipefail +ROOT="$(cd "$(dirname "$0")/../.." && pwd)" +cd "$ROOT" +AGENT="${AXONFLOW_AGENT_URL:-http://localhost:8080}" +CLIENT_ID="${AXONFLOW_CLIENT_ID:-runtime-e2e}" +CLIENT_SECRET="${AXONFLOW_CLIENT_SECRET:-runtime-e2e-secret}" +# This pom sets surefire's skipTests from its own skipUnitTests property, which overrides a +# command-line -DskipTests, so -DskipTests alone still runs the whole unit suite. +mvn -q -DskipTests -DskipUnitTests=true -Dfmt.skip=true package +mvn -q -DskipTests dependency:build-classpath -Dmdep.outputFile=target/v11-examples-cp.txt +SDK_JAR=$(ls target/axonflow-sdk-*.jar | grep -v sources | grep -v javadoc | head -1) +# A binding so the SDK's WARN output is visible: the SDK depends on slf4j-api alone, and without a +# binding its logger is a no-op. +SLF4J_SIMPLE="${HOME}/.m2/repository/org/slf4j/slf4j-simple/2.0.12/slf4j-simple-2.0.12.jar" +if [ ! -f "$SLF4J_SIMPLE" ]; then + mvn -q dependency:get -Dartifact=org.slf4j:slf4j-simple:2.0.12 +fi +CP="${SDK_JAR}:${SLF4J_SIMPLE}:$(cat target/v11-examples-cp.txt)" +OUT=target/v11-examples +rm -rf "$OUT" +for ex in pep-handshake typed-policies; do + mkdir -p "$OUT/$ex" + javac -d "$OUT/$ex" -cp "$CP" examples/$ex/src/main/java/com/getaxonflow/examples/*.java +done + +FAILURES=0 +check() { + if [ "$1" = ok ]; then echo "PASS: $2"; else echo "FAIL: $2"; FAILURES=$((FAILURES + 1)); fi +} +# Runs one example with the given environment, captures its output, and returns its exit code. +run_example() { + local ex=$1 main=$2 log=$3; shift 3 + set +e + env AXONFLOW_AGENT_URL="$AGENT" AXONFLOW_TELEMETRY=off AXONFLOW_CLIENT_ID="$CLIENT_ID" AXONFLOW_CLIENT_SECRET="$CLIENT_SECRET" "$@" \ + java -cp "$OUT/$ex:$CP" "$main" >"$log" 2>&1 + local rc=$? + set -e + grep -vE '^[[:space:]]*$| DEBUG | INFO ' "$log" | sed 's/^/ | /' + return $rc +} + +echo "=== 1. pep-handshake on a fresh stack" +rc=0; run_example pep-handshake com.getaxonflow.examples.PepHandshake "$OUT/1.log" || rc=$? +check "$([ $rc = 0 ] && echo ok)" "pep-handshake exits 0 (exit $rc)" +first=$(grep -m1 -oE '^verdict=[a-z_]+' "$OUT/1.log" || true) +check "$([ "$first" = verdict=allow ] && echo ok)" "the first decide is allowed on a fresh stack ($first)" +check "$(grep -q '^refused at /pep_id: ' "$OUT/1.log" && echo ok)" \ + "the declaration the platform would refuse fails in the client, at /pep_id, before anything is sent" + +echo "=== 2. typed-policies: validate, publish and activate" +rc=0; run_example typed-policies com.getaxonflow.examples.TypedPolicies "$OUT/2.log" \ + AXONFLOW_TYPED_POLICY_PUBLISH=1 AXONFLOW_TYPED_POLICY_BODY="$ROOT/tests/fixtures/typed_policy_publish_body.json" || rc=$? +check "$([ $rc = 0 ] && echo ok)" "typed-policies exits 0 (exit $rc)" +check "$(grep -qx 'activated' "$OUT/2.log" && echo ok)" "the document is published and activated" + +echo "=== 3. OBSERVATION, not asserted: pep-handshake after the activation" +run_example pep-handshake com.getaxonflow.examples.PepHandshake "$OUT/3.log" || true +echo " observed: $(grep -m1 -oE '^verdict=.*' "$OUT/3.log" || echo 'no verdict printed')" + +if [ "$FAILURES" -gt 0 ]; then + echo; echo "FAIL: v11_examples ($FAILURES assertion(s))"; exit 1 +fi +echo; echo "PASS: v11_examples" diff --git a/src/main/java/com/getaxonflow/sdk/exceptions/PEPHandshakeException.java b/src/main/java/com/getaxonflow/sdk/exceptions/PEPHandshakeException.java index 93e5a77..d3c54e6 100644 --- a/src/main/java/com/getaxonflow/sdk/exceptions/PEPHandshakeException.java +++ b/src/main/java/com/getaxonflow/sdk/exceptions/PEPHandshakeException.java @@ -5,7 +5,7 @@ import com.getaxonflow.sdk.types.PEPHandshake; /** - * A PEP capability declaration the platform would refuse (platform v11.0.0). + * A PEP capability declaration the platform would refuse (read by the platform from v10.4.0). * *

{@link PEPHandshake#of} and {@link com.getaxonflow.sdk.types.PEPCapability#of} apply the * platform's own rules, so a declaration its decoder would answer with a 400 fails where it is diff --git a/src/main/java/com/getaxonflow/sdk/types/PEPCapability.java b/src/main/java/com/getaxonflow/sdk/types/PEPCapability.java index cfc1f62..ee73644 100644 --- a/src/main/java/com/getaxonflow/sdk/types/PEPCapability.java +++ b/src/main/java/com/getaxonflow/sdk/types/PEPCapability.java @@ -10,7 +10,8 @@ /** * One obligation type, at one schema version, that an enforcement point can discharge: a member of - * a {@link PEPHandshake} (platform v11.0.0). The platform matches both members exactly. + * a {@link PEPHandshake} (read by the platform from v10.4.0). The platform matches both members + * exactly. * *

Built only through {@link #of}, which admits the obligation types the SDK's AuthZEN contract * declares ({@link AuthZENObligationType#KNOWN_WIRE_VALUES}) at a positive version. The platform diff --git a/src/main/java/com/getaxonflow/sdk/types/PEPHandshake.java b/src/main/java/com/getaxonflow/sdk/types/PEPHandshake.java index 62dfb2a..3adaa23 100644 --- a/src/main/java/com/getaxonflow/sdk/types/PEPHandshake.java +++ b/src/main/java/com/getaxonflow/sdk/types/PEPHandshake.java @@ -17,8 +17,9 @@ import java.util.regex.Pattern; /** - * A PEP capability declaration (platform v11.0.0): the exact obligation types and schema versions - * an enforcement point can discharge, sent on each governed call as the {@value #HEADER} header. + * A PEP capability declaration (read by the platform from v10.4.0): the exact obligation types and + * schema versions an enforcement point can discharge, sent on each governed call as the {@value + * #HEADER} header. * *

The header carries the unpadded base64url encoding of the JSON document {@code * {"profile_version":1,"pep_id":...,"audience":...,"capabilities":[{"type":...,"version":...}]}}. @@ -35,11 +36,12 @@ * pre-check ({@code getPolicyApprovedContext}, {@code preCheck}). No other route reads it, and the * client never sends it anywhere else. * - *

Absent is not empty. A client with no declaration sends no header, and the platform - * behaves as it did before the handshake existed; there is no default, because only the caller - * knows what its enforcement point can discharge. An empty capability list declares that it - * discharges nothing, which on Enterprise turns every allow carrying a mandatory obligation into a - * deny. + *

Absent is not empty. A client with no declaration sends no header; there is no default, + * because only the caller knows what its enforcement point can discharge. The platform reads the + * handshake from v10.4.0, and from v11.0.0, on both editions, a decide under an organization's + * redact override refuses a caller that does not declare redaction. An empty capability list + * declares that it discharges nothing, which on Enterprise turns every allow carrying a mandatory + * obligation into a deny. * *

Built only through {@link #of}, which applies the platform's own rules (its {@code * DecodePEPHandshake}) and computes the header once. An instance is therefore always a declaration