davsclaus opened a new pull request, #3198:
URL: https://github.com/apache/camel-kamelets/pull/3198

   Part of #3170: `http-sink` and `http-source` can send a static bearer token, 
and can accept status codes other than 2xx. A trust store is documented, not 
added as an option (see below).
   
   ### The options
   
   Both are optional, and both use optional placeholders without a `default`. 
When they are not set, the endpoint URI is exactly today's.
   
   | Option | Template mapping | What it does |
   |---|---|---|
   | `authBearerToken` | `authBearerToken: "RAW({{?authBearerToken}})"` | A 
static token, such as an API key, sent as `Authorization: Bearer <token>`. It 
is a secret: `format: password` and `urn:camel:group:credentials`. |
   | `okStatusCodeRange` | `okStatusCodeRange: "{{?okStatusCodeRange}}"` | The 
status codes that do not fail the message (`http-sink`), or that are sent as a 
message (`http-source`), such as `200-299,404`. |
   
   How the HTTP component uses them:
   
   - **The token is used only with `authMethod: Bearer`.** Without it, the 
token is ignored. The token is sent on the first request only with 
`authenticationPreemptive: true`. Without that option, it is sent only after 
the service answers 401 with a `WWW-Authenticate` header that asks for a Bearer 
token. The option descriptions say both.
   - **`RAW()` keeps the token as it is.** A token with `+`, `/` and `=` 
reached the server unchanged.
   - **`okStatusCodeRange` replaces `200-299`.** It does not add to it, so 
`404` alone makes a 200 fail. The description says to list the 2xx codes too. A 
`pattern` rejects spaces, because Camel cannot parse a range with spaces.
   
   `authMethod` now lists `Bearer`. It also says that Basic and Digest login 
work without it. It no longer calls the option a comma-separated list, because 
Camel compares it with a single value.
   
   ### No trust store option
   
   The HTTP endpoint has only one TLS option, `sslContextParameters`, which 
takes a bean. A Kamelet cannot create a bean only when an option is set. A bean 
that is always there would change the calls even when no trust store is given:
   
   - **`http://` turns into `https://`.** camel-http uses TLS whenever 
`sslContextParameters` is set (`HttpComponent`: `secure = 
isSecureConnection(uri) || sslContextParameters != null`). A route that called 
`http://127.0.0.1:18480/echo` with an empty `SSLContextParameters` bean failed 
with `SSLException: Unsupported or unrecognized SSL message`.
   - **TLS settings change.** `SSLContextParameters` applies its own filters 
for protocols and cipher suites. I read this in the code and did not test it.
   
   Camel can already do this at the application level, without changing the 
Java trust store, and it works with these Kamelets today:
   
   ```properties
   camel.ssl.enabled = true
   camel.ssl.trustStore = file:/etc/certs/truststore.p12
   camel.ssl.trustStorePassword = changeit
   camel.component.https.useGlobalSslContextParameters = true
   ```
   
   The property is set on the `https` component: an `https://` URL uses that 
component, so the same setting on `http` has no effect. The trust store then 
**replaces** the Java one for every `https://` call of the application, and the 
`http://` calls do not change. The "Good to know" paragraph of both Kamelets 
and their pages say this.
   
   A trust store set for each Kamelet would need simple endpoint options in 
camel-http, such as `trustStore`, `trustStorePassword` and `trustStoreType`, 
applied only to `https://` addresses. That could be a Camel JIRA.
   
   ### Pages
   
   The pages of both Kamelets still sent readers to the deprecated 
`http-secured-*` Kamelets. They now have:
   
   - a table of the login options, with when each one sends its credentials;
   - examples for the token and for `okStatusCodeRange`;
   - the trust store properties above.
   
   The examples on the pages were run as written.
   
   ### Verification
   
   I used Camel JBang 4.24.0-SNAPSHOT with `--local-kamelet-dir` and a local 
Python server on HTTP and HTTPS. The HTTPS certificate was signed by a private 
test CA. The server logged the `Authorization` header of each request.
   
   | Case | Result |
   |---|---|
   | `http-sink`, `authMethod: Bearer`, token, `authenticationPreemptive: true` 
| First request carries `Authorization: Bearer s3cr3t-T0ken+/=`, 200 |
   | `http-sink`, token, not preemptive, service sends a `WWW-Authenticate: 
Bearer` challenge | 401 without the header, then 200 with the token |
   | `http-sink`, token, not preemptive, service sends 401 with no challenge | 
Fails with 401; the token is never sent |
   | `http-sink`, token and preemptive but no `authMethod` | Fails: `No 
credentials for preemptive authentication` |
   | `http-source`, Bearer token, preemptive | Every poll sends the token, 200 |
   | `http-sink`, 404, option unset | Fails: `HttpOperationFailedException ... 
statusCode: 404` |
   | `http-sink`, 404, `okStatusCodeRange: 200-299,404` | Passes; 
`CamelHttpResponseCode` is 404, the body is the 404 response |
   | `http-sink`, 409, `okStatusCodeRange: 200-299,409` (the page example) | 
Passes with 409 |
   | `http-sink`, 500, `okStatusCodeRange: 200-299,404` | Fails with 500 |
   | `http-sink`, 200, `okStatusCodeRange: 404` | Fails with 200 |
   | `http-source`, 404, option unset | No message; the error is logged at 
every poll |
   | `http-source`, 404, `okStatusCodeRange: 200-299,404` | A message with 
status 404 at every poll |
   | HTTPS with the private CA, nothing set (Kamelets from `main` and from this 
PR) | Both fail: `PKIX path building failed` |
   | HTTPS, CA in the JVM trust store (`-Djavax.net.ssl.trustStore`) | 200, as 
today |
   | HTTPS, `camel.ssl.*` with the trusted CA and 
`camel.component.https.useGlobalSslContextParameters=true` (Kamelets from 
`main` and from this PR) | 200 |
   | The same with a trust store of another CA | Fails: `PKIX path building 
failed` |
   | The same with another CA in `camel.ssl.*`, and the right CA in the JVM 
trust store | Fails: the `camel.ssl` store replaces the JVM one |
   | The same with `camel.component.http.useGlobalSslContextParameters=true` | 
Fails: an `https://` URL uses the `https` component |
   | `http://` call while `camel.ssl.*` is set | 200; plain HTTP is not 
affected |
   | Options unset: `camel get endpoint` for `http-sink` (with and without 
login) and `http-source`, Kamelets from `main` and from this PR | Identical 
URIs, such as `http://127.0.0.1:18480/echo?authenticationPreemptive=false` |
   | Login of #3168: Basic, not preemptive | 401, then 200 with the credentials 
(sink and source) |
   | Login of #3168: OAuth 2.0 client credentials | Token fetched from the 
token URL, then sent as `Bearer` |
   | Digest login, with and without `authMethod: Digest` | 401 challenge, then 
200 |
   | No options, URL with a query `?a=1&b=2` | 200; the query is kept, no 
`Authorization` header |
   
   `./mvnw clean verify -DskipTests` and then `./mvnw clean verify` passed. 
Neither ran `install`. The copies of the Kamelets in `library/camel-kamelets` 
were refreshed with `./mvnw -pl library/camel-kamelets 
resources:copy-resources@copy-resource-one`, and `kamelets-index.json` was 
regenerated by the build.
   
   _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]

Reply via email to