allthingssecurity opened a new pull request, #27676:
URL: https://github.com/apache/camel/pull/27676

   # Description
   
   [CAMEL-25525](https://issues.apache.org/jira/browse/CAMEL-25525)
   
   `KeycloakConsumer` queries the events of the realm without a lower time 
bound and skips those older than its checkpoint (`lastEventTime`) and those 
whose fingerprint it has already routed. When a poll moved the checkpoint to a 
newer event time, it cleared all the fingerprints, also those of the events at 
the new checkpoint, so the next poll got those events again from Keycloak and 
routed them a second time. Every poll that saw a newer event therefore 
delivered the latest event(s) twice, in the default configuration, for user 
events and admin events. The docs say the deduplication ensures "events are not 
processed multiple times".
   
   Now, when the checkpoint moves, the consumer forgets only the fingerprints 
older than the new checkpoint and keeps those at it (a fingerprint starts with 
the event time), in both `pollEvents` and `pollAdminEvents`. After each poll 
the set still holds only the fingerprints of the latest event time. A poll 
routes the same events as before except the repeated ones, so there is no 
upgrade-guide note.
   
   Tests:
   - New `KeycloakConsumerLatestEventsTest` (mocked `Keycloak` client as in 
`KeycloakConsumerTest`, `startScheduler=false`, the test calls `poll()`): two 
events polled twice must be routed once; then a newer event and a second event 
at the previous latest time are added and polled twice; the same for admin 
events.
   - Without the change both fail: `the events of the first poll must not be 
routed again ==> expected: <0> but was: <1>` (and the same for admin events). 
The existing `KeycloakConsumerTest` uses `expectedMinimumMessageCount(2)`, so 
it does not see the third delivery.
   - With the change: camel-keycloak 141 unit tests, 0 failures (the 
integration tests need Docker and were skipped).
   
   Not changed here: the size limit of 1000 fingerprints (not reached with the 
default `maxResults`); Keycloak returns at most `maxResults` (default 100) 
events per query, ordered by descending time, so a poll with more new events 
than that misses the older ones; that needs paging with `first` and is better 
handled in its own issue.
   
   Found with a Lean 4 model of the poll: "a second poll of the same events 
routes nothing" fails for two events, and main is proved to route again every 
event at the time a poll moves the checkpoint to; the fix is proved to never 
route again an event the previous poll routed. I then reproduced it with the 
consumer.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built and tested camel-keycloak, including the formatter and 
import-sort plugins. I did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to