This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new 119abeee1 Fix #3244: http-sink does not send the Authorization header
of the incoming message (#3245)
119abeee1 is described below
commit 119abeee16741b0cfe036ed37fd64791c13629f3
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 19 07:35:42 2026 +0100
Fix #3244: http-sink does not send the Authorization header of the incoming
message (#3245)
http-sink removes the Authorization and Proxy-Authorization headers of
the message before the call, so a credential that came with the message
is not sent on, and the login configured on the Kamelet is not replaced
by it.
Signed-off-by: Claus Ibsen <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
kamelets/http-sink.kamelet.yaml | 8 +-
.../catalog/HttpSinkAuthorizationTest.java | 101 +++++++++++++++++++++
.../main/resources/META-INF/kamelets-index.json | 2 +-
.../main/resources/kamelets/http-sink.kamelet.yaml | 8 +-
4 files changed, 114 insertions(+), 5 deletions(-)
diff --git a/kamelets/http-sink.kamelet.yaml b/kamelets/http-sink.kamelet.yaml
index 2305fc9d5..eeaab7484 100644
--- a/kamelets/http-sink.kamelet.yaml
+++ b/kamelets/http-sink.kamelet.yaml
@@ -35,11 +35,11 @@ spec:
Use it to push data to any service that accepts HTTP calls, such as a
webhook, a REST API or a serverless function.
- Input: the body is sent as the request body, as text, bytes or a stream.
Turn structured data such as a Map into JSON text first, for example with
`json-serialize-action`. The `Content-Type` header is sent as the content type
of the request, and the other headers of the message, except the Camel ones,
are sent as HTTP headers.
+ Input: the body is sent as the request body, as text, bytes or a stream.
Turn structured data such as a Map into JSON text first, for example with
`json-serialize-action`. The `Content-Type` header is sent as the content type
of the request, and the other headers of the message, except the Camel ones and
`Authorization` and `Proxy-Authorization`, are sent as HTTP headers.
Output: when it is used inside a route, the body afterwards is the
response of the service.
- Good to know: a response with a status code outside `okStatusCodeRange`,
which is `200-299` when it is not set, fails the message. The address, the
method and the proxy come only from the options; headers on the message cannot
change where it is sent. Log in either with `authUsername` and `authPassword`,
with a static token in `authBearerToken`, or with `oauth2ClientId`,
`oauth2ClientSecret` and `oauth2TokenEndpoint`: the Kamelet then gets a token
from that URL and sends it as a Be [...]
+ Good to know: a response with a status code outside `okStatusCodeRange`,
which is `200-299` when it is not set, fails the message. The address, the
method and the proxy come only from the options; headers on the message cannot
change where it is sent. The login comes only from the options too: an
`Authorization` or `Proxy-Authorization` header on the message is removed, so a
credential that came with the message, such as the one of the caller of
`webhook-source`, is not sent on. Fo [...]
required:
- url
type: object
@@ -167,6 +167,10 @@ spec:
name: CamelRestHttpUri
- removeHeader:
name: CamelRestHttpQuery
+ - removeHeader:
+ name: Authorization
+ - removeHeader:
+ name: Proxy-Authorization
- setHeader:
name: CamelHttpMethod
expression:
diff --git
a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/HttpSinkAuthorizationTest.java
b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/HttpSinkAuthorizationTest.java
new file mode 100644
index 000000000..05039fca5
--- /dev/null
+++
b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/HttpSinkAuthorizationTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.kamelets.catalog;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.util.Base64;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import com.sun.net.httpserver.HttpServer;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.kamelet.KameletComponent;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Runs http-sink against a local server with an Authorization header on the
message, to check that the login comes
+ * only from the options of the Kamelet.
+ */
+public class HttpSinkAuthorizationTest {
+
+ // the source files, not the catalog jar
+ private static final Path KAMELETS = Path.of("../../kamelets");
+ private static final Map<String, Object> CALLER_CREDENTIALS
+ = Map.of("Authorization", "Bearer caller-token",
"Proxy-Authorization", "Basic Y2FsbGVyOnB3");
+
+ private final BlockingQueue<String> requests = new LinkedBlockingQueue<>();
+ private HttpServer server;
+ private CamelContext context;
+
+ @BeforeEach
+ void start() throws Exception {
+ server = HttpServer.create(new
InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
+ server.createContext("/", http -> {
+ requests.add("authorization=" +
http.getRequestHeaders().getFirst("Authorization")
+ + " proxy-authorization=" +
http.getRequestHeaders().getFirst("Proxy-Authorization"));
+ http.getRequestBody().readAllBytes();
+ http.sendResponseHeaders(200, -1);
+ http.close();
+ });
+ server.start();
+ context = new DefaultCamelContext();
+ context.getComponent("kamelet", KameletComponent.class)
+ .setLocation("file:" + KAMELETS.toAbsolutePath().normalize());
+ context.start();
+ }
+
+ @AfterEach
+ void stop() {
+ if (context != null) {
+ context.stop();
+ }
+ server.stop(0);
+ }
+
+ @Test
+ void credentialOfTheMessageIsNotSentOn() {
+
context.createProducerTemplate().sendBodyAndHeaders("kamelet:http-sink?url=" +
url(), "hello",
+ CALLER_CREDENTIALS);
+
+ assertEquals("authorization=null proxy-authorization=null",
requests.poll());
+ }
+
+ @Test
+ void configuredLoginIsUsedInsteadOfTheMessage() {
+
context.createProducerTemplate().sendBodyAndHeaders("kamelet:http-sink?url=" +
url()
+ +
"&authMethod=Basic&authUsername=operator&authPassword=op-pass"
+ +
"&authenticationPreemptive=true",
+ "hello", CALLER_CREDENTIALS);
+
+ String basic =
Base64.getEncoder().encodeToString("operator:op-pass".getBytes(StandardCharsets.UTF_8));
+ assertEquals("authorization=Basic " + basic + "
proxy-authorization=null", requests.poll());
+ }
+
+ private String url() {
+ return "http://" + InetAddress.getLoopbackAddress().getHostAddress() +
":" + server.getAddress().getPort()
+ + "/target";
+ }
+}
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index eeecf0961..1243111e6 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -1025,7 +1025,7 @@
"supportLevel" : "Stable",
"title" : "HTTP Sink",
"summary" : "Sends each message to a web service or REST API as an HTTP or
HTTPS request, for example a POST of JSON to a webhook.",
- "description" : "Sends each message to a web service or REST API as an
HTTP or HTTPS request, for example a POST of JSON to a webhook.\n\nUse it to
push data to any service that accepts HTTP calls, such as a webhook, a REST API
or a serverless function.\n\nInput: the body is sent as the request body, as
text, bytes or a stream. Turn structured data such as a Map into JSON text
first, for example with `json-serialize-action`. The `Content-Type` header is
sent as the content type of th [...]
+ "description" : "Sends each message to a web service or REST API as an
HTTP or HTTPS request, for example a POST of JSON to a webhook.\n\nUse it to
push data to any service that accepts HTTP calls, such as a webhook, a REST API
or a serverless function.\n\nInput: the body is sent as the request body, as
text, bytes or a stream. Turn structured data such as a Map into JSON text
first, for example with `json-serialize-action`. The `Content-Type` header is
sent as the content type of th [...]
"group" : "HTTP",
"namespace" : "HTTP",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/http-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/http-sink.kamelet.yaml
index 2305fc9d5..eeaab7484 100644
--- a/library/camel-kamelets/src/main/resources/kamelets/http-sink.kamelet.yaml
+++ b/library/camel-kamelets/src/main/resources/kamelets/http-sink.kamelet.yaml
@@ -35,11 +35,11 @@ spec:
Use it to push data to any service that accepts HTTP calls, such as a
webhook, a REST API or a serverless function.
- Input: the body is sent as the request body, as text, bytes or a stream.
Turn structured data such as a Map into JSON text first, for example with
`json-serialize-action`. The `Content-Type` header is sent as the content type
of the request, and the other headers of the message, except the Camel ones,
are sent as HTTP headers.
+ Input: the body is sent as the request body, as text, bytes or a stream.
Turn structured data such as a Map into JSON text first, for example with
`json-serialize-action`. The `Content-Type` header is sent as the content type
of the request, and the other headers of the message, except the Camel ones and
`Authorization` and `Proxy-Authorization`, are sent as HTTP headers.
Output: when it is used inside a route, the body afterwards is the
response of the service.
- Good to know: a response with a status code outside `okStatusCodeRange`,
which is `200-299` when it is not set, fails the message. The address, the
method and the proxy come only from the options; headers on the message cannot
change where it is sent. Log in either with `authUsername` and `authPassword`,
with a static token in `authBearerToken`, or with `oauth2ClientId`,
`oauth2ClientSecret` and `oauth2TokenEndpoint`: the Kamelet then gets a token
from that URL and sends it as a Be [...]
+ Good to know: a response with a status code outside `okStatusCodeRange`,
which is `200-299` when it is not set, fails the message. The address, the
method and the proxy come only from the options; headers on the message cannot
change where it is sent. The login comes only from the options too: an
`Authorization` or `Proxy-Authorization` header on the message is removed, so a
credential that came with the message, such as the one of the caller of
`webhook-source`, is not sent on. Fo [...]
required:
- url
type: object
@@ -167,6 +167,10 @@ spec:
name: CamelRestHttpUri
- removeHeader:
name: CamelRestHttpQuery
+ - removeHeader:
+ name: Authorization
+ - removeHeader:
+ name: Proxy-Authorization
- setHeader:
name: CamelHttpMethod
expression: