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 bf3756bcc8a1 CAMEL-28022: camel-cedar - a fractional number in the 
context or entity data gives an ERROR outcome (#31259)
bf3756bcc8a1 is described below

commit bf3756bcc8a160cc8dce918e193a1d568883c344
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Dec 3 14:26:46 2026 +0100

    CAMEL-28022: camel-cedar - a fractional number in the context or entity 
data gives an ERROR outcome (#31259)
    
    * CAMEL-28022: camel-cedar - a fractional number in the context or entity 
data gives an ERROR outcome
      Cedar has no floating-point type and represents every whole number as a
      Long, so a number with a fractional part was converted to a whole number.
      Such a value now gives the ERROR outcome instead, for both the context
      expression result and the entity JSON of a CedarEntityProvider. A
      whole-valued number such as 100 or 100.0 and a Cedar Decimal, whose digits
      are carried as a string, are unaffected.
    * CAMEL-28022: camel-cedar - check the static entities for fractional 
numbers as well
      The static entities of entitiesResource went through the same Cedar
      value deserializer without the check, so a number with a fractional
      part in them was still truncated to a whole number. The entities JSON,
      static or from a CedarEntityProvider, is now read once and checked
      before the entities are bound from that same tree: such a number fails
      the load, so the start fails and a reload keeps the active revision.
      An empty entities document is rejected explicitly. The option
      descriptions and the upgrade note say truncated.
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
    Signed-off-by: Andrea Cosentino <[email protected]>
    Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
 .../camel/catalog/beans/CedarSecurityPolicy.json   |   2 +-
 .../org/apache/camel/catalog/components/cedar.json |   6 +-
 .../org/apache/camel/component/cedar/cedar.json    |   6 +-
 .../org/apache/camel/bean/CedarSecurityPolicy.json |   2 +-
 .../camel/component/cedar/CedarConfiguration.java  |  11 +-
 .../camel/component/cedar/CedarEvaluator.java      |  47 +++++++-
 .../camel/component/cedar/CedarEvaluatorTest.java  | 125 +++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_25.adoc    |  10 ++
 .../endpoint/dsl/CedarEndpointBuilderFactory.java  |  47 ++++----
 9 files changed, 223 insertions(+), 33 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/CedarSecurityPolicy.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/CedarSecurityPolicy.json
index 2a7bda5bcdde..5bce53e815c6 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/CedarSecurityPolicy.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/beans/CedarSecurityPolicy.json
@@ -10,7 +10,7 @@
     "groupId": "org.apache.camel",
     "artifactId": "camel-cedar",
     "version": "4.25.0-SNAPSHOT",
-    "properties": { "policiesResource": { "index": 0, "kind": "property", 
"displayName": "Policies Resource", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The location of the Cedar policies, as text in 
the Cedar policy language (permit and forbid policies, not the JSON policy 
format), with a classpath: or file: prefix; other prefixes are rejected. It is 
read as UTF-8, parsed and validated aga [...]
+    "properties": { "policiesResource": { "index": 0, "kind": "property", 
"displayName": "Policies Resource", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The location of the Cedar policies, as text in 
the Cedar policy language (permit and forbid policies, not the JSON policy 
format), with a classpath: or file: prefix; other prefixes are rejected. It is 
read as UTF-8, parsed and validated aga [...]
   }
 }
 
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/cedar.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/cedar.json
index 78b5338a86b1..c8f5f5720ffa 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/cedar.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/cedar.json
@@ -30,9 +30,9 @@
   "properties": {
     "operation": { "index": 0, "kind": "path", "displayName": "Operation", 
"group": "producer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The operation to perform. Only authorize is 
supported: it evaluates the Cedar authorization request of the message against 
the policy set and stores the result (outcome ALLOW, DENY or ERROR, the engine 
decision, the determining policies, the [...]
     "action": { "index": 1, "kind": "parameter", "displayName": "Action", 
"group": "producer", "label": "", "required": true, "type": "object", 
"javaType": "org.apache.camel.Expression", "deprecated": false, "autowired": 
false, "secret": false, "supportSimpleExpression": true, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The action of the Cedar authorization request, 
that is what the principal wants to [...]
-    "context": { "index": 2, "kind": "parameter", "displayName": "Context", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.apache.camel.Expression", "deprecated": false, "autowired": 
false, "secret": false, "supportSimpleExpression": true, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The context of the Cedar authorization 
request: more request data that the poli [...]
-    "entitiesResource": { "index": 3, "kind": "parameter", "displayName": 
"Entities Resource", "group": "producer", "label": "", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The location of the static Cedar entities that 
the policies can read, such as the attributes and parents [...]
-    "entityProvider": { "index": 4, "kind": "parameter", "displayName": 
"Entity Provider", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": "org.apache.camel.component.cedar.CedarEntityProvider", 
"deprecated": false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "A CedarEntityProvider that returns, for each 
message, the Cedar entities [...]
+    "context": { "index": 2, "kind": "parameter", "displayName": "Context", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.apache.camel.Expression", "deprecated": false, "autowired": 
false, "secret": false, "supportSimpleExpression": true, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The context of the Cedar authorization 
request: more request data that the poli [...]
+    "entitiesResource": { "index": 3, "kind": "parameter", "displayName": 
"Entities Resource", "group": "producer", "label": "", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The location of the static Cedar entities that 
the policies can read, such as the attributes and parents [...]
+    "entityProvider": { "index": 4, "kind": "parameter", "displayName": 
"Entity Provider", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": "org.apache.camel.component.cedar.CedarEntityProvider", 
"deprecated": false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "A CedarEntityProvider that returns, for each 
message, the Cedar entities [...]
     "maxResourceSize": { "index": 5, "kind": "parameter", "displayName": "Max 
Resource Size", "group": "producer", "label": "", "required": false, "type": 
"integer", "javaType": "int", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": 1048576, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The maximum size, in bytes, of each of the 
policies, schema and entities resources, of the c [...]
     "policiesResource": { "index": 6, "kind": "parameter", "displayName": 
"Policies Resource", "group": "producer", "label": "", "required": true, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The location of the Cedar policies, as text in 
the Cedar policy language (permit and forbid policies, not [...]
     "principal": { "index": 7, "kind": "parameter", "displayName": 
"Principal", "group": "producer", "label": "", "required": true, "type": 
"object", "javaType": "org.apache.camel.Expression", "deprecated": false, 
"autowired": false, "secret": false, "supportSimpleExpression": true, 
"configurationClass": "org.apache.camel.component.cedar.CedarConfiguration", 
"configurationField": "configuration", "description": "The principal of the 
Cedar authorization request, that is who asks for acces [...]
diff --git 
a/components/camel-cedar/src/generated/resources/META-INF/org/apache/camel/component/cedar/cedar.json
 
b/components/camel-cedar/src/generated/resources/META-INF/org/apache/camel/component/cedar/cedar.json
index 78b5338a86b1..c8f5f5720ffa 100644
--- 
a/components/camel-cedar/src/generated/resources/META-INF/org/apache/camel/component/cedar/cedar.json
+++ 
b/components/camel-cedar/src/generated/resources/META-INF/org/apache/camel/component/cedar/cedar.json
@@ -30,9 +30,9 @@
   "properties": {
     "operation": { "index": 0, "kind": "path", "displayName": "Operation", 
"group": "producer", "label": "", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The operation to perform. Only authorize is 
supported: it evaluates the Cedar authorization request of the message against 
the policy set and stores the result (outcome ALLOW, DENY or ERROR, the engine 
decision, the determining policies, the [...]
     "action": { "index": 1, "kind": "parameter", "displayName": "Action", 
"group": "producer", "label": "", "required": true, "type": "object", 
"javaType": "org.apache.camel.Expression", "deprecated": false, "autowired": 
false, "secret": false, "supportSimpleExpression": true, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The action of the Cedar authorization request, 
that is what the principal wants to [...]
-    "context": { "index": 2, "kind": "parameter", "displayName": "Context", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.apache.camel.Expression", "deprecated": false, "autowired": 
false, "secret": false, "supportSimpleExpression": true, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The context of the Cedar authorization 
request: more request data that the poli [...]
-    "entitiesResource": { "index": 3, "kind": "parameter", "displayName": 
"Entities Resource", "group": "producer", "label": "", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The location of the static Cedar entities that 
the policies can read, such as the attributes and parents [...]
-    "entityProvider": { "index": 4, "kind": "parameter", "displayName": 
"Entity Provider", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": "org.apache.camel.component.cedar.CedarEntityProvider", 
"deprecated": false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "A CedarEntityProvider that returns, for each 
message, the Cedar entities [...]
+    "context": { "index": 2, "kind": "parameter", "displayName": "Context", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.apache.camel.Expression", "deprecated": false, "autowired": 
false, "secret": false, "supportSimpleExpression": true, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The context of the Cedar authorization 
request: more request data that the poli [...]
+    "entitiesResource": { "index": 3, "kind": "parameter", "displayName": 
"Entities Resource", "group": "producer", "label": "", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The location of the static Cedar entities that 
the policies can read, such as the attributes and parents [...]
+    "entityProvider": { "index": 4, "kind": "parameter", "displayName": 
"Entity Provider", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": "org.apache.camel.component.cedar.CedarEntityProvider", 
"deprecated": false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "A CedarEntityProvider that returns, for each 
message, the Cedar entities [...]
     "maxResourceSize": { "index": 5, "kind": "parameter", "displayName": "Max 
Resource Size", "group": "producer", "label": "", "required": false, "type": 
"integer", "javaType": "int", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": 1048576, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The maximum size, in bytes, of each of the 
policies, schema and entities resources, of the c [...]
     "policiesResource": { "index": 6, "kind": "parameter", "displayName": 
"Policies Resource", "group": "producer", "label": "", "required": true, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.cedar.CedarConfiguration", "configurationField": 
"configuration", "description": "The location of the Cedar policies, as text in 
the Cedar policy language (permit and forbid policies, not [...]
     "principal": { "index": 7, "kind": "parameter", "displayName": 
"Principal", "group": "producer", "label": "", "required": true, "type": 
"object", "javaType": "org.apache.camel.Expression", "deprecated": false, 
"autowired": false, "secret": false, "supportSimpleExpression": true, 
"configurationClass": "org.apache.camel.component.cedar.CedarConfiguration", 
"configurationField": "configuration", "description": "The principal of the 
Cedar authorization request, that is who asks for acces [...]
diff --git 
a/components/camel-cedar/src/generated/resources/META-INF/services/org/apache/camel/bean/CedarSecurityPolicy.json
 
b/components/camel-cedar/src/generated/resources/META-INF/services/org/apache/camel/bean/CedarSecurityPolicy.json
index 2a7bda5bcdde..5bce53e815c6 100644
--- 
a/components/camel-cedar/src/generated/resources/META-INF/services/org/apache/camel/bean/CedarSecurityPolicy.json
+++ 
b/components/camel-cedar/src/generated/resources/META-INF/services/org/apache/camel/bean/CedarSecurityPolicy.json
@@ -10,7 +10,7 @@
     "groupId": "org.apache.camel",
     "artifactId": "camel-cedar",
     "version": "4.25.0-SNAPSHOT",
-    "properties": { "policiesResource": { "index": 0, "kind": "property", 
"displayName": "Policies Resource", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The location of the Cedar policies, as text in 
the Cedar policy language (permit and forbid policies, not the JSON policy 
format), with a classpath: or file: prefix; other prefixes are rejected. It is 
read as UTF-8, parsed and validated aga [...]
+    "properties": { "policiesResource": { "index": 0, "kind": "property", 
"displayName": "Policies Resource", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The location of the Cedar policies, as text in 
the Cedar policy language (permit and forbid policies, not the JSON policy 
format), with a classpath: or file: prefix; other prefixes are rejected. It is 
read as UTF-8, parsed and validated aga [...]
   }
 }
 
diff --git 
a/components/camel-cedar/src/main/java/org/apache/camel/component/cedar/CedarConfiguration.java
 
b/components/camel-cedar/src/main/java/org/apache/camel/component/cedar/CedarConfiguration.java
index 8a6cfbfed374..929bac5323fc 100644
--- 
a/components/camel-cedar/src/main/java/org/apache/camel/component/cedar/CedarConfiguration.java
+++ 
b/components/camel-cedar/src/main/java/org/apache/camel/component/cedar/CedarConfiguration.java
@@ -50,7 +50,10 @@ public class CedarConfiguration {
                             + " of entities, each with uid, attrs and parents, 
and optionally tags), with a classpath: or"
                             + " file: prefix; other prefixes are rejected. 
They are loaded and validated against the schema"
                             + " together with the policies and the schema, as 
one revision: a failed load fails the start,"
-                            + " and a failed reload keeps the active revision. 
When not set, there are no static entities.")
+                            + " and a failed reload keeps the active revision. 
Cedar has no floating-point numbers, so a"
+                            + " number with a fractional part in the entities 
fails the load rather than being truncated"
+                            + " to a whole number: use a whole number or a 
Decimal. When not set, there are no static"
+                            + " entities.")
     private String entitiesResource;
     @UriParam
     @Metadata(required = true,
@@ -86,7 +89,8 @@ public class CedarConfiguration {
                             + " with the JSON mapping of Cedar Java: a String 
is a string, a whole number a Long, a"
                             + " Collection a set, a nested Map or POJO a 
record, and a Cedar Java value such as an"
                             + " EntityUID, IpAddress or Decimal an entity 
reference or extension value of that type. Cedar"
-                            + " has no floating-point numbers: use a whole 
number or a Decimal."
+                            + " has no floating-point numbers, so a number 
with a fractional part gives the ERROR outcome"
+                            + " rather than being truncated to a whole number: 
use a whole number or a Decimal."
                             + " When not set, the context is empty; the body 
and the headers are never"
                             + " added on their own. A null result, a result 
that cannot be converted, a context larger than"
                             + " maxResourceSize, or a context that does not 
match the type the schema declares for the"
@@ -98,7 +102,8 @@ public class CedarConfiguration {
                             + " such as the attributes and parents of the 
principal or the resource loaded from a store."
                             + " They are added to the static entities for this 
message only and validated against the"
                             + " schema. A provider that throws an exception, 
or returns null, more than maxResourceSize"
-                            + " bytes, JSON that is malformed or does not 
match the schema, or an entity UID that is"
+                            + " bytes, JSON that is malformed, carries a 
number with a fractional part, or does not match"
+                            + " the schema, or an entity UID that is"
                             + " already defined gives the ERROR outcome. The 
provider owns its I/O timeouts and caching:"
                             + " Camel neither limits how long it runs nor 
checks how current its data is.")
     private CedarEntityProvider entityProvider;
diff --git 
a/components/camel-cedar/src/main/java/org/apache/camel/component/cedar/CedarEvaluator.java
 
b/components/camel-cedar/src/main/java/org/apache/camel/component/cedar/CedarEvaluator.java
index abf6e57c9e6b..f0bcfaab6e99 100644
--- 
a/components/camel-cedar/src/main/java/org/apache/camel/component/cedar/CedarEvaluator.java
+++ 
b/components/camel-cedar/src/main/java/org/apache/camel/component/cedar/CedarEvaluator.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.cedar;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
@@ -42,6 +43,8 @@ import com.cedarpolicy.model.schema.Schema;
 import com.cedarpolicy.value.EntityUID;
 import com.cedarpolicy.value.Value;
 import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
@@ -55,6 +58,8 @@ public final class CedarEvaluator extends ServiceSupport {
     private static final Logger LOG = 
LoggerFactory.getLogger(CedarEvaluator.class);
     private static final TypeReference<Map<String, Value>> CONTEXT_TYPE = new 
TypeReference<>() {
     };
+    private static final TypeReference<Set<Entity>> ENTITIES_TYPE = new 
TypeReference<>() {
+    };
     private final CamelContext camelContext;
     private final CedarConfiguration configuration;
     private final Supplier<AuthorizationEngine> engineFactory;
@@ -161,7 +166,7 @@ public final class CedarEvaluator extends ServiceSupport {
             }
             step = "parsing";
             option = "entitiesResource";
-            Entities entities = Entities.parse(entitiesText);
+            Entities entities = new Entities(parseEntities(entitiesText));
             step = "validating";
             engine.validateEntities(new EntityValidationRequest(schema, new 
ArrayList<>(entities.getEntities())));
             MessageDigest digest = MessageDigest.getInstance("SHA-256");
@@ -234,7 +239,9 @@ public final class CedarEvaluator extends ServiceSupport {
                     if (value == null) {
                         throw new Rejected("the context expression yielded 
null");
                     }
-                    context = CedarJson.objectMapper().convertValue(value, 
CONTEXT_TYPE);
+                    JsonNode tree = 
CedarJson.objectMapper().valueToTree(value);
+                    rejectNonWholeNumbers(tree);
+                    context = CedarJson.objectMapper().convertValue(tree, 
CONTEXT_TYPE);
                     if 
(CedarJson.objectMapper().writeValueAsBytes(context).length > 
configuration.getMaxResourceSize()) {
                         throw new Rejected("the context is larger than 
maxResourceSize");
                     }
@@ -295,7 +302,7 @@ public final class CedarEvaluator extends ServiceSupport {
         }
         Set<EntityUID> ids = new HashSet<>();
         entities.forEach(entity -> ids.add(entity.getEUID()));
-        for (Entity entity : Entities.parse(json).getEntities()) {
+        for (Entity entity : parseEntities(json)) {
             if (!ids.add(entity.getEUID())) {
                 throw new Rejected("the entity provider returned an entity UID 
that is already defined");
             }
@@ -307,6 +314,40 @@ public final class CedarEvaluator extends ServiceSupport {
         return requestEntities;
     }
 
+    /**
+     * Reads Cedar entities JSON, the static entities and the entities of a 
provider alike, as
+     * {@link Entities#parse(String)} does. The document is read once: the 
tree that is checked for numbers that are not
+     * whole is the tree the entities are made from.
+     */
+    private static Set<Entity> parseEntities(String json) throws IOException {
+        // the Cedar Java deserializers need the object mapper itself as the 
codec of the parser they read from
+        ObjectMapper mapper = CedarJson.objectMapper();
+        JsonNode tree = mapper.readTree(json);
+        if (tree == null || tree.isMissingNode() || tree.isNull()) {
+            throw new Rejected("the entities JSON is empty");
+        }
+        rejectNonWholeNumbers(tree);
+        return mapper.readValue(mapper.treeAsTokens(tree), ENTITIES_TYPE);
+    }
+
+    /**
+     * Rejects a JSON number that is not a whole number anywhere in the tree. 
Cedar has no floating-point type: its
+     * value deserializer reads every in-range JSON number as a Long, so a 
number with a fractional part would be
+     * truncated toward zero rather than carried faithfully, and such input is 
rejected instead. A whole-valued number
+     * such as 100 or 100.0 is accepted, and a Cedar Decimal, whose digits are 
carried as a String, is unaffected.
+     */
+    private static void rejectNonWholeNumbers(JsonNode node) {
+        if (node.isNumber()) {
+            if (!node.canConvertToExactIntegral()) {
+                throw new Rejected("a number is not a whole number; Cedar has 
no floating-point type");
+            }
+        } else if (node.isContainerNode()) {
+            for (JsonNode child : node) {
+                rejectNonWholeNumbers(child);
+            }
+        }
+    }
+
     private static EntityUID uid(Expression expression, Exchange exchange) {
         Object value = expression.evaluate(exchange, Object.class);
         if (value instanceof EntityUID uid) {
diff --git 
a/components/camel-cedar/src/test/java/org/apache/camel/component/cedar/CedarEvaluatorTest.java
 
b/components/camel-cedar/src/test/java/org/apache/camel/component/cedar/CedarEvaluatorTest.java
index 30dd0285e01c..1a94f48274c6 100644
--- 
a/components/camel-cedar/src/test/java/org/apache/camel/component/cedar/CedarEvaluatorTest.java
+++ 
b/components/camel-cedar/src/test/java/org/apache/camel/component/cedar/CedarEvaluatorTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.cedar;
 import java.io.ByteArrayInputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Proxy;
+import java.math.BigDecimal;
 import java.net.InetSocketAddress;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
@@ -174,6 +175,130 @@ class CedarEvaluatorTest {
         }
     }
 
+    @Test
+    void fractionalContextNumberGivesErrorOutcome() throws Exception {
+        String schema = SCHEMA.replace("context: {}", "context: {amount: 
Long}");
+        try (Fixture fixture = new Fixture(
+                "permit(principal == User::\"alice\", action == 
Action::\"read\", resource == Doc::\"budget\")"
+                                           + " when { context.amount <= 100 
};",
+                schema)) {
+            
fixture.config.setContext(ExpressionBuilder.constantExpression(Map.of("amount", 
100.9)));
+            fixture.start();
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).outcome())
+                    .isEqualTo(CedarAuthorizationResult.Outcome.ERROR);
+        }
+    }
+
+    @Test
+    void wholeValuedDoubleContextIsAccepted() throws Exception {
+        String schema = SCHEMA.replace("context: {}", "context: {amount: 
Long}");
+        try (Fixture fixture = new Fixture(
+                "permit(principal == User::\"alice\", action == 
Action::\"read\", resource == Doc::\"budget\")"
+                                           + " when { context.amount <= 100 
};",
+                schema)) {
+            
fixture.config.setContext(ExpressionBuilder.constantExpression(Map.of("amount", 
100.0)));
+            fixture.start();
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).isAllowed()).isTrue();
+        }
+    }
+
+    @Test
+    void bigDecimalFractionalContextGivesErrorOutcome() throws Exception {
+        String schema = SCHEMA.replace("context: {}", "context: {amount: 
Long}");
+        try (Fixture fixture = new Fixture(
+                "permit(principal == User::\"alice\", action == 
Action::\"read\", resource == Doc::\"budget\")"
+                                           + " when { context.amount <= 100 
};",
+                schema)) {
+            
fixture.config.setContext(ExpressionBuilder.constantExpression(Map.of("amount", 
new BigDecimal("100.9"))));
+            fixture.start();
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).outcome())
+                    .isEqualTo(CedarAuthorizationResult.Outcome.ERROR);
+        }
+    }
+
+    @Test
+    void fractionalNumberNestedInContextCollectionGivesErrorOutcome() throws 
Exception {
+        String schema = SCHEMA.replace("context: {}", "context: {limits: 
Set<Long>}");
+        try (Fixture fixture = new Fixture(PERMIT, schema)) {
+            
fixture.config.setContext(ExpressionBuilder.constantExpression(Map.of("limits", 
List.of(1, 2.5))));
+            fixture.start();
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).outcome())
+                    .isEqualTo(CedarAuthorizationResult.Outcome.ERROR);
+        }
+    }
+
+    @Test
+    void fractionalEntityProviderAttributeGivesErrorOutcome() throws Exception 
{
+        String schema = "entity User { score: Long }; entity Doc;"
+                        + " action \"read\" appliesTo {principal: User, 
resource: Doc, context: {}};";
+        try (Fixture fixture = new Fixture("permit(principal,action,resource) 
when { principal.score <= 100 };", schema)) {
+            fixture.config.setEntityProvider(
+                    exchange -> 
"[{\"uid\":{\"type\":\"User\",\"id\":\"alice\"},\"attrs\":{\"score\":99.9},\"parents\":[]}]");
+            fixture.start();
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).outcome())
+                    .isEqualTo(CedarAuthorizationResult.Outcome.ERROR);
+        }
+    }
+
+    @Test
+    void fractionalStaticEntityAttributeFailsLoadAndKeepsActiveRevision() 
throws Exception {
+        String schema = "entity User { score: Long }; entity Doc;"
+                        + " action \"read\" appliesTo {principal: User, 
resource: Doc, context: {}};";
+        String policy = "permit(principal,action,resource) when { 
principal.score <= 100 };";
+        try (Fixture fixture = new Fixture(policy, schema)) {
+            Path entities = fixture.directory.resolve("entities.json");
+            // 100.9 is not a whole number
+            Files.writeString(entities, userWithScore("100.9"));
+            fixture.config.setEntitiesResource(entities.toUri().toString());
+            assertThatThrownBy(fixture::start)
+                    .hasMessageContaining("parsing of entitiesResource failed 
(a number is not a whole number")
+                    .hasMessageContaining("no revision is 
active").hasMessageNotContaining("100.9").hasNoCause();
+            assertThat(fixture.evaluator.getRevision()).isNull();
+        }
+        try (Fixture fixture = new Fixture(policy, schema)) {
+            Path entities = fixture.directory.resolve("entities.json");
+            // a whole-valued number is accepted
+            Files.writeString(entities, userWithScore("100.0"));
+            fixture.config.setEntitiesResource(entities.toUri().toString());
+            fixture.start();
+            String revision = fixture.evaluator.getRevision();
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).isAllowed()).isTrue();
+            Files.writeString(entities, userWithScore("100.9"));
+            assertThatThrownBy(fixture.evaluator::reload)
+                    .hasMessageContaining("parsing of entitiesResource failed 
(a number is not a whole number")
+                    .hasMessageContaining("the previous revision is retained");
+            assertThat(fixture.evaluator.getRevision()).isEqualTo(revision);
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).isAllowed()).isTrue();
+        }
+    }
+
+    @Test
+    void emptyEntitiesJsonIsRejected() throws Exception {
+        try (Fixture fixture = new Fixture(PERMIT, SCHEMA)) {
+            fixture.config.setEntityProvider(exchange -> "");
+            fixture.start();
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).outcome())
+                    .isEqualTo(CedarAuthorizationResult.Outcome.ERROR);
+            fixture.config.setEntityProvider(exchange -> "null");
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).outcome())
+                    .isEqualTo(CedarAuthorizationResult.Outcome.ERROR);
+            // an empty array is a valid entities document
+            fixture.config.setEntityProvider(exchange -> "[]");
+            
assertThat(fixture.evaluator.evaluate(fixture.exchange()).isAllowed()).isTrue();
+        }
+        try (Fixture fixture = new Fixture(PERMIT, SCHEMA)) {
+            Path entities = fixture.directory.resolve("entities.json");
+            Files.writeString(entities, "");
+            fixture.config.setEntitiesResource(entities.toUri().toString());
+            assertThatThrownBy(fixture::start)
+                    .hasMessageContaining("parsing of entitiesResource failed 
(the entities JSON is empty)");
+        }
+    }
+
+    private static String userWithScore(String score) {
+        return 
"[{\"uid\":{\"type\":\"User\",\"id\":\"alice\"},\"attrs\":{\"score\":" + score 
+ "},\"parents\":[]}]";
+    }
+
     @Test
     void validatesSchemaAndRetainsRevisionAfterInvalidReload() throws 
Exception {
         try (Fixture fixture = new Fixture(PERMIT, SCHEMA)) {
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
index 1ebdb6789f69..f95b8bc9d366 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
@@ -97,6 +97,16 @@ the builder of Azure Identity instead:
       builderClass: com.azure.identity.DefaultAzureCredentialBuilder
 ----
 
+=== camel-cedar - a fractional number in the context or entity data is rejected
+
+The `camel-cedar` component converts the `context` expression result, the 
entity JSON that a `CedarEntityProvider`
+returns, and the static entities of `entitiesResource` to Cedar values. Cedar 
has no floating-point type and
+represents every whole number as a `Long`. A number that carries a fractional 
part (for example a `Double`, `Float`
+or `BigDecimal` such as `100.9`) is no longer truncated to a whole number. In 
the context or in the entities of the
+provider it now gives the `ERROR` outcome. In `entitiesResource` it fails the 
start, and on a reload the active
+revision is kept. A whole-valued number such as `100` or `100.0` is still 
accepted, and a Cedar `Decimal`, whose
+digits are written as a string, is unaffected. Use a whole number or a Cedar 
`Decimal` for fractional values.
+
 === camel-azure-key-vault - EventhubsReloadTriggerTask now checkpoints after 
processing
 
 `EventhubsReloadTriggerTask` now writes an Event Hubs checkpoint after each 
event.
diff --git 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CedarEndpointBuilderFactory.java
 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CedarEndpointBuilderFactory.java
index aa295e2ee094..8e6501b54997 100644
--- 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CedarEndpointBuilderFactory.java
+++ 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CedarEndpointBuilderFactory.java
@@ -100,11 +100,13 @@ public interface CedarEndpointBuilderFactory {
          * number a Long, a Collection a set, a nested Map or POJO a record, 
and
          * a Cedar Java value such as an EntityUID, IpAddress or Decimal an
          * entity reference or extension value of that type. Cedar has no
-         * floating-point numbers: use a whole number or a Decimal. When not
-         * set, the context is empty; the body and the headers are never added
-         * on their own. A null result, a result that cannot be converted, a
-         * context larger than maxResourceSize, or a context that does not 
match
-         * the type the schema declares for the action gives the ERROR outcome.
+         * floating-point numbers, so a number with a fractional part gives the
+         * ERROR outcome rather than being truncated to a whole number: use a
+         * whole number or a Decimal. When not set, the context is empty; the
+         * body and the headers are never added on their own. A null result, a
+         * result that cannot be converted, a context larger than
+         * maxResourceSize, or a context that does not match the type the 
schema
+         * declares for the action gives the ERROR outcome.
          * 
          * The option is a: <code>org.apache.camel.Expression</code> type.
          * 
@@ -126,11 +128,13 @@ public interface CedarEndpointBuilderFactory {
          * number a Long, a Collection a set, a nested Map or POJO a record, 
and
          * a Cedar Java value such as an EntityUID, IpAddress or Decimal an
          * entity reference or extension value of that type. Cedar has no
-         * floating-point numbers: use a whole number or a Decimal. When not
-         * set, the context is empty; the body and the headers are never added
-         * on their own. A null result, a result that cannot be converted, a
-         * context larger than maxResourceSize, or a context that does not 
match
-         * the type the schema declares for the action gives the ERROR outcome.
+         * floating-point numbers, so a number with a fractional part gives the
+         * ERROR outcome rather than being truncated to a whole number: use a
+         * whole number or a Decimal. When not set, the context is empty; the
+         * body and the headers are never added on their own. A null result, a
+         * result that cannot be converted, a context larger than
+         * maxResourceSize, or a context that does not match the type the 
schema
+         * declares for the action gives the ERROR outcome.
          * 
          * The option will be converted to a
          * <code>org.apache.camel.Expression</code> type.
@@ -152,7 +156,10 @@ public interface CedarEndpointBuilderFactory {
          * prefix; other prefixes are rejected. They are loaded and validated
          * against the schema together with the policies and the schema, as one
          * revision: a failed load fails the start, and a failed reload keeps
-         * the active revision. When not set, there are no static entities.
+         * the active revision. Cedar has no floating-point numbers, so a 
number
+         * with a fractional part in the entities fails the load rather than
+         * being truncated to a whole number: use a whole number or a Decimal.
+         * When not set, there are no static entities.
          * 
          * The option is a: <code>java.lang.String</code> type.
          * 
@@ -173,10 +180,11 @@ public interface CedarEndpointBuilderFactory {
          * store. They are added to the static entities for this message only
          * and validated against the schema. A provider that throws an
          * exception, or returns null, more than maxResourceSize bytes, JSON
-         * that is malformed or does not match the schema, or an entity UID 
that
-         * is already defined gives the ERROR outcome. The provider owns its 
I/O
-         * timeouts and caching: Camel neither limits how long it runs nor
-         * checks how current its data is.
+         * that is malformed, carries a number with a fractional part, or does
+         * not match the schema, or an entity UID that is already defined gives
+         * the ERROR outcome. The provider owns its I/O timeouts and caching:
+         * Camel neither limits how long it runs nor checks how current its 
data
+         * is.
          * 
          * The option is a:
          * <code>org.apache.camel.component.cedar.CedarEntityProvider</code>
@@ -199,10 +207,11 @@ public interface CedarEndpointBuilderFactory {
          * store. They are added to the static entities for this message only
          * and validated against the schema. A provider that throws an
          * exception, or returns null, more than maxResourceSize bytes, JSON
-         * that is malformed or does not match the schema, or an entity UID 
that
-         * is already defined gives the ERROR outcome. The provider owns its 
I/O
-         * timeouts and caching: Camel neither limits how long it runs nor
-         * checks how current its data is.
+         * that is malformed, carries a number with a fractional part, or does
+         * not match the schema, or an entity UID that is already defined gives
+         * the ERROR outcome. The provider owns its I/O timeouts and caching:
+         * Camel neither limits how long it runs nor checks how current its 
data
+         * is.
          * 
          * The option will be converted to a
          * <code>org.apache.camel.component.cedar.CedarEntityProvider</code>

Reply via email to