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

   # Description
   
   [CAMEL-27427](https://issues.apache.org/jira/browse/CAMEL-27427): 
`TrustManagersParameters` can carry a ready-made `TrustManager`, but 
`KeyManagersParameters` could only describe key material as a 
`KeyStoreParameters` plus a key password. That is awkward for runtimes that 
already manage key material and expose it as an `X509KeyManager`.
   
   ## What changes
   
   - **camel-api**: `KeyManagersParameters` gains a `keyManager` option, 
mirroring `TrustManagersParameters.trustManager`. When it is set, 
`createKeyManagers()` returns it and does not use the key store, key password, 
provider or algorithm. The `certAlias` of `SSLContextParameters` still applies 
to an `X509KeyManager`, because `createSSLContext()` wraps it in 
`AliasedX509ExtendedKeyManager` as before. A debug log line tells when the key 
manager overrides configured key store fields.
   - **XML DSL** (camel-core-xml, used by camel-spring-xml): new `keyManager` 
attribute on `<keyManagers>`, a reference to a `KeyManager` bean in the 
registry, resolved with `mandatoryLookup` like `trustManager`. 
`camel-spring.xsd` is regenerated in the catalog.
   - **camel-vertx-common**: `VertxHelper` builds its own `KeyManagerFactory` 
from the key store, so it would have ignored the option. It now wraps a carried 
`X509KeyManager` with `KeyCertOptions.wrap`, and rejects any other `KeyManager` 
type, which Vert.x cannot use.
   - **camel-coap (DTLS) and camel-kafka**: both read the key store fields 
directly and cannot use a `KeyManager`. Without a check, CoAP failed with a 
`NullPointerException` (key manager only) or silently used the key store (both 
set), and Kafka silently connected without a client certificate. Both now fail 
at startup with an `IllegalArgumentException` that says to configure a key 
store. `coap+tcp` uses `createSSLContext()` and supports the option.
   - **Docs**: the JSSE utility page documents the new attribute.
   
   Components that call `SSLContextParameters.createSSLContext()`, including 
the Thrift consumer, support the option without changes.
   
   ## Not in this PR
   
   - CoAP and Kafka have the same gap for 
`TrustManagersParameters.trustManager` (CoAP fails with a 
`NullPointerException`, Kafka ignores it). That predates this change and is 
left for a follow-up.
   - The YAML/XML application model (`SSLContextParametersDefinition`) and 
camel-main have no `trustManager` option either, so no `keyManager` option is 
added there.
   - Real `X509KeyManager` support for CoAP DTLS (it needs a private key and 
certificate chain, which an `X509KeyManager` can provide) could be a follow-up.
   
   No upgrade guide entry: the option is new and opt-in, and no default changes.
   
   ## Tests
   
   - `KeyManagersParametersTest#testCustomKeyManager`, `VertxHelperTest`, the 
new Spring XML `KeyManagersParametersFactoryBeanTest`, 
`KafkaClientConfigurationTest#existingKeyManagerIsRejected` and the new 
`CoAPEndpointKeyManagerTest` all configure a key store that would fail, or 
would win, if the key manager were not honored, so they check the precedence 
rather than a non-null result.
   - `SSLContextParametersTest#testCertAliasAppliesToExistingKeyManager` checks 
that `certAlias` applies to a carried key manager.
   - Mutation-checked locally: disabling the shortcut in `createKeyManagers()`, 
the CoAP guard or the Kafka guard makes the matching test fail.
   - Passing locally: the JSSE tests in camel-core (48), the Spring XML JSSE 
tests, camel-vertx-common (6), `KafkaClientConfigurationTest` (7), and the 
camel-coap TLS suites plus the new test (34).
   
   # 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.
   
   The changed modules were built and formatted, and the only generated change 
(`camel-spring.xsd`) is committed. A full root build ran with `-Dquickly` 
before the second commit; CI will confirm there are no uncommitted generated 
changes.
   
   # 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.
   
   _Claude Code on behalf of Adriano Machado (@ammachado)_
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._
   


-- 
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