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.git
The following commit(s) were added to refs/heads/main by this push:
new 11a7264e7eff CAMEL-27222: camel-platform-http-main, camel-netty-http,
camel-undertow - remove the Authorization header after the login is checked
(#30365)
11a7264e7eff is described below
commit 11a7264e7effdfd3ec8037132adbd1ff23a769f2
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 19 12:54:42 2026 +0100
CAMEL-27222: camel-platform-http-main, camel-netty-http, camel-undertow -
remove the Authorization header after the login is checked (#30365)
When Camel checks the credential of an incoming request, the Authorization
header is removed from the message, as the OAuth bearer token validation
already does: the server-level basic and JWT authentication of
camel-platform-http-main, the basic authentication of camel-netty-http
(securityConfiguration) and the security provider of camel-undertow.
Requests that Camel does not check keep the header. Upgrade guide entry
for 4.24.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../camel/catalog/docs/netty-http-component.adoc | 4 +
.../camel/catalog/docs/platform-http-main.adoc | 6 ++
.../camel/catalog/docs/undertow-component.adoc | 3 +
.../src/main/docs/netty-http-component.adoc | 4 +
.../http/handlers/HttpServerChannelHandler.java | 13 +++
.../NettyHttpBasicAuthConstraintMapperTest.java | 8 +-
.../netty/http/NettyHttpBasicAuthTest.java | 2 +
.../src/main/docs/platform-http-main.adoc | 6 ++
.../BasicAuthenticationMainHttpServerTest.java | 14 +++
.../JWTAuthenticationMainHttpServerTest.java | 17 ++++
.../http/vertx/VertxPlatformHttpConsumer.java | 4 +-
.../http/vertx/VertxPlatformHttpServer.java | 16 ++-
.../vertx/VertxPlatformHttpAuthenticationTest.java | 112 +++++++++++++++++++++
.../src/main/docs/undertow-component.adoc | 3 +
.../camel/component/undertow/UndertowConsumer.java | 5 +-
.../undertow/spi/SecurityProviderTest.java | 16 +++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 16 +++
17 files changed, 244 insertions(+), 5 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-http-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-http-component.adoc
index 5b098510360b..abfeb44607c1 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-http-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/netty-http-component.adoc
@@ -246,6 +246,10 @@ the JAAS based authenticator is used, which will use the
realm name
specified (`_someRealm_` in the example above) and use the JAAS realm and the
`JAAS \{\{LoginModule}}s` of this realm for authentication.
+Once the credential of a request has been checked, the `Authorization` header
is removed from the message, so it is
+not passed on to the route. The `CamelHttpAuthentication` header is still set
to `Basic`. A request to a resource
+that the security constraint does not restrict keeps the header as sent.
+
==== Specifying ACL on web resources
The `org.apache.camel.component.netty.http.SecurityConstraint` allows
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/platform-http-main.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/platform-http-main.adoc
index badb147a9726..42a5c2fc947e 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/platform-http-main.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/platform-http-main.adoc
@@ -153,6 +153,12 @@ Rename the alias of the key to its algorithm, for example:
keytool -changealias -alias keycloak -destalias RS256 -keystore
keycloak-realm.p12 -storetype PKCS12
----
+== The Authorization header
+
+When the server authenticates a request
(`camel.server.authenticationEnabled=true`, with basic or JWT authentication),
+the `Authorization` header of the request is not passed on to the route: it is
removed from the message once the
+credential has been checked. A request to a path that is not under
`authenticationPath` keeps the header as sent.
+
== See More
- xref:platform-http-vertx.adoc[Platform HTTP Vert.x]
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/undertow-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/undertow-component.adoc
index 1f372e399d33..a4f5435ed774 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/undertow-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/undertow-component.adoc
@@ -344,6 +344,9 @@ If there is an object passed to the component as parameter
`securityConfiguratio
Provider will be used
for authentication of all requests.
+Once the security provider has authenticated a request, the `Authorization`
header is removed from the message, so it
+is not passed on to the route. The headers that the provider adds with
`addHeader` are set after that.
+
Property `requireServletContext` of security providers forces the Undertow
server to run
with servlet context, as soon as an endpoint that uses such a provider,
configured on the endpoint
or on the component, is started. There will be no servlet actually handled.
This feature is meant only
diff --git
a/components/camel-netty-http/src/main/docs/netty-http-component.adoc
b/components/camel-netty-http/src/main/docs/netty-http-component.adoc
index 5b098510360b..abfeb44607c1 100644
--- a/components/camel-netty-http/src/main/docs/netty-http-component.adoc
+++ b/components/camel-netty-http/src/main/docs/netty-http-component.adoc
@@ -246,6 +246,10 @@ the JAAS based authenticator is used, which will use the
realm name
specified (`_someRealm_` in the example above) and use the JAAS realm and the
`JAAS \{\{LoginModule}}s` of this realm for authentication.
+Once the credential of a request has been checked, the `Authorization` header
is removed from the message, so it is
+not passed on to the route. The `CamelHttpAuthentication` header is still set
to `Basic`. A request to a resource
+that the security constraint does not restrict keeps the header as sent.
+
==== Specifying ACL on web resources
The `org.apache.camel.component.netty.http.SecurityConstraint` allows
diff --git
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
index a5fb044cbd84..44b77b33b659 100644
---
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
+++
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java
@@ -39,6 +39,7 @@ import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.ssl.SslHandler;
+import io.netty.util.AttributeKey;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePropertyKey;
import org.apache.camel.LoggingLevel;
@@ -78,6 +79,11 @@ import static
io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
public class HttpServerChannelHandler extends ServerChannelHandler {
private static final Logger LOG =
LoggerFactory.getLogger(HttpServerChannelHandler.class);
+
+ // whether the basic auth credential of the request being read has been
checked by Camel, so that beforeProcess
+ // (called by channelRead0 of the super class on the same thread) removes
the Authorization header from the message
+ private static final AttributeKey<Boolean> BASIC_AUTH_CHECKED
+ = AttributeKey.valueOf(HttpServerChannelHandler.class.getName() +
".basicAuthChecked");
private final NettyHttpConsumer consumer;
public HttpServerChannelHandler(NettyHttpConsumer consumer) {
@@ -157,6 +163,7 @@ public class HttpServerChannelHandler extends
ServerChannelHandler {
}
// is basic auth configured
+ boolean basicAuthChecked = false;
NettyHttpSecurityConfiguration security =
consumer.getEndpoint().getSecurityConfiguration();
if (security != null && security.isAuthenticate() &&
"Basic".equalsIgnoreCase(security.getConstraint())) {
String url = request.uri();
@@ -235,11 +242,13 @@ public class HttpServerChannelHandler extends
ServerChannelHandler {
return;
} else {
LOG.debug("Http Basic Auth authorized for username: {}",
principal.getUsername());
+ basicAuthChecked = true;
}
}
}
// let Camel process this message
+ ctx.channel().attr(BASIC_AUTH_CHECKED).set(basicAuthChecked);
super.channelRead0(ctx, msg);
}
@@ -446,6 +455,10 @@ public class HttpServerChannelHandler extends
ServerChannelHandler {
}
final Message in = exchange.getIn();
+ if
(Boolean.TRUE.equals(ctx.channel().attr(BASIC_AUTH_CHECKED).getAndSet(null))) {
+ // the credential has been checked by Camel, so it is not passed
on to the route
+ OAuthHttpSecuritySupport.removeAuthorizationHeader(in);
+ }
OAuthHttpSecuritySupport security =
consumer.getEndpoint().getOauthHttpSecurity();
if (security != null) {
Validation validation = security.validate(
diff --git
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthConstraintMapperTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthConstraintMapperTest.java
index 332cbeaaf095..f639a5a3db6e 100644
---
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthConstraintMapperTest.java
+++
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthConstraintMapperTest.java
@@ -61,10 +61,14 @@ public class NettyHttpBasicAuthConstraintMapperTest extends
BaseNettyTestSupport
@Test
public void testBasicAuth() throws Exception {
getMockEndpoint("mock:input").expectedBodiesReceived("Hello Public",
"Hello World");
+ // the public page is not checked, so its Authorization header is kept
+
getMockEndpoint("mock:input").message(0).header("Authorization").isEqualTo("Basic
Zm9vOmJhcg==");
+ // the credential checked by Camel is not passed on to the route
+
getMockEndpoint("mock:input").message(1).header("Authorization").isNull();
// we dont need auth for the public page
- String out =
template.requestBody("netty-http:http://localhost:{{port}}/foo/public/hello.txt",
"Hello Public",
- String.class);
+ String out =
template.requestBodyAndHeader("netty-http:http://localhost:{{port}}/foo/public/hello.txt",
+ "Hello Public", "Authorization", "Basic Zm9vOmJhcg==",
String.class);
assertEquals("Bye World", out);
CamelExecutionException e = assertThrows(CamelExecutionException.class,
diff --git
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthTest.java
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthTest.java
index e954d35548ca..e10b55792afa 100644
---
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthTest.java
+++
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthTest.java
@@ -62,6 +62,8 @@ public class NettyHttpBasicAuthTest extends
BaseNettyTestSupport {
public void testBasicAuthSuccessed() throws Exception {
getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:input").expectedHeaderReceived(NettyHttpConstants.HTTP_AUTHENTICATION,
"Basic");
+ // the credential checked by Camel is not passed on to the route
+
getMockEndpoint("mock:input").message(0).header("Authorization").isNull();
// username:password is scott:secret
String auth = "Basic c2NvdHQ6c2VjcmV0";
diff --git
a/components/camel-platform-http-main/src/main/docs/platform-http-main.adoc
b/components/camel-platform-http-main/src/main/docs/platform-http-main.adoc
index badb147a9726..42a5c2fc947e 100644
--- a/components/camel-platform-http-main/src/main/docs/platform-http-main.adoc
+++ b/components/camel-platform-http-main/src/main/docs/platform-http-main.adoc
@@ -153,6 +153,12 @@ Rename the alias of the key to its algorithm, for example:
keytool -changealias -alias keycloak -destalias RS256 -keystore
keycloak-realm.p12 -storetype PKCS12
----
+== The Authorization header
+
+When the server authenticates a request
(`camel.server.authenticationEnabled=true`, with basic or JWT authentication),
+the `Authorization` header of the request is not passed on to the route: it is
removed from the message once the
+credential has been checked. A request to a path that is not under
`authenticationPath` keeps the header as sent.
+
== See More
- xref:platform-http-vertx.adoc[Platform HTTP Vert.x]
diff --git
a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationMainHttpServerTest.java
b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationMainHttpServerTest.java
index 17294503a96d..f03d0871f944 100644
---
a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationMainHttpServerTest.java
+++
b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/BasicAuthenticationMainHttpServerTest.java
@@ -70,6 +70,17 @@ public class BasicAuthenticationMainHttpServerTest {
.body(equalTo("main-http-auth-basic-test-response"));
}
+ @Test
+ public void testAuthorizationHeaderNotPassedOnToRoute() {
+ given()
+ .auth().preemptive().basic("camel", "propertiesPass")
+ .when()
+ .get("/main-http-authorization")
+ .then()
+ .statusCode(200)
+ .body(equalTo("authorization="));
+ }
+
private static class PlatformHttpRouteBuilder extends RouteBuilder {
@Override
@@ -77,6 +88,9 @@ public class BasicAuthenticationMainHttpServerTest {
from("platform-http:/main-http-test")
.log("Received request with headers: ${headers}\nWith
body: ${body}")
.setBody(simple("main-http-auth-basic-test-response"));
+
+ from("platform-http:/main-http-authorization")
+ .setBody(simple("authorization=${header.Authorization}"));
}
}
}
diff --git
a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationMainHttpServerTest.java
b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationMainHttpServerTest.java
index fe7e746bd6bd..82c4d7bf66f4 100644
---
a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationMainHttpServerTest.java
+++
b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/authentication/JWTAuthenticationMainHttpServerTest.java
@@ -95,6 +95,20 @@ public class JWTAuthenticationMainHttpServerTest {
.body(equalTo("Unauthorized"));
}
+ @Test
+ void testAuthorizationHeaderNotPassedOnToRoute() {
+ String validToken
+ = jwtAuth.generateToken(new JsonObject().put("admin",
"camel"), new JWTOptions().setAlgorithm("RS256"));
+
+ given()
+ .header("Authorization", "Bearer " + validToken)
+ .when()
+ .get("/main-http-authorization")
+ .then()
+ .statusCode(200)
+ .body(equalTo("authorization="));
+ }
+
private static class PlatformHttpRouteBuilder extends RouteBuilder {
@Override
@@ -102,6 +116,9 @@ public class JWTAuthenticationMainHttpServerTest {
from("platform-http:/main-http-test")
.log("Received request with headers: ${headers}\nWith
body: ${body}")
.setBody(simple("main-http-auth-jwt-test-response"));
+
+ from("platform-http:/main-http-authorization")
+ .setBody(simple("authorization=${header.Authorization}"));
}
}
}
diff --git
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
index 1f725df7b368..6f19718b9004 100644
---
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
+++
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
@@ -543,7 +543,9 @@ public class VertxPlatformHttpConsumer extends
DefaultConsumer
String httpPath = (String) message.getHeader(Exchange.HTTP_PATH);
message.setHeader(Exchange.HTTP_PATH,
HttpHelper.stripUriPrefix(httpPath, getEndpoint().getPath()));
}
- if (securityHandler != null) {
+ if (securityHandler != null ||
Boolean.TRUE.equals(ctx.get(VertxPlatformHttpServer.AUTHENTICATED_BY_SERVER))) {
+ // the credential has been checked by Camel (the security handler
of the endpoint, or the authentication
+ // configured on the server), so it is not passed on to the route
message.removeHeader(AUTHORIZATION);
}
return httpRequestBodyHandler.handle(ctx, message);
diff --git
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
index 98d0195f7447..8251db4d3ebc 100644
---
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
+++
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
@@ -56,6 +56,12 @@ import static
org.apache.camel.component.platform.http.vertx.VertxPlatformHttpSe
public class VertxPlatformHttpServer extends ServiceSupport implements
CamelContextAware, StaticService {
private static final Logger LOGGER =
LoggerFactory.getLogger(VertxPlatformHttpServer.class);
+ /**
+ * Routing context key set when the request passed an authentication
handler of the server; the consumer then
+ * removes the Authorization header from the Camel message.
+ */
+ static final String AUTHENTICATED_BY_SERVER =
VertxPlatformHttpServer.class.getName() + ".authenticated";
+
private final VertxPlatformHttpServerConfiguration configuration;
private CamelContext context;
@@ -348,7 +354,15 @@ public class VertxPlatformHttpServer extends
ServiceSupport implements CamelCont
authenticationConfig.getEntries()
.stream()
.sorted(this::compareUrlPathsSpecificity)
- .forEach(entry ->
subRouter.route(entry.getPath()).handler(entry.createAuthenticationHandler(vertx)));
+ .forEach(entry -> subRouter.route(entry.getPath())
+ .handler(entry.createAuthenticationHandler(vertx))
+ .handler(VertxPlatformHttpServer::markAuthenticated));
+ }
+
+ private static void markAuthenticated(RoutingContext ctx) {
+ // the request passed the authentication handler: the credential it
carried has been checked
+ ctx.put(AUTHENTICATED_BY_SERVER, Boolean.TRUE);
+ ctx.next();
}
private int compareUrlPathsSpecificity(AuthenticationConfigEntry entry1,
AuthenticationConfigEntry entry2) {
diff --git
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpAuthenticationTest.java
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpAuthenticationTest.java
index 904b5c336a99..0f3977952e22 100644
---
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpAuthenticationTest.java
+++
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpAuthenticationTest.java
@@ -18,10 +18,19 @@ package org.apache.camel.component.platform.http.vertx;
import io.restassured.RestAssured;
import io.vertx.core.Future;
+import io.vertx.core.Vertx;
+import io.vertx.core.json.JsonObject;
+import io.vertx.ext.auth.JWTOptions;
+import io.vertx.ext.auth.PubSecKeyOptions;
import io.vertx.ext.auth.User;
+import io.vertx.ext.auth.authentication.AuthenticationProvider;
import io.vertx.ext.auth.authentication.UsernamePasswordCredentials;
+import io.vertx.ext.auth.jwt.JWTAuth;
+import io.vertx.ext.auth.jwt.JWTAuthOptions;
import io.vertx.ext.auth.properties.PropertyFileAuthentication;
+import io.vertx.ext.web.handler.AuthenticationHandler;
import io.vertx.ext.web.handler.BasicAuthHandler;
+import io.vertx.ext.web.handler.JWTAuthHandler;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import
org.apache.camel.component.platform.http.vertx.auth.AuthenticationConfig;
@@ -252,6 +261,109 @@ public class VertxPlatformHttpAuthenticationTest {
}
}
+ @Test
+ public void testBasicAuthenticationRemovesAuthorizationHeader() throws
Exception {
+ CamelContext context = createCamelContext(authenticationConfig -> {
+ authenticationConfig.setEnabled(true);
+ AuthenticationConfigEntry entry = new AuthenticationConfigEntry();
+ entry.setAuthenticationProviderFactory(
+ vertx -> PropertyFileAuthentication.create(vertx,
"camel-platform-http-vertx-auth.properties"));
+ entry.setAuthenticationHandlerFactory(BasicAuthHandler::create);
+ entry.setPath("/protected");
+ authenticationConfig.getEntries().add(entry);
+ });
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/protected")
+
.setBody().simple("authorization=${header.Authorization}");
+
+ from("platform-http:/unprotected")
+
.setBody().simple("authorization=${header.Authorization}");
+ }
+ });
+
+ try {
+ context.start();
+
+ // the credential checked by Camel is not passed on to the route
+ given()
+ .auth().preemptive().basic("camel", "propertiesPass")
+ .when()
+ .get("/protected")
+ .then()
+ .statusCode(200)
+ .body(equalTo("authorization="));
+
+ // a path without authentication keeps the header as is
+ given()
+ .header("Authorization", "Basic Zm9vOmJhcg==")
+ .when()
+ .get("/unprotected")
+ .then()
+ .statusCode(200)
+ .body(equalTo("authorization=Basic Zm9vOmJhcg=="));
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ public void testJWTAuthenticationRemovesAuthorizationHeader() throws
Exception {
+ JWTAuthOptions jwtAuthOptions = new JWTAuthOptions()
+ .addPubSecKey(new
PubSecKeyOptions().setAlgorithm("HS256").setBuffer("test-secret-for-the-jwt-tokens"));
+
+ CamelContext context = createCamelContext(authenticationConfig -> {
+ authenticationConfig.setEnabled(true);
+ AuthenticationConfigEntry entry = new AuthenticationConfigEntry();
+ entry.setAuthenticationProviderFactory(vertx ->
JWTAuth.create(vertx, jwtAuthOptions));
+ entry.setAuthenticationHandlerFactory(
+ new AuthenticationHandlerFactory() {
+ @Override
+ public <T extends AuthenticationProvider>
AuthenticationHandler createAuthenticationHandler(
+ T authenticationProvider) {
+ return JWTAuthHandler.create((JWTAuth)
authenticationProvider);
+ }
+ });
+ entry.setPath("/*");
+ authenticationConfig.getEntries().add(entry);
+ });
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/jwt")
+
.setBody().simple("authorization=${header.Authorization}");
+ }
+ });
+
+ Vertx tokenVertx = Vertx.vertx();
+ try {
+ context.start();
+
+ String token = JWTAuth.create(tokenVertx, jwtAuthOptions)
+ .generateToken(new JsonObject().put("sub", "camel"), new
JWTOptions().setAlgorithm("HS256"));
+
+ given()
+ .when()
+ .get("/jwt")
+ .then()
+ .statusCode(401);
+
+ given()
+ .header("Authorization", "Bearer " + token)
+ .when()
+ .get("/jwt")
+ .then()
+ .statusCode(200)
+ .body(equalTo("authorization="));
+ } finally {
+ context.stop();
+ tokenVertx.close();
+ }
+ }
+
private AuthenticationProviderFactory createCustomProvider(String
username, String pass) {
return vertx -> credentials -> {
UsernamePasswordCredentials usernamePassword =
(UsernamePasswordCredentials) credentials;
diff --git a/components/camel-undertow/src/main/docs/undertow-component.adoc
b/components/camel-undertow/src/main/docs/undertow-component.adoc
index 1f372e399d33..a4f5435ed774 100644
--- a/components/camel-undertow/src/main/docs/undertow-component.adoc
+++ b/components/camel-undertow/src/main/docs/undertow-component.adoc
@@ -344,6 +344,9 @@ If there is an object passed to the component as parameter
`securityConfiguratio
Provider will be used
for authentication of all requests.
+Once the security provider has authenticated a request, the `Authorization`
header is removed from the message, so it
+is not passed on to the route. The headers that the provider adds with
`addHeader` are set after that.
+
Property `requireServletContext` of security providers forces the Undertow
server to run
with servlet context, as soon as an endpoint that uses such a provider,
configured on the endpoint
or on the component, is started. There will be no servlet actually handled.
This feature is meant only
diff --git
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
index 834fa859593a..94f75655e54e 100644
---
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
+++
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
@@ -421,8 +421,11 @@ public class UndertowConsumer extends DefaultConsumer
implements HttpHandler, Su
exchange.setProperty(OAuthHttpSecuritySupport.OAUTH_TOKEN_VALIDATION_RESULT,
oauthTokenValidationResult);
}
- //securityProvider could add its own header into result exchange
if (getEndpoint().getSecurityProvider() != null) {
+ // the request has been authenticated by the securityProvider (see
handleRequest), so the credential is not
+ // passed on to the route
+ OAuthHttpSecuritySupport.removeAuthorizationHeader(in);
+ //securityProvider could add its own header into result exchange
getEndpoint().getSecurityProvider().addHeader((key, value) ->
in.setHeader(key, value), httpExchange);
}
diff --git
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/spi/SecurityProviderTest.java
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/spi/SecurityProviderTest.java
index d9c3ba8f0dbb..5a8447596fe6 100644
---
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/spi/SecurityProviderTest.java
+++
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/spi/SecurityProviderTest.java
@@ -45,6 +45,22 @@ public class SecurityProviderTest extends
AbstractSecurityProviderTest {
MockEndpoint.assertIsSatisfied(context);
}
+ @Test
+ public void testSecuredAllowedRemovesAuthorizationHeader() throws
Exception {
+ securityConfiguration.setRoleToAssign("user");
+
+ getMockEndpoint("mock:input").expectedMessageCount(1);
+ // the credential checked by Camel is not passed on to the route
+
getMockEndpoint("mock:input").message(0).header("Authorization").isNull();
+
+ String out =
template.requestBodyAndHeader("undertow:http://localhost:{{port}}/foo", null,
"Authorization",
+ "Basic c2NvdHQ6c2VjcmV0", String.class);
+
+ assertEquals("user", out);
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
@Test
public void testSecuredNotAllowed() {
securityConfiguration.setRoleToAssign("admin");
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 06a65126c967..b83d3516b77b 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -954,6 +954,22 @@ is now sent with the first request; before, the request
failed with `IllegalStat
when `authDomain` is not set. Before, the endpoint answered only Basic and
Digest challenges with these credentials,
and the component did not use them. If the server asks for Basic credentials,
remove `authMethod=NTLM`.
+=== camel-platform-http-main, camel-netty-http, camel-undertow - the
Authorization header is removed after the login is checked
+
+When Camel checks the credential of an incoming request, the `Authorization`
header of the request is now removed from
+the message before the route gets it, as the OAuth bearer token validation of
these components already does since
+Camel 4.21. This applies to:
+
+* camel-platform-http-main: the requests under
`camel.server.authenticationPath` when
+ `camel.server.authenticationEnabled=true`, with basic
(`basicPropertiesFile`) or JWT authentication.
+* camel-netty-http: the requests that are checked with basic authentication
(`securityConfiguration`).
+* camel-undertow: the requests that a security provider
(`UndertowSecurityProvider`) has authenticated.
+
+Before, the header was passed on to the route, and from there to the steps
that use the message headers, such as a
+log of the headers or a producer that sends them on. A request that Camel does
not check, for example to a path outside
+`authenticationPath` or to a resource that the netty-http security constraint
does not restrict, keeps the header as
+sent. A route that has to call a backend with credentials sets them on that
producer.
+
=== camel-mdc - camel.routeId is the route being run
The `camel.routeId` MDC value is now the id of the route that runs the step,
as with the deprecated