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

   # Description
   
   [CAMEL-25073](https://issues.apache.org/jira/browse/CAMEL-25073), item 1
   
   @davsclaus listed this after his deep review of #26959 (CAMEL-25065): a 
CamelContext name (or management name) with `, = : " * ?` fails to start. The 
ticket has three options. This PR implements the recommended one, (b), together 
with the context-key clash check that our follow-up comment on the ticket 
showed it needs. The alternatives are listed below; if you prefer one of them, 
I'll change the PR.
   
   The management name (by default the CamelContext name) goes unquoted into 
the `context=` key of every MBean object name 
(`DefaultManagementObjectNameStrategy.getContextId`). For such names `start()` 
fails: `, = : "` and a line feed give a `MalformedObjectNameException`, and `* 
?` turn the name into a pattern, which cannot be registered. Nothing falls 
back, so the CamelContext does not start.
   
   Change, all in `JmxManagementLifecycleStrategy.onContextStarting`:
   - The management name is sanitized: `, = : " * ?` and a line feed become 
`_`, with one WARN. The names that `findFreeName` gets from the name strategy 
are sanitized too, as they are built from the raw name. Every query that builds 
the `context=` key from `getManagementName()` keeps working, in Camel 
(`ManagedCamelContext`, `ManagedRoute`, the dev consoles, the route coverage 
dumper) and outside it. The CamelContext MBean keeps the real name in its 
quoted `name=` key and in its `CamelId` attribute.
   - Clash check on the context key. A sanitized name can be the name of 
another CamelContext (`a,b` and `a_b`). The old clash check compared the whole 
context object name, which includes the quoted real name, so it missed this. 
Both contexts would start with the key `a_b`, and `registerMBeanWithServer` 
silently skips names that are already taken, so the second context would have 
no route, processor or component MBeans, and its `ManagedCamelContext` lookups 
would return the first context's MBeans. The check now also counts a 
CamelContext MBean with the same `context=` key and another name as a clash 
(one `context=<key>,type=context,*` query when the context starts). Then the 
next free management name is used, or the start is vetoed for a fixed 
management name pattern, as already happens for two CamelContexts with the same 
name.
   
   The clash check also closes two gaps that main has without special 
characters: two CamelContexts with different names and the same fixed 
`managementNamePattern` (both started and shared the key; now the second is 
vetoed), and `foo`, a second `foo` (which gets a free name such as `foo-1`), 
then a CamelContext named `foo-1` (shared the key; now it gets the next free 
name). The upgrade guide has a paragraph under `=== camel-management`.
   
   Names that start today keep their management name and object names.
   
   Options on the ticket:
   - (a) Quote the `context=` key only when needed. MBean names would show the 
real name, but `getContextId` and the 13 queries built by hand in 4 modules 
(`ManagedCamelContext` 7, `ManagedRoute` 1, `ProducerDevConsole` 2, 
`ReceiveDevConsole` 1, the two `CamelRouteCoverageDumper`) must change, and 
external tools that build the key from the management name (hawtio, Jolokia 
clients, scripts) keep failing for such names.
   - (b) Sanitize the management name. This PR does that, plus the clash check.
   - (c) Fail fast with a clear message. Such names still could not be used 
with JMX.
   
   Found and checked with a Lean 4 model of the unquoted-value rule, 
`ObjectName.quote`/`unquote` and the clash check of `onContextStarting` (kept 
outside the repo). Sanitizing alone is not injective (`a,b` and `a_b`), and no 
sanitizer that keeps today's names can be: for an invalid `x`, `g(x)` is valid, 
so `g(g(x)) = g(x)`. The old clash check misses these collisions in either 
start order. Quote-when-needed round-trips and is injective, so (a) has no 
collision problem. Sanitizing plus the context-key check keeps the context keys 
unique for every start sequence, and it gives the same result as main wherever 
main was right (a veto, or keys that were already unique). Only the line feed 
must be replaced; `\r` works unquoted.
   
   Tests: the new `ManagedCamelContextNameObjectNameTest` (11 tests) covers:
   - each of the 7 characters: the context starts, the key is `my_camel`, 
`CamelId` keeps the name, and `ManagedCamelContext.getManagedRoute` finds the 
route;
   - `my_camel` and `my,camel`, in both orders, get separate MBeans;
   - a CamelContext named like the free name another one got gets its own 
MBeans;
   - a fixed pattern used by `foo` and `bar` vetoes the second context.
   
   All 11 fail on main, in two runs. With sanitizing but without the 
context-key check, the 4 clash tests fail (`expected: not equal but was: 
<my_camel>`, and the fixed pattern is not vetoed). The whole `camel-management` 
module passes (542 tests, 0 failures, 1 skipped).
   
   Related CAMEL-25073 PRs, each for one item and based on `main`: item 2 
(`camel-management-onexception-shared-mbean`), item 3 
(`camel-management-masked-endpoint-unregister`), item 4 
(`camel-management-thread-pool-source-id`) and item 5 
(`camel-management-contextonly-components`). All five merge cleanly with `main` 
and with each other in every pair (`git merge-tree`). Items 1, 2, 3 and 5 
change different methods of `JmxManagementLifecycleStrategy`; items 1, 4 and 5 
add separate paragraphs under `=== camel-management` in the upgrade guide. With 
all five merged together, the `camel-management` module passes (553 tests, 0 
failures, 1 skipped). None depends on another.
   
   # 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 `core/camel-management`, including the formatter and 
import-sort plugins. No generated files change. 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