This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 5bf631eb74da CAMEL-26837: Support expressions for complete policy
input documents (#29832)
5bf631eb74da is described below
commit 5bf631eb74da9d41eab7720ee9c21b1f11645554
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Nov 16 22:54:50 2026 +0100
CAMEL-26837: Support expressions for complete policy input documents
(#29832)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-authored-by: Codex <[email protected]>
---
.../camel/catalog/beans/OpaSecurityPolicy.json | 2 +-
.../org/apache/camel/catalog/components/opa.json | 32 +--
.../apache/camel/catalog/docs/opa-component.adoc | 84 +++++++
.../component/opa/OpaComponentConfigurer.java | 6 +
.../camel/component/opa/OpaEndpointConfigurer.java | 6 +
.../camel/component/opa/OpaEndpointUriFactory.java | 3 +-
.../opa/security/OpaSecurityPolicyConfigurer.java | 6 +
.../org/apache/camel/component/opa/opa.json | 32 +--
.../org/apache/camel/bean/OpaSecurityPolicy.json | 2 +-
.../camel-opa/src/main/docs/opa-component.adoc | 84 +++++++
.../camel/component/opa/OpaConfiguration.java | 21 ++
.../apache/camel/component/opa/OpaEndpoint.java | 9 +-
.../camel/component/opa/OpaPolicyEvaluator.java | 55 ++++-
.../camel/component/opa/OpaRestEvaluator.java | 9 +-
.../camel/component/opa/OpaWasmEvaluator.java | 21 +-
.../component/opa/security/OpaSecurityPolicy.java | 26 ++-
.../component/opa/OpaInputExpressionTest.java | 251 +++++++++++++++++++++
.../org/apache/camel/component/opa/OpaWasmIT.java | 14 ++
.../component/dsl/OpaComponentBuilderFactory.java | 22 ++
.../endpoint/dsl/OpaEndpointBuilderFactory.java | 39 ++++
20 files changed, 680 insertions(+), 44 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/OpaSecurityPolicy.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/OpaSecurityPolicy.json
index d1504304e6d2..e63c588ce2ee 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/OpaSecurityPolicy.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/OpaSecurityPolicy.json
@@ -10,7 +10,7 @@
"groupId": "org.apache.camel",
"artifactId": "camel-opa",
"version": "4.24.0-SNAPSHOT",
- "properties": { "serverUrl": { "index": 0, "kind": "property",
"displayName": "Server Url", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "http:\/\/localhost:8181", "description": "The base URL of the
OPA server, without the \/v1\/data suffix. Not used in wasm mode." },
"policyPath": { "index": 1, "kind": "property", "displayName": "Policy Path",
"required": true, "type": "string", "javaT [...]
+ "properties": { "serverUrl": { "index": 0, "kind": "property",
"displayName": "Server Url", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "http:\/\/localhost:8181", "description": "The base URL of the
OPA server, without the \/v1\/data suffix. Not used in wasm mode." },
"policyPath": { "index": 1, "kind": "property", "displayName": "Policy Path",
"required": true, "type": "string", "javaT [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/opa.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/opa.json
index 2fcbffcb3426..5d41c69a2137 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/opa.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/opa.json
@@ -39,15 +39,16 @@
"borrowTimeout": { "index": 12, "kind": "property", "displayName": "Borrow
Timeout", "group": "advanced", "label": "advanced", "required": false, "type":
"duration", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long an exchange waits for a free
WebAssembly policy instance in wasm mode before the e [...]
"connectionTimeout": { "index": 13, "kind": "property", "displayName":
"Connection Timeout", "group": "advanced", "label": "advanced", "required":
false, "type": "duration", "javaType": "long", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "10000",
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "How long to wait for the
connection to the OPA server to be established, in rest mo [...]
"healthCheckBundles": { "index": 14, "kind": "property", "displayName":
"Health Check Bundles", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "Whether the server
readiness check also requires activation of OPA's configured [...]
- "opaClient": { "index": 15, "kind": "property", "displayName": "Opa
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "com.styra.opa.OPAClient", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An existing OPAClient to use. When set,
serverUrl and bearerToken are ignored." },
- "poolSize": { "index": 16, "kind": "property", "displayName": "Pool Size",
"group": "advanced", "label": "advanced", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 8, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How many WebAssembly policy instances to pool
in wasm mode. An instance carries mutable state and is not thre [...]
- "requestTimeout": { "index": 17, "kind": "property", "displayName":
"Request Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long to wait for the decision once
connected, in rest mode. A request that times out [...]
- "healthCheckConsumerEnabled": { "index": 18, "kind": "property",
"displayName": "Health Check Consumer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all consumer based health checks
from this component" },
- "healthCheckProducerEnabled": { "index": 19, "kind": "property",
"displayName": "Health Check Producer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all producer based health checks
from this component. Notice: Camel has by default disabled all producer based
health-checks. You can turn on produce [...]
- "bearerToken": { "index": 20, "kind": "property", "displayName": "Bearer
Token", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Bearer token sent to the OPA server in the
Authorization header, for an OPA instance that [...]
- "failOpen": { "index": 21, "kind": "property", "displayName": "Fail Open",
"group": "security", "label": "security", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "security": "insecure:dev", "defaultValue": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Whether to allow the exchange to proceed when
the policy decision point i [...]
- "sslContextParameters": { "index": 22, "kind": "property", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "TLS configuration for the connection to the
OPA server in [...]
- "useGlobalSslContextParameters": { "index": 23, "kind": "property",
"displayName": "Use Global Ssl Context Parameters", "group": "security",
"label": "security", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Enable usage of global SSL context
parameters." }
+ "inputExpression": { "index": 15, "kind": "property", "displayName":
"Input Expression", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType": "org.apache.camel.Expression",
"deprecated": false, "autowired": false, "secret": false,
"supportSimpleExpression": true, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An expression producing the complete policy
input as a Map [...]
+ "opaClient": { "index": 16, "kind": "property", "displayName": "Opa
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "com.styra.opa.OPAClient", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An existing OPAClient to use. When set,
serverUrl and bearerToken are ignored." },
+ "poolSize": { "index": 17, "kind": "property", "displayName": "Pool Size",
"group": "advanced", "label": "advanced", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 8, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How many WebAssembly policy instances to pool
in wasm mode. An instance carries mutable state and is not thre [...]
+ "requestTimeout": { "index": 18, "kind": "property", "displayName":
"Request Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long to wait for the decision once
connected, in rest mode. A request that times out [...]
+ "healthCheckConsumerEnabled": { "index": 19, "kind": "property",
"displayName": "Health Check Consumer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all consumer based health checks
from this component" },
+ "healthCheckProducerEnabled": { "index": 20, "kind": "property",
"displayName": "Health Check Producer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all producer based health checks
from this component. Notice: Camel has by default disabled all producer based
health-checks. You can turn on produce [...]
+ "bearerToken": { "index": 21, "kind": "property", "displayName": "Bearer
Token", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Bearer token sent to the OPA server in the
Authorization header, for an OPA instance that [...]
+ "failOpen": { "index": 22, "kind": "property", "displayName": "Fail Open",
"group": "security", "label": "security", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "security": "insecure:dev", "defaultValue": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Whether to allow the exchange to proceed when
the policy decision point i [...]
+ "sslContextParameters": { "index": 23, "kind": "property", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "TLS configuration for the connection to the
OPA server in [...]
+ "useGlobalSslContextParameters": { "index": 24, "kind": "property",
"displayName": "Use Global Ssl Context Parameters", "group": "security",
"label": "security", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Enable usage of global SSL context
parameters." }
},
"headers": {
"CamelOpaDecisionAllow": { "index": 0, "kind": "header", "displayName":
"", "group": "producer", "label": "producer", "required": false, "javaType":
"Boolean", "deprecated": false, "autowired": false, "secret": false,
"description": "The allow\/deny verdict of the policy evaluation. Always
overwritten by the component, so a value set by an inbound message never
survives into the route.", "constantName":
"org.apache.camel.component.opa.OpaConstants#DECISION_ALLOW" },
@@ -76,11 +77,12 @@
"borrowTimeout": { "index": 11, "kind": "parameter", "displayName":
"Borrow Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long an exchange waits for a free
WebAssembly policy instance in wasm mode before the [...]
"connectionTimeout": { "index": 12, "kind": "parameter", "displayName":
"Connection Timeout", "group": "advanced", "label": "advanced", "required":
false, "type": "duration", "javaType": "long", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "10000",
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "How long to wait for the
connection to the OPA server to be established, in rest m [...]
"healthCheckBundles": { "index": 13, "kind": "parameter", "displayName":
"Health Check Bundles", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "Whether the server
readiness check also requires activation of OPA's configured [...]
- "opaClient": { "index": 14, "kind": "parameter", "displayName": "Opa
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "com.styra.opa.OPAClient", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An existing OPAClient to use. When set,
serverUrl and bearerToken are ignored." },
- "poolSize": { "index": 15, "kind": "parameter", "displayName": "Pool
Size", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 8, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How many WebAssembly policy instances to pool
in wasm mode. An instance carries mutable state and is not thr [...]
- "requestTimeout": { "index": 16, "kind": "parameter", "displayName":
"Request Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long to wait for the decision once
connected, in rest mode. A request that times out [...]
- "bearerToken": { "index": 17, "kind": "parameter", "displayName": "Bearer
Token", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Bearer token sent to the OPA server in the
Authorization header, for an OPA instance tha [...]
- "failOpen": { "index": 18, "kind": "parameter", "displayName": "Fail
Open", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "security": "insecure:dev", "defaultValue": false,
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "Whether to allow the
exchange to proceed when the policy decision point [...]
- "sslContextParameters": { "index": 19, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "TLS configuration for the connection to the
OPA server i [...]
+ "inputExpression": { "index": 14, "kind": "parameter", "displayName":
"Input Expression", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType": "org.apache.camel.Expression",
"deprecated": false, "autowired": false, "secret": false,
"supportSimpleExpression": true, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An expression producing the complete policy
input as a Ma [...]
+ "opaClient": { "index": 15, "kind": "parameter", "displayName": "Opa
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "com.styra.opa.OPAClient", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An existing OPAClient to use. When set,
serverUrl and bearerToken are ignored." },
+ "poolSize": { "index": 16, "kind": "parameter", "displayName": "Pool
Size", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 8, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How many WebAssembly policy instances to pool
in wasm mode. An instance carries mutable state and is not thr [...]
+ "requestTimeout": { "index": 17, "kind": "parameter", "displayName":
"Request Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long to wait for the decision once
connected, in rest mode. A request that times out [...]
+ "bearerToken": { "index": 18, "kind": "parameter", "displayName": "Bearer
Token", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Bearer token sent to the OPA server in the
Authorization header, for an OPA instance tha [...]
+ "failOpen": { "index": 19, "kind": "parameter", "displayName": "Fail
Open", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "security": "insecure:dev", "defaultValue": false,
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "Whether to allow the
exchange to proceed when the policy decision point [...]
+ "sslContextParameters": { "index": 20, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "TLS configuration for the connection to the
OPA server i [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/opa-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/opa-component.adoc
index f1d966bed6bc..13d20db8a0d4 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/opa-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/opa-component.adoc
@@ -241,6 +241,90 @@ conversion applies at depth.
The component's own `CamelOpa*` decision headers are never sent back to OPA,
so a policy cannot be shown a
verdict that an inbound message claimed for itself.
+=== Custom input expressions
+
+Set `inputExpression=#domainInput` to evaluate a configured Camel `Expression`
bean that produces the complete
+policy input. This replaces the default envelope in both REST and WASM modes,
and also applies to
+`OpaSecurityPolicy`. The expression result may be a `Map`, an object JSON
node, or a POJO supported by the
+component's Jackson JSON mapping. Nested maps, lists and POJOs are normalized
to JSON-native values; a top-level
+JSON string is not parsed implicitly. Null, scalar, array and streaming
results fail closed before the policy
+engine is called, even when `failOpen=true`.
+
+For example, take the verified identity from an exchange property the route
set after authentication, and only
+the domain payload from the body:
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+context.getRegistry().bind("domainInput", new ExpressionAdapter() {
+ @Override
+ public Object evaluate(Exchange exchange) {
+ return Map.of("subject", exchange.getProperty("verifiedSubject"),
+ "order", exchange.getMessage().getBody());
+ }
+});
+
+from("direct:orders")
+ .to("opa:authz/orders/allow?inputExpression=#domainInput");
+----
+
+XML::
++
+[source,xml]
+----
+<!-- a small Expression class of the application, with the evaluate(Exchange)
method of the Java tab -->
+<bean id="domainInput" class="com.example.orders.DomainInputExpression"/>
+
+<camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:orders"/>
+ <to uri="opa:authz/orders/allow?inputExpression=#domainInput"/>
+ </route>
+</camelContext>
+----
+
+YAML::
++
+[source,yaml]
+----
+- beans:
+ # a small Expression class of the application, with the evaluate(Exchange)
method of the Java tab
+ - name: domainInput
+ type: com.example.orders.DomainInputExpression
+- route:
+ from:
+ uri: direct:orders
+ steps:
+ - to:
+ uri: opa:authz/orders/allow
+ parameters:
+ inputExpression: "#domainInput"
+----
+====
+
+WARNING: The body comes from the sender. Do not make it the whole input, and
never let it supply the identity or
+role fields the policy reads: a sender who posts `{"subject": "admin"}` would
write straight into them. Take the
+identity from an exchange property the route verified, as
<<authorizing-an-identity>> describes, and put the
+sender's data under a key of its own.
+
+The `includeHeaders`, `includeProperties` and `includeBody` options configure
only the default envelope; they do
+not add or filter fields in a custom input. The expression decides what to
include, so select verified identity
+and application data deliberately. The default envelope withholds the headers
that carry a credential verbatim
+(`Authorization`, `Proxy-Authorization`, `Cookie` and `Set-Cookie`); a custom
expression gets none of that
+protection, so copy headers selectively and leave those out. Decision headers
are still cleared before mapping.
+Custom expression beans must support concurrent evaluation. For a single
exchange the expression runs on the live
+exchange, so a header or property it sets stays on the exchange; in batch mode
it runs on a copy, as described
+below.
+
+In batch mode, the expression is evaluated once per element against an
exchange copy whose body is that element.
+Headers and properties remain available to the expression, while the route's
original List body is preserved.
+The expression must produce one JSON object per element; a mapping failure
stops the batch before calling OPA.
+The component does not consume streams automatically. If an expression
explicitly reads a stream, configure
+stream caching or handle its lifetime in the route.
+
== Reading the verdict
`CamelOpaDecision` holds the decision document exactly as OPA returned it.
`CamelOpaDecisionAllow` holds the
diff --git
a/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaComponentConfigurer.java
b/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaComponentConfigurer.java
index 45ff639df719..ac3864b907be 100644
---
a/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaComponentConfigurer.java
+++
b/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaComponentConfigurer.java
@@ -60,6 +60,8 @@ public class OpaComponentConfigurer extends
PropertyConfigurerSupport implements
case "includeHeaders":
getOrCreateConfiguration(target).setIncludeHeaders(property(camelContext,
java.lang.String.class, value)); return true;
case "includeproperties":
case "includeProperties":
getOrCreateConfiguration(target).setIncludeProperties(property(camelContext,
java.lang.String.class, value)); return true;
+ case "inputexpression":
+ case "inputExpression":
getOrCreateConfiguration(target).setInputExpression(property(camelContext,
org.apache.camel.Expression.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer":
target.setLazyStartProducer(property(camelContext, boolean.class, value));
return true;
case "opaclient":
@@ -117,6 +119,8 @@ public class OpaComponentConfigurer extends
PropertyConfigurerSupport implements
case "includeHeaders": return java.lang.String.class;
case "includeproperties":
case "includeProperties": return java.lang.String.class;
+ case "inputexpression":
+ case "inputExpression": return org.apache.camel.Expression.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
case "opaclient":
@@ -170,6 +174,8 @@ public class OpaComponentConfigurer extends
PropertyConfigurerSupport implements
case "includeHeaders": return
getOrCreateConfiguration(target).getIncludeHeaders();
case "includeproperties":
case "includeProperties": return
getOrCreateConfiguration(target).getIncludeProperties();
+ case "inputexpression":
+ case "inputExpression": return
getOrCreateConfiguration(target).getInputExpression();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "opaclient":
diff --git
a/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaEndpointConfigurer.java
b/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaEndpointConfigurer.java
index 1a18746d109c..c19a1c205979 100644
---
a/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaEndpointConfigurer.java
+++
b/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaEndpointConfigurer.java
@@ -46,6 +46,8 @@ public class OpaEndpointConfigurer extends
PropertyConfigurerSupport implements
case "includeHeaders":
target.getConfiguration().setIncludeHeaders(property(camelContext,
java.lang.String.class, value)); return true;
case "includeproperties":
case "includeProperties":
target.getConfiguration().setIncludeProperties(property(camelContext,
java.lang.String.class, value)); return true;
+ case "inputexpression":
+ case "inputExpression":
target.getConfiguration().setInputExpression(property(camelContext,
org.apache.camel.Expression.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer":
target.setLazyStartProducer(property(camelContext, boolean.class, value));
return true;
case "opaclient":
@@ -94,6 +96,8 @@ public class OpaEndpointConfigurer extends
PropertyConfigurerSupport implements
case "includeHeaders": return java.lang.String.class;
case "includeproperties":
case "includeProperties": return java.lang.String.class;
+ case "inputexpression":
+ case "inputExpression": return org.apache.camel.Expression.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
case "opaclient":
@@ -138,6 +142,8 @@ public class OpaEndpointConfigurer extends
PropertyConfigurerSupport implements
case "includeHeaders": return
target.getConfiguration().getIncludeHeaders();
case "includeproperties":
case "includeProperties": return
target.getConfiguration().getIncludeProperties();
+ case "inputexpression":
+ case "inputExpression": return
target.getConfiguration().getInputExpression();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "opaclient":
diff --git
a/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaEndpointUriFactory.java
b/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaEndpointUriFactory.java
index 670b50f9c6b6..bd704cb53c84 100644
---
a/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaEndpointUriFactory.java
+++
b/components/camel-opa/src/generated/java/org/apache/camel/component/opa/OpaEndpointUriFactory.java
@@ -24,7 +24,7 @@ public class OpaEndpointUriFactory extends
org.apache.camel.support.component.En
private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
private static final Map<String, String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(20);
+ Set<String> props = new HashSet<>(21);
props.add("allowKey");
props.add("batch");
props.add("bearerToken");
@@ -37,6 +37,7 @@ public class OpaEndpointUriFactory extends
org.apache.camel.support.component.En
props.add("includeBody");
props.add("includeHeaders");
props.add("includeProperties");
+ props.add("inputExpression");
props.add("lazyStartProducer");
props.add("opaClient");
props.add("policyBundle");
diff --git
a/components/camel-opa/src/generated/java/org/apache/camel/component/opa/security/OpaSecurityPolicyConfigurer.java
b/components/camel-opa/src/generated/java/org/apache/camel/component/opa/security/OpaSecurityPolicyConfigurer.java
index abfe3940d152..9d3882a2c24e 100644
---
a/components/camel-opa/src/generated/java/org/apache/camel/component/opa/security/OpaSecurityPolicyConfigurer.java
+++
b/components/camel-opa/src/generated/java/org/apache/camel/component/opa/security/OpaSecurityPolicyConfigurer.java
@@ -47,6 +47,8 @@ public class OpaSecurityPolicyConfigurer extends
org.apache.camel.support.compon
case "includeHeaders": target.setIncludeHeaders(property(camelContext,
java.lang.String.class, value)); return true;
case "includeproperties":
case "includeProperties":
target.setIncludeProperties(property(camelContext, java.lang.String.class,
value)); return true;
+ case "inputexpression":
+ case "inputExpression":
target.setInputExpression(property(camelContext,
org.apache.camel.Expression.class, value)); return true;
case "opaclient":
case "opaClient": target.setOpaClient(property(camelContext,
com.styra.opa.OPAClient.class, value)); return true;
case "policybundle":
@@ -93,6 +95,8 @@ public class OpaSecurityPolicyConfigurer extends
org.apache.camel.support.compon
case "includeHeaders": return java.lang.String.class;
case "includeproperties":
case "includeProperties": return java.lang.String.class;
+ case "inputexpression":
+ case "inputExpression": return org.apache.camel.Expression.class;
case "opaclient":
case "opaClient": return com.styra.opa.OPAClient.class;
case "policybundle":
@@ -140,6 +144,8 @@ public class OpaSecurityPolicyConfigurer extends
org.apache.camel.support.compon
case "includeHeaders": return target.getIncludeHeaders();
case "includeproperties":
case "includeProperties": return target.getIncludeProperties();
+ case "inputexpression":
+ case "inputExpression": return target.getInputExpression();
case "opaclient":
case "opaClient": return target.getOpaClient();
case "policybundle":
diff --git
a/components/camel-opa/src/generated/resources/META-INF/org/apache/camel/component/opa/opa.json
b/components/camel-opa/src/generated/resources/META-INF/org/apache/camel/component/opa/opa.json
index 2fcbffcb3426..5d41c69a2137 100644
---
a/components/camel-opa/src/generated/resources/META-INF/org/apache/camel/component/opa/opa.json
+++
b/components/camel-opa/src/generated/resources/META-INF/org/apache/camel/component/opa/opa.json
@@ -39,15 +39,16 @@
"borrowTimeout": { "index": 12, "kind": "property", "displayName": "Borrow
Timeout", "group": "advanced", "label": "advanced", "required": false, "type":
"duration", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long an exchange waits for a free
WebAssembly policy instance in wasm mode before the e [...]
"connectionTimeout": { "index": 13, "kind": "property", "displayName":
"Connection Timeout", "group": "advanced", "label": "advanced", "required":
false, "type": "duration", "javaType": "long", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "10000",
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "How long to wait for the
connection to the OPA server to be established, in rest mo [...]
"healthCheckBundles": { "index": 14, "kind": "property", "displayName":
"Health Check Bundles", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "Whether the server
readiness check also requires activation of OPA's configured [...]
- "opaClient": { "index": 15, "kind": "property", "displayName": "Opa
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "com.styra.opa.OPAClient", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An existing OPAClient to use. When set,
serverUrl and bearerToken are ignored." },
- "poolSize": { "index": 16, "kind": "property", "displayName": "Pool Size",
"group": "advanced", "label": "advanced", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 8, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How many WebAssembly policy instances to pool
in wasm mode. An instance carries mutable state and is not thre [...]
- "requestTimeout": { "index": 17, "kind": "property", "displayName":
"Request Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long to wait for the decision once
connected, in rest mode. A request that times out [...]
- "healthCheckConsumerEnabled": { "index": 18, "kind": "property",
"displayName": "Health Check Consumer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all consumer based health checks
from this component" },
- "healthCheckProducerEnabled": { "index": 19, "kind": "property",
"displayName": "Health Check Producer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all producer based health checks
from this component. Notice: Camel has by default disabled all producer based
health-checks. You can turn on produce [...]
- "bearerToken": { "index": 20, "kind": "property", "displayName": "Bearer
Token", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Bearer token sent to the OPA server in the
Authorization header, for an OPA instance that [...]
- "failOpen": { "index": 21, "kind": "property", "displayName": "Fail Open",
"group": "security", "label": "security", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "security": "insecure:dev", "defaultValue": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Whether to allow the exchange to proceed when
the policy decision point i [...]
- "sslContextParameters": { "index": 22, "kind": "property", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "TLS configuration for the connection to the
OPA server in [...]
- "useGlobalSslContextParameters": { "index": 23, "kind": "property",
"displayName": "Use Global Ssl Context Parameters", "group": "security",
"label": "security", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Enable usage of global SSL context
parameters." }
+ "inputExpression": { "index": 15, "kind": "property", "displayName":
"Input Expression", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType": "org.apache.camel.Expression",
"deprecated": false, "autowired": false, "secret": false,
"supportSimpleExpression": true, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An expression producing the complete policy
input as a Map [...]
+ "opaClient": { "index": 16, "kind": "property", "displayName": "Opa
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "com.styra.opa.OPAClient", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An existing OPAClient to use. When set,
serverUrl and bearerToken are ignored." },
+ "poolSize": { "index": 17, "kind": "property", "displayName": "Pool Size",
"group": "advanced", "label": "advanced", "required": false, "type": "integer",
"javaType": "int", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": 8, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How many WebAssembly policy instances to pool
in wasm mode. An instance carries mutable state and is not thre [...]
+ "requestTimeout": { "index": 18, "kind": "property", "displayName":
"Request Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long to wait for the decision once
connected, in rest mode. A request that times out [...]
+ "healthCheckConsumerEnabled": { "index": 19, "kind": "property",
"displayName": "Health Check Consumer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all consumer based health checks
from this component" },
+ "healthCheckProducerEnabled": { "index": 20, "kind": "property",
"displayName": "Health Check Producer Enabled", "group": "health", "label":
"health", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Used for enabling or disabling all producer based health checks
from this component. Notice: Camel has by default disabled all producer based
health-checks. You can turn on produce [...]
+ "bearerToken": { "index": 21, "kind": "property", "displayName": "Bearer
Token", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Bearer token sent to the OPA server in the
Authorization header, for an OPA instance that [...]
+ "failOpen": { "index": 22, "kind": "property", "displayName": "Fail Open",
"group": "security", "label": "security", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "security": "insecure:dev", "defaultValue": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Whether to allow the exchange to proceed when
the policy decision point i [...]
+ "sslContextParameters": { "index": 23, "kind": "property", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "TLS configuration for the connection to the
OPA server in [...]
+ "useGlobalSslContextParameters": { "index": 24, "kind": "property",
"displayName": "Use Global Ssl Context Parameters", "group": "security",
"label": "security", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Enable usage of global SSL context
parameters." }
},
"headers": {
"CamelOpaDecisionAllow": { "index": 0, "kind": "header", "displayName":
"", "group": "producer", "label": "producer", "required": false, "javaType":
"Boolean", "deprecated": false, "autowired": false, "secret": false,
"description": "The allow\/deny verdict of the policy evaluation. Always
overwritten by the component, so a value set by an inbound message never
survives into the route.", "constantName":
"org.apache.camel.component.opa.OpaConstants#DECISION_ALLOW" },
@@ -76,11 +77,12 @@
"borrowTimeout": { "index": 11, "kind": "parameter", "displayName":
"Borrow Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long an exchange waits for a free
WebAssembly policy instance in wasm mode before the [...]
"connectionTimeout": { "index": 12, "kind": "parameter", "displayName":
"Connection Timeout", "group": "advanced", "label": "advanced", "required":
false, "type": "duration", "javaType": "long", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "10000",
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "How long to wait for the
connection to the OPA server to be established, in rest m [...]
"healthCheckBundles": { "index": 13, "kind": "parameter", "displayName":
"Health Check Bundles", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "Whether the server
readiness check also requires activation of OPA's configured [...]
- "opaClient": { "index": 14, "kind": "parameter", "displayName": "Opa
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "com.styra.opa.OPAClient", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An existing OPAClient to use. When set,
serverUrl and bearerToken are ignored." },
- "poolSize": { "index": 15, "kind": "parameter", "displayName": "Pool
Size", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 8, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How many WebAssembly policy instances to pool
in wasm mode. An instance carries mutable state and is not thr [...]
- "requestTimeout": { "index": 16, "kind": "parameter", "displayName":
"Request Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long to wait for the decision once
connected, in rest mode. A request that times out [...]
- "bearerToken": { "index": 17, "kind": "parameter", "displayName": "Bearer
Token", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Bearer token sent to the OPA server in the
Authorization header, for an OPA instance tha [...]
- "failOpen": { "index": 18, "kind": "parameter", "displayName": "Fail
Open", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "security": "insecure:dev", "defaultValue": false,
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "Whether to allow the
exchange to proceed when the policy decision point [...]
- "sslContextParameters": { "index": 19, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "TLS configuration for the connection to the
OPA server i [...]
+ "inputExpression": { "index": 14, "kind": "parameter", "displayName":
"Input Expression", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType": "org.apache.camel.Expression",
"deprecated": false, "autowired": false, "secret": false,
"supportSimpleExpression": true, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An expression producing the complete policy
input as a Ma [...]
+ "opaClient": { "index": 15, "kind": "parameter", "displayName": "Opa
Client", "group": "advanced", "label": "advanced", "required": false, "type":
"object", "javaType": "com.styra.opa.OPAClient", "deprecated": false,
"autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "An existing OPAClient to use. When set,
serverUrl and bearerToken are ignored." },
+ "poolSize": { "index": 16, "kind": "parameter", "displayName": "Pool
Size", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 8, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How many WebAssembly policy instances to pool
in wasm mode. An instance carries mutable state and is not thr [...]
+ "requestTimeout": { "index": 17, "kind": "parameter", "displayName":
"Request Timeout", "group": "advanced", "label": "advanced", "required": false,
"type": "duration", "javaType": "long", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "30000", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "How long to wait for the decision once
connected, in rest mode. A request that times out [...]
+ "bearerToken": { "index": 18, "kind": "parameter", "displayName": "Bearer
Token", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "Bearer token sent to the OPA server in the
Authorization header, for an OPA instance tha [...]
+ "failOpen": { "index": 19, "kind": "parameter", "displayName": "Fail
Open", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "security": "insecure:dev", "defaultValue": false,
"configurationClass": "org.apache.camel.component.opa.OpaConfiguration",
"configurationField": "configuration", "description": "Whether to allow the
exchange to proceed when the policy decision point [...]
+ "sslContextParameters": { "index": 20, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.opa.OpaConfiguration", "configurationField":
"configuration", "description": "TLS configuration for the connection to the
OPA server i [...]
}
}
diff --git
a/components/camel-opa/src/generated/resources/META-INF/services/org/apache/camel/bean/OpaSecurityPolicy.json
b/components/camel-opa/src/generated/resources/META-INF/services/org/apache/camel/bean/OpaSecurityPolicy.json
index d1504304e6d2..e63c588ce2ee 100644
---
a/components/camel-opa/src/generated/resources/META-INF/services/org/apache/camel/bean/OpaSecurityPolicy.json
+++
b/components/camel-opa/src/generated/resources/META-INF/services/org/apache/camel/bean/OpaSecurityPolicy.json
@@ -10,7 +10,7 @@
"groupId": "org.apache.camel",
"artifactId": "camel-opa",
"version": "4.24.0-SNAPSHOT",
- "properties": { "serverUrl": { "index": 0, "kind": "property",
"displayName": "Server Url", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "http:\/\/localhost:8181", "description": "The base URL of the
OPA server, without the \/v1\/data suffix. Not used in wasm mode." },
"policyPath": { "index": 1, "kind": "property", "displayName": "Policy Path",
"required": true, "type": "string", "javaT [...]
+ "properties": { "serverUrl": { "index": 0, "kind": "property",
"displayName": "Server Url", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "http:\/\/localhost:8181", "description": "The base URL of the
OPA server, without the \/v1\/data suffix. Not used in wasm mode." },
"policyPath": { "index": 1, "kind": "property", "displayName": "Policy Path",
"required": true, "type": "string", "javaT [...]
}
}
diff --git a/components/camel-opa/src/main/docs/opa-component.adoc
b/components/camel-opa/src/main/docs/opa-component.adoc
index f1d966bed6bc..13d20db8a0d4 100644
--- a/components/camel-opa/src/main/docs/opa-component.adoc
+++ b/components/camel-opa/src/main/docs/opa-component.adoc
@@ -241,6 +241,90 @@ conversion applies at depth.
The component's own `CamelOpa*` decision headers are never sent back to OPA,
so a policy cannot be shown a
verdict that an inbound message claimed for itself.
+=== Custom input expressions
+
+Set `inputExpression=#domainInput` to evaluate a configured Camel `Expression`
bean that produces the complete
+policy input. This replaces the default envelope in both REST and WASM modes,
and also applies to
+`OpaSecurityPolicy`. The expression result may be a `Map`, an object JSON
node, or a POJO supported by the
+component's Jackson JSON mapping. Nested maps, lists and POJOs are normalized
to JSON-native values; a top-level
+JSON string is not parsed implicitly. Null, scalar, array and streaming
results fail closed before the policy
+engine is called, even when `failOpen=true`.
+
+For example, take the verified identity from an exchange property the route
set after authentication, and only
+the domain payload from the body:
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+context.getRegistry().bind("domainInput", new ExpressionAdapter() {
+ @Override
+ public Object evaluate(Exchange exchange) {
+ return Map.of("subject", exchange.getProperty("verifiedSubject"),
+ "order", exchange.getMessage().getBody());
+ }
+});
+
+from("direct:orders")
+ .to("opa:authz/orders/allow?inputExpression=#domainInput");
+----
+
+XML::
++
+[source,xml]
+----
+<!-- a small Expression class of the application, with the evaluate(Exchange)
method of the Java tab -->
+<bean id="domainInput" class="com.example.orders.DomainInputExpression"/>
+
+<camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:orders"/>
+ <to uri="opa:authz/orders/allow?inputExpression=#domainInput"/>
+ </route>
+</camelContext>
+----
+
+YAML::
++
+[source,yaml]
+----
+- beans:
+ # a small Expression class of the application, with the evaluate(Exchange)
method of the Java tab
+ - name: domainInput
+ type: com.example.orders.DomainInputExpression
+- route:
+ from:
+ uri: direct:orders
+ steps:
+ - to:
+ uri: opa:authz/orders/allow
+ parameters:
+ inputExpression: "#domainInput"
+----
+====
+
+WARNING: The body comes from the sender. Do not make it the whole input, and
never let it supply the identity or
+role fields the policy reads: a sender who posts `{"subject": "admin"}` would
write straight into them. Take the
+identity from an exchange property the route verified, as
<<authorizing-an-identity>> describes, and put the
+sender's data under a key of its own.
+
+The `includeHeaders`, `includeProperties` and `includeBody` options configure
only the default envelope; they do
+not add or filter fields in a custom input. The expression decides what to
include, so select verified identity
+and application data deliberately. The default envelope withholds the headers
that carry a credential verbatim
+(`Authorization`, `Proxy-Authorization`, `Cookie` and `Set-Cookie`); a custom
expression gets none of that
+protection, so copy headers selectively and leave those out. Decision headers
are still cleared before mapping.
+Custom expression beans must support concurrent evaluation. For a single
exchange the expression runs on the live
+exchange, so a header or property it sets stays on the exchange; in batch mode
it runs on a copy, as described
+below.
+
+In batch mode, the expression is evaluated once per element against an
exchange copy whose body is that element.
+Headers and properties remain available to the expression, while the route's
original List body is preserved.
+The expression must produce one JSON object per element; a mapping failure
stops the batch before calling OPA.
+The component does not consume streams automatically. If an expression
explicitly reads a stream, configure
+stream caching or handle its lifetime in the route.
+
== Reading the verdict
`CamelOpaDecision` holds the decision document exactly as OPA returned it.
`CamelOpaDecisionAllow` holds the
diff --git
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaConfiguration.java
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaConfiguration.java
index 4d6c8c67d067..1c789eb42780 100644
---
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaConfiguration.java
+++
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaConfiguration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.opa;
import com.styra.opa.OPAClient;
+import org.apache.camel.Expression;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
@@ -43,6 +44,13 @@ public class OpaConfiguration implements Cloneable {
@UriParam
private boolean includeBody;
+ @UriParam(label = "advanced",
+ description = "An expression producing the complete policy input
as a Map, object JSON node or POJO."
+ + " Replaces the default input envelope;
includeHeaders, includeProperties and includeBody"
+ + " then do not apply. In batch mode it sees each
element as the body on an exchange copy."
+ + " Null, scalar and streaming results fail
closed. Reference a configured expression bean.")
+ private Expression inputExpression;
+
@UriParam(label = "security", security = "secret")
private String bearerToken;
@@ -85,6 +93,19 @@ public class OpaConfiguration implements Cloneable {
@Metadata(autowired = true)
private OPAClient opaClient;
+ public Expression getInputExpression() {
+ return inputExpression;
+ }
+
+ /**
+ * An expression producing the complete policy input. Replaces the default
envelope and its inclusion options. The
+ * result must be a Map, object JSON node or JSON-convertible POJO. In a
batch the expression sees each element as
+ * the body on an exchange copy. Null, scalar and streaming results fail
closed.
+ */
+ public void setInputExpression(Expression inputExpression) {
+ this.inputExpression = inputExpression;
+ }
+
/**
* The base URL of the OPA server, without the {@code /v1/data} suffix.
The default assumes OPA running as a sidecar
* on the standard port.
diff --git
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaEndpoint.java
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaEndpoint.java
index f941042acd8c..05ac17ed0994 100644
---
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaEndpoint.java
+++
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaEndpoint.java
@@ -82,6 +82,9 @@ public class OpaEndpoint extends DefaultEndpoint {
@Override
protected void doStart() throws Exception {
super.doStart();
+ if (configuration.getInputExpression() != null) {
+ configuration.getInputExpression().init(getCamelContext());
+ }
String mode = configuration.getEvaluationMode();
if (WASM_MODE.equalsIgnoreCase(mode)) {
if (configuration.isBatch()) {
@@ -103,7 +106,7 @@ public class OpaEndpoint extends DefaultEndpoint {
evaluator = new OpaRestEvaluator(
opaClient, null, policyPath,
configuration.getAllowKey(), configuration.getIncludeHeaders(),
configuration.getIncludeProperties(),
configuration.isIncludeBody(),
- configuration.isFailOpen());
+ configuration.isFailOpen(),
configuration.getInputExpression());
} else {
sslContext = createSslContext();
OpaHttpClient transport = OpaRestEvaluator.createTransport(
@@ -115,7 +118,7 @@ public class OpaEndpoint extends DefaultEndpoint {
opaClient, transport, policyPath,
configuration.getAllowKey(),
configuration.getIncludeHeaders(),
configuration.getIncludeProperties(),
configuration.isIncludeBody(),
- configuration.isFailOpen());
+ configuration.isFailOpen(),
configuration.getInputExpression());
}
}
}
@@ -172,7 +175,7 @@ public class OpaEndpoint extends DefaultEndpoint {
getCamelContext(), configuration.getPolicyBundle(),
configuration.getEntrypoint(),
configuration.getPoolSize(), configuration.getBorrowTimeout(),
policyPath, configuration.getAllowKey(),
configuration.getIncludeHeaders(),
configuration.getIncludeProperties(), configuration.isIncludeBody(),
- configuration.isFailOpen());
+ configuration.isFailOpen(),
configuration.getInputExpression());
}
@Override
diff --git
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java
index 1e20ad88f96e..988d3b1d582d 100644
---
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java
+++
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaPolicyEvaluator.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.opa;
+import java.io.InputStream;
+import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -25,7 +27,11 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicBoolean;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
import org.apache.camel.Message;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
@@ -42,6 +48,9 @@ public abstract class OpaPolicyEvaluator {
private static final Logger LOG =
LoggerFactory.getLogger(OpaPolicyEvaluator.class);
private static final String ALL_NAMES = "*";
+ private static final ObjectMapper INPUT_MAPPER = new ObjectMapper();
+ private static final TypeReference<Map<String, Object>> INPUT_TYPE = new
TypeReference<>() {
+ };
/**
* Headers that carry a caller credential verbatim. They are withheld when
{@code includeHeaders} is the wildcard,
@@ -56,10 +65,16 @@ public abstract class OpaPolicyEvaluator {
private final Set<String> includedProperties;
private final boolean includeBody;
private final boolean failOpen;
+ private final Expression inputExpression;
private final AtomicBoolean unreadableVerdictWarned = new AtomicBoolean();
protected OpaPolicyEvaluator(String policyPath, String allowKey, String
includeHeaders,
String includeProperties, boolean
includeBody, boolean failOpen) {
+ this(policyPath, allowKey, includeHeaders, includeProperties,
includeBody, failOpen, null);
+ }
+
+ protected OpaPolicyEvaluator(String policyPath, String allowKey, String
includeHeaders,
+ String includeProperties, boolean
includeBody, boolean failOpen, Expression inputExpression) {
this.policyPath = ObjectHelper.notNull(policyPath, "policyPath");
this.allowKey = ObjectHelper.isNotEmpty(allowKey) ? allowKey : "allow";
// headers default to all of them, exchange properties to none:
properties are mostly used to carry
@@ -68,6 +83,7 @@ public abstract class OpaPolicyEvaluator {
this.includedProperties = parseNameFilter(includeProperties, false);
this.includeBody = includeBody;
this.failOpen = failOpen;
+ this.inputExpression = inputExpression;
}
/**
@@ -83,9 +99,16 @@ public abstract class OpaPolicyEvaluator {
// what this component decided. Overwriting at the end is not enough:
the paths that throw never get there,
// and a route that handles the exception would resume routing with
the sender's own verdict still on it
clearDecisionHeaders(exchange);
+ Map<String, Object> input;
+ try {
+ input = buildInput(exchange);
+ } catch (Exception e) {
+ restoreInterruptIfWrapped(e);
+ throw new OpaPolicyEvaluationException("Failed to build input for
policy " + policyPath, exchange, e);
+ }
Object decision;
try {
- decision = evaluateDecision(buildInput(exchange));
+ decision = evaluateDecision(input);
} catch (InterruptedException e) {
// not a policy failure but a shutdown, so failOpen must not turn
it into an allow: nothing decided
// that this exchange was permitted. Restore the flag the
interruptible wait cleared, then fail closed.
@@ -198,8 +221,13 @@ public abstract class OpaPolicyEvaluator {
return verdicts;
}
Map<String, Map<String, Object>> inputs = new LinkedHashMap<>();
- for (int i = 0; i < elements.size(); i++) {
- inputs.put(Integer.toString(i), buildInput(exchange,
elements.get(i), true));
+ try {
+ for (int i = 0; i < elements.size(); i++) {
+ inputs.put(Integer.toString(i), buildInput(exchange,
elements.get(i), true));
+ }
+ } catch (Exception e) {
+ restoreInterruptIfWrapped(e);
+ throw new OpaPolicyEvaluationException("Failed to build batch
input for policy " + policyPath, exchange, e);
}
List<OpaBatchOutcome> outcomes = new ArrayList<>(elements.size());
@@ -300,6 +328,9 @@ public abstract class OpaPolicyEvaluator {
* Builds the {@code input} document handed to OPA.
*/
protected Map<String, Object> buildInput(Exchange exchange) {
+ if (inputExpression != null) {
+ return mappedInput(exchange);
+ }
return buildInput(exchange, exchange.getMessage().getBody(),
includeBody);
}
@@ -308,6 +339,11 @@ public abstract class OpaPolicyEvaluator {
* the element as the body so every element is authorized against the same
shared headers and properties.
*/
protected Map<String, Object> buildInput(Exchange exchange, Object body,
boolean withBody) {
+ if (inputExpression != null) {
+ Exchange element = exchange.copy();
+ element.getMessage().setBody(body);
+ return mappedInput(element);
+ }
Map<String, Object> input = new LinkedHashMap<>();
Map<String, Object> headers = new LinkedHashMap<>();
for (Map.Entry<String, Object> entry :
exchange.getMessage().getHeaders().entrySet()) {
@@ -350,6 +386,19 @@ public abstract class OpaPolicyEvaluator {
return input;
}
+ private Map<String, Object> mappedInput(Exchange exchange) {
+ Object value = inputExpression.evaluate(exchange, Object.class);
+ if (value == null || value instanceof InputStream || value instanceof
Reader) {
+ throw new IllegalArgumentException("inputExpression must produce a
JSON object, not a null or streaming value");
+ }
+ JsonNode node = INPUT_MAPPER.valueToTree(value);
+ if (!node.isObject()) {
+ throw new IllegalArgumentException(
+ "inputExpression must produce a JSON object, but was " +
value.getClass().getName());
+ }
+ return INPUT_MAPPER.convertValue(node, INPUT_TYPE);
+ }
+
/**
* Reads the allow/deny verdict out of the decision document.
* <p/>
diff --git
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaRestEvaluator.java
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaRestEvaluator.java
index 2116e6ae0270..6cb0e9412dc9 100644
---
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaRestEvaluator.java
+++
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaRestEvaluator.java
@@ -29,6 +29,7 @@ import com.styra.opa.openapi.models.errors.AuthException;
import com.styra.opa.openapi.models.errors.ClientError;
import com.styra.opa.openapi.models.errors.SDKError;
import com.styra.opa.openapi.models.errors.ServerError;
+import org.apache.camel.Expression;
import org.apache.camel.util.ObjectHelper;
/**
@@ -42,7 +43,13 @@ public class OpaRestEvaluator extends OpaPolicyEvaluator
implements AutoCloseabl
public OpaRestEvaluator(OPAClient client, OpaHttpClient transport, String
policyPath, String allowKey,
String includeHeaders,
String includeProperties, boolean includeBody,
boolean failOpen) {
- super(policyPath, allowKey, includeHeaders, includeProperties,
includeBody, failOpen);
+ this(client, transport, policyPath, allowKey, includeHeaders,
includeProperties, includeBody, failOpen, null);
+ }
+
+ public OpaRestEvaluator(OPAClient client, OpaHttpClient transport, String
policyPath, String allowKey,
+ String includeHeaders, String includeProperties,
boolean includeBody, boolean failOpen,
+ Expression inputExpression) {
+ super(policyPath, allowKey, includeHeaders, includeProperties,
includeBody, failOpen, inputExpression);
this.client = ObjectHelper.notNull(client, "client");
this.transport = transport;
}
diff --git
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaWasmEvaluator.java
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaWasmEvaluator.java
index b10d52dc4cff..7e909b0b2f50 100644
---
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaWasmEvaluator.java
+++
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/OpaWasmEvaluator.java
@@ -26,6 +26,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.styra.opa.wasm.OpaPolicy;
import org.apache.camel.CamelContext;
+import org.apache.camel.Expression;
import org.apache.camel.support.ResourceHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@@ -51,7 +52,14 @@ public class OpaWasmEvaluator extends OpaPolicyEvaluator
implements AutoCloseabl
public OpaWasmEvaluator(byte[] wasm, String data, String entrypoint, int
poolSize, long borrowTimeout,
String policyPath, String allowKey, String
includeHeaders, String includeProperties,
boolean includeBody, boolean failOpen) {
- super(policyPath, allowKey, includeHeaders, includeProperties,
includeBody, failOpen);
+ this(wasm, data, entrypoint, poolSize, borrowTimeout, policyPath,
allowKey, includeHeaders, includeProperties,
+ includeBody, failOpen, null);
+ }
+
+ public OpaWasmEvaluator(byte[] wasm, String data, String entrypoint, int
poolSize, long borrowTimeout,
+ String policyPath, String allowKey, String
includeHeaders, String includeProperties,
+ boolean includeBody, boolean failOpen, Expression
inputExpression) {
+ super(policyPath, allowKey, includeHeaders, includeProperties,
includeBody, failOpen, inputExpression);
this.entrypoint = entrypoint;
this.data = data;
// OpaPolicy carries mutable input/data and is not thread-safe, while
a Camel producer is invoked
@@ -105,6 +113,15 @@ public class OpaWasmEvaluator extends OpaPolicyEvaluator
implements AutoCloseabl
String policyPath, String allowKey, String includeHeaders, String
includeProperties, boolean includeBody,
boolean failOpen)
throws Exception {
+ return create(camelContext, policyBundle, entrypoint, poolSize,
borrowTimeout, policyPath, allowKey,
+ includeHeaders, includeProperties, includeBody, failOpen,
null);
+ }
+
+ public static OpaWasmEvaluator create(
+ CamelContext camelContext, String policyBundle, String entrypoint,
int poolSize, long borrowTimeout,
+ String policyPath, String allowKey, String includeHeaders, String
includeProperties, boolean includeBody,
+ boolean failOpen, Expression inputExpression)
+ throws Exception {
if (ObjectHelper.isEmpty(policyBundle)) {
throw new IllegalArgumentException(
"policyBundle is required when evaluationMode=wasm; build
one with"
@@ -119,7 +136,7 @@ public class OpaWasmEvaluator extends OpaPolicyEvaluator
implements AutoCloseabl
Bundle bundle = loadPolicy(camelContext, policyBundle);
return new OpaWasmEvaluator(
bundle.wasm(), bundle.data(), resolvedEntrypoint, poolSize,
borrowTimeout, policyPath, allowKey,
- includeHeaders, includeProperties, includeBody, failOpen);
+ includeHeaders, includeProperties, includeBody, failOpen,
inputExpression);
}
/**
diff --git
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/security/OpaSecurityPolicy.java
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/security/OpaSecurityPolicy.java
index 7b21e2aeed4d..330d8317b285 100644
---
a/components/camel-opa/src/main/java/org/apache/camel/component/opa/security/OpaSecurityPolicy.java
+++
b/components/camel-opa/src/main/java/org/apache/camel/component/opa/security/OpaSecurityPolicy.java
@@ -23,6 +23,7 @@ import javax.net.ssl.SSLContext;
import com.styra.opa.OPAClient;
import org.apache.camel.CamelContext;
+import org.apache.camel.Expression;
import org.apache.camel.NamedNode;
import org.apache.camel.Processor;
import org.apache.camel.Route;
@@ -94,6 +95,11 @@ public class OpaSecurityPolicy implements
AuthorizationPolicy {
@Metadata(defaultValue = "false",
description = "Whether to send the message body to OPA as part
of the input document.")
private boolean includeBody;
+ @Metadata(label = "advanced",
+ description = "An expression producing the complete policy input
as a Map, object JSON node or POJO."
+ + " Replaces the default input envelope and its
includeHeaders, includeProperties and"
+ + " includeBody options. Null, scalar and
streaming results fail closed.")
+ private Expression inputExpression;
@Metadata(label = "security", security = "secret",
description = "Bearer token sent to the OPA server in the
Authorization header, for an OPA instance that"
+ " has its API authentication enabled. Not used
in wasm mode.")
@@ -204,11 +210,14 @@ public class OpaSecurityPolicy implements
AuthorizationPolicy {
* engine runs.
*/
private OpaPolicyEvaluator buildEvaluator(CamelContext camelContext) {
+ if (inputExpression != null) {
+ inputExpression.init(camelContext);
+ }
if (WASM_MODE.equalsIgnoreCase(evaluationMode)) {
warnIgnoredServerOptions();
try {
return OpaWasmEvaluator.create(camelContext, policyBundle,
entrypoint, poolSize, borrowTimeout,
- policyPath, allowKey, includeHeaders,
includeProperties, includeBody, failOpen);
+ policyPath, allowKey, includeHeaders,
includeProperties, includeBody, failOpen, inputExpression);
} catch (RuntimeException e) {
// the validation messages (policyBundle, poolSize) already
read correctly; do not bury them
throw e;
@@ -229,7 +238,8 @@ public class OpaSecurityPolicy implements
AuthorizationPolicy {
ownsClient = true;
}
return new OpaRestEvaluator(
- opaClient, transport, policyPath, allowKey, includeHeaders,
includeProperties, includeBody, failOpen);
+ opaClient, transport, policyPath, allowKey, includeHeaders,
includeProperties, includeBody, failOpen,
+ inputExpression);
}
/**
@@ -319,6 +329,18 @@ public class OpaSecurityPolicy implements
AuthorizationPolicy {
return evaluator;
}
+ public Expression getInputExpression() {
+ return inputExpression;
+ }
+
+ /**
+ * An expression producing the complete input as a Map, object JSON node
or JSON-convertible POJO. Replaces the
+ * default envelope and its inclusion options. Null, scalar and streaming
results fail closed.
+ */
+ public void setInputExpression(Expression inputExpression) {
+ this.inputExpression = inputExpression;
+ }
+
public String getServerUrl() {
return serverUrl;
}
diff --git
a/components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaInputExpressionTest.java
b/components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaInputExpressionTest.java
new file mode 100644
index 000000000000..39ec34049550
--- /dev/null
+++
b/components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaInputExpressionTest.java
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.opa;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.styra.opa.OPAClient;
+import com.styra.opa.OPAResult;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.opa.security.OpaSecurityPolicy;
+import org.apache.camel.support.ExpressionAdapter;
+import org.apache.camel.support.builder.ExpressionBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class OpaInputExpressionTest extends CamelTestSupport {
+
+ private static final String PATH = "authz/allow";
+
+ @BindToRegistry("opaClient")
+ private final OPAClient client = mock(OPAClient.class);
+
+ private OpaEndpoint endpoint(Expression expression, boolean batch, boolean
failOpen) throws Exception {
+ OpaConfiguration configuration = new OpaConfiguration();
+ configuration.setOpaClient(client);
+ configuration.setInputExpression(expression);
+ configuration.setBatch(batch);
+ configuration.setFailOpen(failOpen);
+ OpaEndpoint endpoint = new OpaEndpoint("opa:" + PATH, new
OpaComponent(context), configuration);
+ endpoint.setPolicyPath(PATH);
+ context.addService(endpoint);
+ endpoint.start();
+ return endpoint;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, Object> capturedInput() throws Exception {
+ ArgumentCaptor<Map<String, Object>> captor =
ArgumentCaptor.forClass(Map.class);
+ verify(client).evaluate(eq(PATH), captor.capture(), eq(Object.class));
+ return captor.getValue();
+ }
+
+ @Test
+ void sendsTheCompleteDomainInputWithoutTheDefaultEnvelope() throws
Exception {
+ when(client.evaluate(eq(PATH), anyMap(),
eq(Object.class))).thenReturn(Boolean.TRUE);
+ Map<String, Object> input = Map.of("subject", "alice", "order",
Map.of("id", 42, "lines", List.of("a", "b")));
+
+ Exchange out =
template.request(endpoint(ExpressionBuilder.bodyExpression(), false, false), e
-> {
+ e.getMessage().setBody(input);
+ e.getMessage().setHeader("ignored-by-custom-mapping", "value");
+ });
+
+ assertThat(out.getException()).isNull();
+
assertThat(capturedInput()).isEqualTo(input).doesNotContainKeys("headers",
"body", "exchangeId");
+ assertThat(out.getMessage().getBody()).isSameAs(input);
+ }
+
+ @Test
+ void convertsPojoAndNestedValuesToJsonObjects() throws Exception {
+ when(client.evaluate(eq(PATH), anyMap(),
eq(Object.class))).thenReturn(Boolean.TRUE);
+ Order order = new Order("alice", new OrderDetails(42, List.of("a",
"b")));
+
+ Exchange out =
template.request(endpoint(ExpressionBuilder.bodyExpression(), false, false),
+ e -> e.getMessage().setBody(order));
+
+ assertThat(out.getException()).isNull();
+ assertThat(capturedInput()).containsEntry("subject", "alice")
+ .containsEntry("order", Map.of("id", 42, "lines", List.of("a",
"b")));
+ assertThat(out.getMessage().getBody()).isSameAs(order);
+ }
+
+ @Test
+ void rejectsNullScalarAndStreamingResultsEvenUnderFailOpen() throws
Exception {
+ ByteArrayInputStream stream = new ByteArrayInputStream(new byte[] { 1,
2, 3 });
+ for (Object input : Arrays.asList(null, "not a JSON object",
List.of("not", "an", "object"), stream)) {
+ Exchange out =
template.request(endpoint(ExpressionBuilder.bodyExpression(), false, true),
+ e -> e.getMessage().setBody(input));
+
+
assertThat(out.getException()).isInstanceOf(OpaPolicyEvaluationException.class)
+ .hasMessageContaining("Failed to build input");
+
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_ALLOW)).isNull();
+
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isNull();
+ }
+ assertThat(stream.available()).as("mapping did not consume the
rejected stream").isEqualTo(3);
+ verify(client, never()).evaluate(anyString(), anyMap(),
eq(Object.class));
+ }
+
+ @Test
+ void treatsMappingFailureSeparatelyFromDecisionPointUnavailability()
throws Exception {
+ Expression broken = new ExpressionAdapter() {
+ @Override
+ public Object evaluate(Exchange exchange) {
+ throw new IllegalStateException("Could not map input", new
IOException("local data unavailable"));
+ }
+ };
+ for (boolean batch : List.of(false, true)) {
+ Exchange out = template.request(endpoint(broken, batch, true),
+ e -> e.getMessage().setBody(List.of("a")));
+
+
assertThat(out.getException()).isInstanceOf(OpaPolicyEvaluationException.class)
+ .hasMessageContaining("build");
+
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isNull();
+
assertThat(out.getMessage().getHeader(OpaConstants.BATCH_DECISION)).isNull();
+ }
+ verify(client, never()).evaluate(anyString(), anyMap(),
eq(Object.class));
+ verify(client, never()).evaluateBatch(anyString(), anyMap());
+ }
+
+ @Test
+ void mapsEachBatchBodyOnAnExchangeCopy() throws Exception {
+ when(client.evaluateBatch(eq(PATH), anyMap())).thenReturn(
+ Map.of("0", new OPAResult(true), "1", new OPAResult(false)));
+ Expression input = new ExpressionAdapter() {
+ @Override
+ public Object evaluate(Exchange exchange) {
+ exchange.getMessage().setHeader("mapper-state", "local to this
element");
+ return Map.of("subject",
exchange.getProperty("verifiedSubject"), "order",
exchange.getMessage().getBody());
+ }
+ };
+ List<Map<String, Integer>> orders = List.of(Map.of("id", 1),
Map.of("id", 2));
+
+ Exchange out = template.request(endpoint(input, true, false), e -> {
+ e.setProperty("verifiedSubject", "alice");
+ e.getMessage().setBody(orders);
+ });
+
+ assertThat(out.getException()).isNull();
+ assertThat(out.getMessage().getBody()).isSameAs(orders);
+ assertThat(out.getMessage().getHeader("mapper-state")).isNull();
+ @SuppressWarnings("unchecked")
+ ArgumentCaptor<Map<String, Object>> captor =
ArgumentCaptor.forClass(Map.class);
+ verify(client).evaluateBatch(eq(PATH), captor.capture());
+
assertThat(captor.getValue()).containsExactlyInAnyOrderEntriesOf(Map.of(
+ "0", Map.of("subject", "alice", "order", Map.of("id", 1)),
+ "1", Map.of("subject", "alice", "order", Map.of("id", 2))));
+ assertThat(out.getMessage().getHeader(OpaConstants.BATCH_DECISION,
List.class)).containsExactly(true, false);
+ }
+
+ @Test
+ void rejectsAnInvalidBatchElementBeforeCallingOpa() throws Exception {
+ List<Object> elements = Arrays.asList(Map.of("subject", "alice"),
null);
+
+ Exchange out =
template.request(endpoint(ExpressionBuilder.bodyExpression(), true, true),
+ e -> e.getMessage().setBody(elements));
+
+
assertThat(out.getException()).isInstanceOf(OpaPolicyEvaluationException.class)
+ .hasMessageContaining("Failed to build batch input");
+ assertThat(out.getMessage().getBody()).isSameAs(elements);
+
assertThat(out.getMessage().getHeader(OpaConstants.BATCH_DECISION)).isNull();
+
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_FAILED_OPEN)).isNull();
+ verify(client, never()).evaluateBatch(anyString(), anyMap());
+ }
+
+ @Test
+ void normalizesAnObjectJsonNode() throws Exception {
+ when(client.evaluate(eq(PATH), anyMap(),
eq(Object.class))).thenReturn(Boolean.TRUE);
+ var input = new ObjectMapper().createObjectNode().put("subject",
"alice");
+
+ Exchange out =
template.request(endpoint(ExpressionBuilder.bodyExpression(), false, false),
+ e -> e.getMessage().setBody(input));
+
+ assertThat(out.getException()).isNull();
+
assertThat(capturedInput()).containsOnlyKeys("subject").containsEntry("subject",
"alice");
+ assertThat(out.getMessage().getBody()).isSameAs(input);
+ }
+
+ @Test
+ void initializesTheExpressionBeforeTheFirstEvaluation() throws Exception {
+ AtomicBoolean initialized = new AtomicBoolean();
+ Expression expression = new ExpressionAdapter() {
+ @Override
+ public void init(CamelContext camelContext) {
+ initialized.set(true);
+ }
+
+ @Override
+ public Object evaluate(Exchange exchange) {
+ assertThat(initialized).isTrue();
+ return Map.of("subject", "alice");
+ }
+ };
+ when(client.evaluate(eq(PATH), anyMap(),
eq(Object.class))).thenReturn(Boolean.TRUE);
+
+ Exchange out = template.request(endpoint(expression, false, false), e
-> {
+ });
+
+ assertThat(initialized).isTrue();
+ assertThat(out.getException()).isNull();
+ }
+
+ @Test
+ void usesTheSameMappingThroughASecurityPolicy() throws Exception {
+ when(client.evaluate(eq(PATH), anyMap(),
eq(Object.class))).thenReturn(Boolean.TRUE);
+ OpaSecurityPolicy policy = new OpaSecurityPolicy();
+ policy.setPolicyPath(PATH);
+ policy.setOpaClient(client);
+ policy.setInputExpression(ExpressionBuilder.bodyExpression());
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:mapped-policy").policy(policy).to("mock:mapped-result");
+ }
+ });
+
+ Exchange out = template.request("direct:mapped-policy", e ->
e.getMessage().setBody(Map.of("subject", "alice")));
+
+ assertThat(out.getException()).isNull();
+
assertThat(capturedInput()).containsOnlyKeys("subject").containsEntry("subject",
"alice");
+ assertThat(out.getMessage().getBody()).isEqualTo(Map.of("subject",
"alice"));
+ }
+
+ public record Order(String subject, OrderDetails order) {
+ }
+
+ public record OrderDetails(int id, List<String> lines) {
+ }
+}
diff --git
a/components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaWasmIT.java
b/components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaWasmIT.java
index cf04bd992006..34626c7fbe27 100644
---
a/components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaWasmIT.java
+++
b/components/camel-opa/src/test/java/org/apache/camel/component/opa/OpaWasmIT.java
@@ -34,6 +34,7 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.health.HealthCheck;
import org.apache.camel.health.HealthCheckHelper;
import org.apache.camel.health.WritableHealthCheckRepository;
+import org.apache.camel.support.builder.ExpressionBuilder;
import org.apache.camel.test.infra.opa.services.OpaWasmBundleBuilder;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@@ -165,6 +166,19 @@ public class OpaWasmIT extends CamelTestSupport {
})).doesNotThrowAnyException();
}
+ @Test
+ void evaluatesTheCustomInputInsteadOfTheDefaultEnvelope() {
+ context.getRegistry().bind("domainInput",
ExpressionBuilder.bodyExpression());
+ Map<String, Object> input = Map.of("headers", Map.of("user", "alice"));
+
+ Exchange out = template.request(wasm("authz/allow") +
"&inputExpression=#domainInput",
+ e -> e.getMessage().setBody(input));
+
+ assertThat(out.getException()).isNull();
+
assertThat(out.getMessage().getHeader(OpaConstants.DECISION_ALLOW)).isEqualTo(true);
+ assertThat(out.getMessage().getBody()).isSameAs(input);
+ }
+
@Test
void allowsWhenThePolicyMatches() {
Exchange out = template.request(wasm("authz/allow"), e ->
e.getMessage().setHeader("user", "alice"));
diff --git
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/OpaComponentBuilderFactory.java
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/OpaComponentBuilderFactory.java
index 87e1e159cc36..3d7e2a738466 100644
---
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/OpaComponentBuilderFactory.java
+++
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/OpaComponentBuilderFactory.java
@@ -375,6 +375,27 @@ public interface OpaComponentBuilderFactory {
return this;
}
+ /**
+ * An expression producing the complete policy input as a Map, object
+ * JSON node or POJO. Replaces the default input envelope;
+ * includeHeaders, includeProperties and includeBody then do not apply.
+ * In batch mode it sees each element as the body on an exchange copy.
+ * Null, scalar and streaming results fail closed. Reference a
+ * configured expression bean.
+ *
+ * The option is a:
<code>org.apache.camel.Expression</code>
+ * type.
+ *
+ * Group: advanced
+ *
+ * @param inputExpression the value to set
+ * @return the dsl builder
+ */
+ default OpaComponentBuilder
inputExpression(org.apache.camel.Expression inputExpression) {
+ doSetProperty("inputExpression", inputExpression);
+ return this;
+ }
+
/**
* An existing OPAClient to use. When set, serverUrl and bearerToken
are
* ignored.
@@ -583,6 +604,7 @@ public interface OpaComponentBuilderFactory {
case "borrowTimeout": getOrCreateConfiguration((OpaComponent)
component).setBorrowTimeout((long) value); return true;
case "connectionTimeout": getOrCreateConfiguration((OpaComponent)
component).setConnectionTimeout((long) value); return true;
case "healthCheckBundles": getOrCreateConfiguration((OpaComponent)
component).setHealthCheckBundles((boolean) value); return true;
+ case "inputExpression": getOrCreateConfiguration((OpaComponent)
component).setInputExpression((org.apache.camel.Expression) value); return true;
case "opaClient": getOrCreateConfiguration((OpaComponent)
component).setOpaClient((com.styra.opa.OPAClient) value); return true;
case "poolSize": getOrCreateConfiguration((OpaComponent)
component).setPoolSize((int) value); return true;
case "requestTimeout": getOrCreateConfiguration((OpaComponent)
component).setRequestTimeout((long) value); return true;
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpaEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpaEndpointBuilderFactory.java
index 5a2e8f2ebf7b..7b99e67f891a 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpaEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/OpaEndpointBuilderFactory.java
@@ -541,6 +541,45 @@ public interface OpaEndpointBuilderFactory {
doSetProperty("healthCheckBundles", healthCheckBundles);
return this;
}
+ /**
+ * An expression producing the complete policy input as a Map, object
+ * JSON node or POJO. Replaces the default input envelope;
+ * includeHeaders, includeProperties and includeBody then do not apply.
+ * In batch mode it sees each element as the body on an exchange copy.
+ * Null, scalar and streaming results fail closed. Reference a
+ * configured expression bean.
+ *
+ * The option is a: <code>org.apache.camel.Expression</code> type.
+ *
+ * Group: advanced
+ *
+ * @param inputExpression the value to set
+ * @return the dsl builder
+ */
+ default AdvancedOpaEndpointBuilder
inputExpression(org.apache.camel.Expression inputExpression) {
+ doSetProperty("inputExpression", inputExpression);
+ return this;
+ }
+ /**
+ * An expression producing the complete policy input as a Map, object
+ * JSON node or POJO. Replaces the default input envelope;
+ * includeHeaders, includeProperties and includeBody then do not apply.
+ * In batch mode it sees each element as the body on an exchange copy.
+ * Null, scalar and streaming results fail closed. Reference a
+ * configured expression bean.
+ *
+ * The option will be converted to a
+ * <code>org.apache.camel.Expression</code> type.
+ *
+ * Group: advanced
+ *
+ * @param inputExpression the value to set
+ * @return the dsl builder
+ */
+ default AdvancedOpaEndpointBuilder inputExpression(String
inputExpression) {
+ doSetProperty("inputExpression", inputExpression);
+ return this;
+ }
/**
* An existing OPAClient to use. When set, serverUrl and bearerToken
are
* ignored.