davsclaus opened a new pull request, #31039: URL: https://github.com/apache/camel/pull/31039
JIRA: https://issues.apache.org/jira/browse/CAMEL-27709 ## What was wrong Since the Eclipse Milo 1.0 migration (Camel 4.16), the `certificateValidator` option of the milo-server component could not be used: - In `MiloServerComponent.buildServerConfig()` the call `serverConfig.setCertificateValidator(certificateValidator)` was commented out (`// FIXME - moved to certificateManager`). Instead the component built `new DefaultCertificateManager(certificateQuarantine, certificateGroup)`, and both fields are only set by `defaultCertificateValidator`. With a custom validator alone, Milo threw a `NullPointerException` in `DefaultCertificateManager.<init>` and the server did not start (`FailedToStartComponentException`). - With `defaultCertificateValidator` also set, the custom validator was ignored in either order of the setters: `setDefaultCertificateValidator()` overwrote the field, or the certificate group had already been built with the file based validator. ## What changed - With Milo 1.x the server validates a client certificate with `CertificateGroup.getCertificateValidator()` of the certificate group of the server certificate, which it gets from the `CertificateManager` (`UascServerAsymmetricHandler`, `SessionManager`). When `certificateValidator` is set, the certificate manager of the server is now wrapped in the new `CertificateValidatorCertificateManager` (in `server.internal`): it delegates everything to the configured certificate manager, but its certificate groups return the custom validator. - `certificateValidator` needs `certificateManager` (it holds the server certificate and key pair). Without one, the server fails to start with a clear message. - Setting both `certificateValidator` and `defaultCertificateValidator` fails the start with a clear `IllegalArgumentException`. - The validator of the file based trust list of `defaultCertificateValidator` is kept in its own field, so it no longer overwrites the `certificateValidator` option. `defaultCertificateValidator` alone works as before. - `certificateValidator` has a description now, and the description of `certificateManager` says how the two work together. - The system property `org.apache.camel.milo.server.default.enableAnonymous` is read in `createDefaultConfiguration()` and `createEndpointConfigs()`. No test uses it, so it is a user-facing switch: when no identity options are set, it adds the Anonymous user token policy and the `AnonymousIdentityValidator`. It is now documented on the milo-server page as off by default and for development only. The code is unchanged. ## Tests - `MiloServerCertificateValidatorTest` (new, 4 tests): the server starts with a custom validator and a certificate manager, and the certificate groups of the server use the custom validator; a custom validator without a certificate manager fails the start; setting both validators, in either order, fails the start. - `ServerClientCertificateValidatorTest` (new): end to end with a milo-client over `Basic256Sha256`. The server's certificate group accepts any client, the custom validator decides: a client it accepts gets the value, and after the validator switches to reject, a second client cannot connect and only reports its node without communication. The validator sees the client certificate of the key store. - All 5 new tests fail before the fix (NPE at server start, and no failure when both validators are set). - `MonitorItemMultiConnectionsCertTest` is enabled again. It does not use `certificateValidator`, and it already passed its first item before this change. It failed only because the clients that cannot connect now report their node once without communication, where the test expected no message. The test now expects that message, checks the value of the connected client, and uses a `@TempDir` instead of the shared `target/testing/cert/default`. - The full camel-milo test suite passes. ## Docs - milo-server page: a section on validating client certificates (`defaultCertificateValidator` or `certificateValidator` with `certificateManager`, not both), and a section on the `enableAnonymous` system property. - Upgrade guide 4.24: `certificateValidator` is used again, and setting both validators now fails the start. - Regenerated the component JSON, the catalog copies (JSON and doc), and the component DSL. This is separate from CAMEL-27704, which lists other milo problems. None of its items overlap. _Claude Code on behalf of Claus Ibsen_ 🤖 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]
