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 7a1a5675dc33 CAMEL-27122: camel-http - oauthProfile option sends the
bearer token per HTTP request (#31135)
7a1a5675dc33 is described below
commit 7a1a5675dc3373b634b2b814374c4cdc2bdfbd59
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Dec 1 09:42:27 2026 +0100
CAMEL-27122: camel-http - oauthProfile option sends the bearer token per
HTTP request (#31135)
Adds the oauthProfile option to the camel-http endpoint. It names a
camel-oauth
profile, and a request interceptor attaches its bearer token to every HTTP
request, so a rotated token is picked up without restarting the route. The
token is only sent to the endpoint's own authority, so a redirect to another
host or port does not leak it. When oauth2* options are also set, the
oauth2*
token wins and a WARN is logged at startup; a WARN is also logged when a
custom
httpClient is used. Documentation and generated files are updated.
Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet
Co-authored-by: Claude Sonnet 4 <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../org/apache/camel/catalog/components/http.json | 7 +-
.../org/apache/camel/catalog/components/https.json | 7 +-
.../apache/camel/catalog/docs/http-component.adoc | 54 ++++++++
.../component/http/HttpEndpointConfigurer.java | 6 +
.../component/http/HttpEndpointUriFactory.java | 3 +-
.../org/apache/camel/component/http/http.json | 7 +-
.../org/apache/camel/component/http/https.json | 7 +-
.../camel-http/src/main/docs/http-component.adoc | 54 ++++++++
.../component/http/CompositeHttpConfigurer.java | 15 +++
.../apache/camel/component/http/HttpEndpoint.java | 83 +++++++++++++
.../component/http/OAuth2ClientConfigurer.java | 33 ++++-
.../http/HttpOAuth2RedirectTokenLeakTest.java | 43 +++++++
.../http/HttpOAuthProfileProducerTest.java | 137 +++++++++++++++++++++
.../http/StubOAuthClientAuthenticationFactory.java | 66 ++++++++++
.../camel/oauth-client-authentication-factory | 17 +++
.../endpoint/dsl/HttpEndpointBuilderFactory.java | 19 +++
16 files changed, 539 insertions(+), 19 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/http.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/http.json
index cff0ec9b824f..93e0fbed08a5 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/http.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/http.json
@@ -169,8 +169,9 @@
"oauth2ResourceIndicator": { "index": 64, "kind": "parameter",
"displayName": "Oauth2 Resource Indicator", "group": "security", "label":
"producer,security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "OAuth2 Token endpoint" },
"oauth2Scope": { "index": 65, "kind": "parameter", "displayName": "Oauth2
Scope", "group": "security", "label": "producer,security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "OAuth2 scope" },
"oauth2TokenEndpoint": { "index": 66, "kind": "parameter", "displayName":
"Oauth2 Token Endpoint", "group": "security", "label": "producer,security",
"required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description":
"OAuth2 Resource Indicator" },
- "sslContextParameters": { "index": 67, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure security
using SSLContextParameters. This takes precedence over the sslContextParameters
of the component, so endpoints of the same component can use diffe [...]
- "x509HostnameVerifier": { "index": 68, "kind": "parameter", "displayName":
"X509 Hostname Verifier", "group": "security", "label": "security", "required":
false, "type": "object", "javaType": "javax.net.ssl.HostnameVerifier",
"deprecated": false, "autowired": false, "secret": false, "security":
"insecure:ssl", "description": "To use a custom X509HostnameVerifier such as
DefaultHostnameVerifier or NoopHostnameVerifier" },
- "oauth2CachedTokensKeyResolver": { "index": 69, "kind": "parameter",
"displayName": "Oauth2 Cached Tokens Key Resolver", "group": "security
(advanced)", "label": "producer,security,advanced", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.http.OAuth2CachedTokensKeyResolver", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
strategy to compute the key of cached OAuth2 tokens when oauth2CacheTokens is
enabled. When [...]
+ "oauthProfile": { "index": 67, "kind": "parameter", "displayName": "Oauth
Profile", "group": "security", "label": "producer,security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "The name of a camel-oauth
profile to use for outgoing requests. When set, a bearer token is resolved per
HTTP request using the named profile (properties under camel.oauth.NAME.*) and
injected as an Authorizati [...]
+ "sslContextParameters": { "index": 68, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure security
using SSLContextParameters. This takes precedence over the sslContextParameters
of the component, so endpoints of the same component can use diffe [...]
+ "x509HostnameVerifier": { "index": 69, "kind": "parameter", "displayName":
"X509 Hostname Verifier", "group": "security", "label": "security", "required":
false, "type": "object", "javaType": "javax.net.ssl.HostnameVerifier",
"deprecated": false, "autowired": false, "secret": false, "security":
"insecure:ssl", "description": "To use a custom X509HostnameVerifier such as
DefaultHostnameVerifier or NoopHostnameVerifier" },
+ "oauth2CachedTokensKeyResolver": { "index": 70, "kind": "parameter",
"displayName": "Oauth2 Cached Tokens Key Resolver", "group": "security
(advanced)", "label": "producer,security,advanced", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.http.OAuth2CachedTokensKeyResolver", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
strategy to compute the key of cached OAuth2 tokens when oauth2CacheTokens is
enabled. When [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/https.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/https.json
index dd7d7e23b715..fcadadfdf4cc 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/https.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/https.json
@@ -169,8 +169,9 @@
"oauth2ResourceIndicator": { "index": 64, "kind": "parameter",
"displayName": "Oauth2 Resource Indicator", "group": "security", "label":
"producer,security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "OAuth2 Token endpoint" },
"oauth2Scope": { "index": 65, "kind": "parameter", "displayName": "Oauth2
Scope", "group": "security", "label": "producer,security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "OAuth2 scope" },
"oauth2TokenEndpoint": { "index": 66, "kind": "parameter", "displayName":
"Oauth2 Token Endpoint", "group": "security", "label": "producer,security",
"required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description":
"OAuth2 Resource Indicator" },
- "sslContextParameters": { "index": 67, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure security
using SSLContextParameters. This takes precedence over the sslContextParameters
of the component, so endpoints of the same component can use diffe [...]
- "x509HostnameVerifier": { "index": 68, "kind": "parameter", "displayName":
"X509 Hostname Verifier", "group": "security", "label": "security", "required":
false, "type": "object", "javaType": "javax.net.ssl.HostnameVerifier",
"deprecated": false, "autowired": false, "secret": false, "security":
"insecure:ssl", "description": "To use a custom X509HostnameVerifier such as
DefaultHostnameVerifier or NoopHostnameVerifier" },
- "oauth2CachedTokensKeyResolver": { "index": 69, "kind": "parameter",
"displayName": "Oauth2 Cached Tokens Key Resolver", "group": "security
(advanced)", "label": "producer,security,advanced", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.http.OAuth2CachedTokensKeyResolver", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
strategy to compute the key of cached OAuth2 tokens when oauth2CacheTokens is
enabled. When [...]
+ "oauthProfile": { "index": 67, "kind": "parameter", "displayName": "Oauth
Profile", "group": "security", "label": "producer,security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "The name of a camel-oauth
profile to use for outgoing requests. When set, a bearer token is resolved per
HTTP request using the named profile (properties under camel.oauth.NAME.*) and
injected as an Authorizati [...]
+ "sslContextParameters": { "index": 68, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure security
using SSLContextParameters. This takes precedence over the sslContextParameters
of the component, so endpoints of the same component can use diffe [...]
+ "x509HostnameVerifier": { "index": 69, "kind": "parameter", "displayName":
"X509 Hostname Verifier", "group": "security", "label": "security", "required":
false, "type": "object", "javaType": "javax.net.ssl.HostnameVerifier",
"deprecated": false, "autowired": false, "secret": false, "security":
"insecure:ssl", "description": "To use a custom X509HostnameVerifier such as
DefaultHostnameVerifier or NoopHostnameVerifier" },
+ "oauth2CachedTokensKeyResolver": { "index": 70, "kind": "parameter",
"displayName": "Oauth2 Cached Tokens Key Resolver", "group": "security
(advanced)", "label": "producer,security,advanced", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.http.OAuth2CachedTokensKeyResolver", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
strategy to compute the key of cached OAuth2 tokens when oauth2CacheTokens is
enabled. When [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/http-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/http-component.adoc
index 539021c12d35..cf84d5e0dd55 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/http-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/http-component.adoc
@@ -980,6 +980,60 @@ all routes and their endpoints from the updated component
configuration after ea
No special configuration is needed for `camel-http`: the fresh endpoints
created during the route
restart carry the newly resolved credentials.
+=== camel-oauth Profile Support
+
+The `oauthProfile` endpoint option integrates with
xref:components:others:oauth.adoc[camel-oauth] to resolve a bearer token per
HTTP request without managing the token endpoint credentials on every endpoint
URI.
+
+Set `oauthProfile` to the name of a profile configured under
`camel.oauth.<profileName>.*` in your application properties. On each outgoing
request Camel resolves a fresh bearer token (or reuses the cached one until it
expires) from that profile and injects it as an `Authorization: Bearer` header.
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("direct:start")
+ .to("https://api.example.com/data?oauthProfile=myProfile");
+----
+
+XML::
++
+[source,xml]
+----
+<route>
+ <from uri="direct:start"/>
+ <to uri="https://api.example.com/data?oauthProfile=myProfile"/>
+</route>
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - to:
+ uri: "https://api.example.com/data"
+ parameters:
+ oauthProfile: myProfile
+----
+====
+
+The profile properties follow the camel-oauth convention:
+
+[source,properties]
+----
+camel.oauth.myProfile.client-id=my-client-id
+camel.oauth.myProfile.client-secret=my-client-secret
+camel.oauth.myProfile.token-endpoint=https://idp.example.com/token
+----
+
+NOTE: The bearer token is only attached to requests directed at the endpoint's
own authority (scheme, host, and port). Redirects to a different host or port
do not receive it, preventing accidental token leakage.
+
+NOTE: `oauthProfile` requires `camel-oauth` on the classpath. It can be used
alongside the `oauth2*` options: `oauth2*` options manage the full OAuth2
credential flow on the endpoint URI, while `oauthProfile` delegates token
acquisition to a named camel-oauth profile. If both are set, the `oauth2*`
token is used and a WARN is logged at startup.
+
=== Logging HTTP activity
With `logHttpActivity=true` (on the component or the endpoint), the HTTP
requests that are sent and the HTTP
diff --git
a/components/camel-http/src/generated/java/org/apache/camel/component/http/HttpEndpointConfigurer.java
b/components/camel-http/src/generated/java/org/apache/camel/component/http/HttpEndpointConfigurer.java
index 63ed10ffffc3..bdcf846ae9d1 100644
---
a/components/camel-http/src/generated/java/org/apache/camel/component/http/HttpEndpointConfigurer.java
+++
b/components/camel-http/src/generated/java/org/apache/camel/component/http/HttpEndpointConfigurer.java
@@ -122,6 +122,8 @@ public class HttpEndpointConfigurer extends
PropertyConfigurerSupport implements
case "oauth2Scope": target.setOauth2Scope(property(camelContext,
java.lang.String.class, value)); return true;
case "oauth2tokenendpoint":
case "oauth2TokenEndpoint":
target.setOauth2TokenEndpoint(property(camelContext, java.lang.String.class,
value)); return true;
+ case "oauthprofile":
+ case "oauthProfile": target.setOauthProfile(property(camelContext,
java.lang.String.class, value)); return true;
case "okstatuscoderange":
case "okStatusCodeRange":
target.setOkStatusCodeRange(property(camelContext, java.lang.String.class,
value)); return true;
case "preservehostheader":
@@ -267,6 +269,8 @@ public class HttpEndpointConfigurer extends
PropertyConfigurerSupport implements
case "oauth2Scope": return java.lang.String.class;
case "oauth2tokenendpoint":
case "oauth2TokenEndpoint": return java.lang.String.class;
+ case "oauthprofile":
+ case "oauthProfile": return java.lang.String.class;
case "okstatuscoderange":
case "okStatusCodeRange": return java.lang.String.class;
case "preservehostheader":
@@ -413,6 +417,8 @@ public class HttpEndpointConfigurer extends
PropertyConfigurerSupport implements
case "oauth2Scope": return target.getOauth2Scope();
case "oauth2tokenendpoint":
case "oauth2TokenEndpoint": return target.getOauth2TokenEndpoint();
+ case "oauthprofile":
+ case "oauthProfile": return target.getOauthProfile();
case "okstatuscoderange":
case "okStatusCodeRange": return target.getOkStatusCodeRange();
case "preservehostheader":
diff --git
a/components/camel-http/src/generated/java/org/apache/camel/component/http/HttpEndpointUriFactory.java
b/components/camel-http/src/generated/java/org/apache/camel/component/http/HttpEndpointUriFactory.java
index a2597b3ccdec..86b868d39474 100644
---
a/components/camel-http/src/generated/java/org/apache/camel/component/http/HttpEndpointUriFactory.java
+++
b/components/camel-http/src/generated/java/org/apache/camel/component/http/HttpEndpointUriFactory.java
@@ -25,7 +25,7 @@ public class HttpEndpointUriFactory extends
org.apache.camel.support.component.E
private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
private static final Map<String, String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(70);
+ Set<String> props = new HashSet<>(71);
props.add("authBearerToken");
props.add("authDomain");
props.add("authHost");
@@ -76,6 +76,7 @@ public class HttpEndpointUriFactory extends
org.apache.camel.support.component.E
props.add("oauth2ResourceIndicator");
props.add("oauth2Scope");
props.add("oauth2TokenEndpoint");
+ props.add("oauthProfile");
props.add("okStatusCodeRange");
props.add("preserveHostHeader");
props.add("proxyAuthDomain");
diff --git
a/components/camel-http/src/generated/resources/META-INF/org/apache/camel/component/http/http.json
b/components/camel-http/src/generated/resources/META-INF/org/apache/camel/component/http/http.json
index cff0ec9b824f..93e0fbed08a5 100644
---
a/components/camel-http/src/generated/resources/META-INF/org/apache/camel/component/http/http.json
+++
b/components/camel-http/src/generated/resources/META-INF/org/apache/camel/component/http/http.json
@@ -169,8 +169,9 @@
"oauth2ResourceIndicator": { "index": 64, "kind": "parameter",
"displayName": "Oauth2 Resource Indicator", "group": "security", "label":
"producer,security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "OAuth2 Token endpoint" },
"oauth2Scope": { "index": 65, "kind": "parameter", "displayName": "Oauth2
Scope", "group": "security", "label": "producer,security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "OAuth2 scope" },
"oauth2TokenEndpoint": { "index": 66, "kind": "parameter", "displayName":
"Oauth2 Token Endpoint", "group": "security", "label": "producer,security",
"required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description":
"OAuth2 Resource Indicator" },
- "sslContextParameters": { "index": 67, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure security
using SSLContextParameters. This takes precedence over the sslContextParameters
of the component, so endpoints of the same component can use diffe [...]
- "x509HostnameVerifier": { "index": 68, "kind": "parameter", "displayName":
"X509 Hostname Verifier", "group": "security", "label": "security", "required":
false, "type": "object", "javaType": "javax.net.ssl.HostnameVerifier",
"deprecated": false, "autowired": false, "secret": false, "security":
"insecure:ssl", "description": "To use a custom X509HostnameVerifier such as
DefaultHostnameVerifier or NoopHostnameVerifier" },
- "oauth2CachedTokensKeyResolver": { "index": 69, "kind": "parameter",
"displayName": "Oauth2 Cached Tokens Key Resolver", "group": "security
(advanced)", "label": "producer,security,advanced", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.http.OAuth2CachedTokensKeyResolver", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
strategy to compute the key of cached OAuth2 tokens when oauth2CacheTokens is
enabled. When [...]
+ "oauthProfile": { "index": 67, "kind": "parameter", "displayName": "Oauth
Profile", "group": "security", "label": "producer,security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "The name of a camel-oauth
profile to use for outgoing requests. When set, a bearer token is resolved per
HTTP request using the named profile (properties under camel.oauth.NAME.*) and
injected as an Authorizati [...]
+ "sslContextParameters": { "index": 68, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure security
using SSLContextParameters. This takes precedence over the sslContextParameters
of the component, so endpoints of the same component can use diffe [...]
+ "x509HostnameVerifier": { "index": 69, "kind": "parameter", "displayName":
"X509 Hostname Verifier", "group": "security", "label": "security", "required":
false, "type": "object", "javaType": "javax.net.ssl.HostnameVerifier",
"deprecated": false, "autowired": false, "secret": false, "security":
"insecure:ssl", "description": "To use a custom X509HostnameVerifier such as
DefaultHostnameVerifier or NoopHostnameVerifier" },
+ "oauth2CachedTokensKeyResolver": { "index": 70, "kind": "parameter",
"displayName": "Oauth2 Cached Tokens Key Resolver", "group": "security
(advanced)", "label": "producer,security,advanced", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.http.OAuth2CachedTokensKeyResolver", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
strategy to compute the key of cached OAuth2 tokens when oauth2CacheTokens is
enabled. When [...]
}
}
diff --git
a/components/camel-http/src/generated/resources/META-INF/org/apache/camel/component/http/https.json
b/components/camel-http/src/generated/resources/META-INF/org/apache/camel/component/http/https.json
index dd7d7e23b715..fcadadfdf4cc 100644
---
a/components/camel-http/src/generated/resources/META-INF/org/apache/camel/component/http/https.json
+++
b/components/camel-http/src/generated/resources/META-INF/org/apache/camel/component/http/https.json
@@ -169,8 +169,9 @@
"oauth2ResourceIndicator": { "index": 64, "kind": "parameter",
"displayName": "Oauth2 Resource Indicator", "group": "security", "label":
"producer,security", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "OAuth2 Token endpoint" },
"oauth2Scope": { "index": 65, "kind": "parameter", "displayName": "Oauth2
Scope", "group": "security", "label": "producer,security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "OAuth2 scope" },
"oauth2TokenEndpoint": { "index": 66, "kind": "parameter", "displayName":
"Oauth2 Token Endpoint", "group": "security", "label": "producer,security",
"required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description":
"OAuth2 Resource Indicator" },
- "sslContextParameters": { "index": 67, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure security
using SSLContextParameters. This takes precedence over the sslContextParameters
of the component, so endpoints of the same component can use diffe [...]
- "x509HostnameVerifier": { "index": 68, "kind": "parameter", "displayName":
"X509 Hostname Verifier", "group": "security", "label": "security", "required":
false, "type": "object", "javaType": "javax.net.ssl.HostnameVerifier",
"deprecated": false, "autowired": false, "secret": false, "security":
"insecure:ssl", "description": "To use a custom X509HostnameVerifier such as
DefaultHostnameVerifier or NoopHostnameVerifier" },
- "oauth2CachedTokensKeyResolver": { "index": 69, "kind": "parameter",
"displayName": "Oauth2 Cached Tokens Key Resolver", "group": "security
(advanced)", "label": "producer,security,advanced", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.http.OAuth2CachedTokensKeyResolver", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
strategy to compute the key of cached OAuth2 tokens when oauth2CacheTokens is
enabled. When [...]
+ "oauthProfile": { "index": 67, "kind": "parameter", "displayName": "Oauth
Profile", "group": "security", "label": "producer,security", "required": false,
"type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "The name of a camel-oauth
profile to use for outgoing requests. When set, a bearer token is resolved per
HTTP request using the named profile (properties under camel.oauth.NAME.*) and
injected as an Authorizati [...]
+ "sslContextParameters": { "index": 68, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure security
using SSLContextParameters. This takes precedence over the sslContextParameters
of the component, so endpoints of the same component can use diffe [...]
+ "x509HostnameVerifier": { "index": 69, "kind": "parameter", "displayName":
"X509 Hostname Verifier", "group": "security", "label": "security", "required":
false, "type": "object", "javaType": "javax.net.ssl.HostnameVerifier",
"deprecated": false, "autowired": false, "secret": false, "security":
"insecure:ssl", "description": "To use a custom X509HostnameVerifier such as
DefaultHostnameVerifier or NoopHostnameVerifier" },
+ "oauth2CachedTokensKeyResolver": { "index": 70, "kind": "parameter",
"displayName": "Oauth2 Cached Tokens Key Resolver", "group": "security
(advanced)", "label": "producer,security,advanced", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.http.OAuth2CachedTokensKeyResolver", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
strategy to compute the key of cached OAuth2 tokens when oauth2CacheTokens is
enabled. When [...]
}
}
diff --git a/components/camel-http/src/main/docs/http-component.adoc
b/components/camel-http/src/main/docs/http-component.adoc
index 539021c12d35..cf84d5e0dd55 100644
--- a/components/camel-http/src/main/docs/http-component.adoc
+++ b/components/camel-http/src/main/docs/http-component.adoc
@@ -980,6 +980,60 @@ all routes and their endpoints from the updated component
configuration after ea
No special configuration is needed for `camel-http`: the fresh endpoints
created during the route
restart carry the newly resolved credentials.
+=== camel-oauth Profile Support
+
+The `oauthProfile` endpoint option integrates with
xref:components:others:oauth.adoc[camel-oauth] to resolve a bearer token per
HTTP request without managing the token endpoint credentials on every endpoint
URI.
+
+Set `oauthProfile` to the name of a profile configured under
`camel.oauth.<profileName>.*` in your application properties. On each outgoing
request Camel resolves a fresh bearer token (or reuses the cached one until it
expires) from that profile and injects it as an `Authorization: Bearer` header.
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("direct:start")
+ .to("https://api.example.com/data?oauthProfile=myProfile");
+----
+
+XML::
++
+[source,xml]
+----
+<route>
+ <from uri="direct:start"/>
+ <to uri="https://api.example.com/data?oauthProfile=myProfile"/>
+</route>
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - to:
+ uri: "https://api.example.com/data"
+ parameters:
+ oauthProfile: myProfile
+----
+====
+
+The profile properties follow the camel-oauth convention:
+
+[source,properties]
+----
+camel.oauth.myProfile.client-id=my-client-id
+camel.oauth.myProfile.client-secret=my-client-secret
+camel.oauth.myProfile.token-endpoint=https://idp.example.com/token
+----
+
+NOTE: The bearer token is only attached to requests directed at the endpoint's
own authority (scheme, host, and port). Redirects to a different host or port
do not receive it, preventing accidental token leakage.
+
+NOTE: `oauthProfile` requires `camel-oauth` on the classpath. It can be used
alongside the `oauth2*` options: `oauth2*` options manage the full OAuth2
credential flow on the endpoint URI, while `oauthProfile` delegates token
acquisition to a named camel-oauth profile. If both are set, the `oauth2*`
token is used and a WARN is logged at startup.
+
=== Logging HTTP activity
With `logHttpActivity=true` (on the component or the endpoint), the HTTP
requests that are sent and the HTTP
diff --git
a/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java
index 321307f65b8f..4a66a49c1f07 100644
---
a/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java
+++
b/components/camel-http/src/main/java/org/apache/camel/component/http/CompositeHttpConfigurer.java
@@ -53,6 +53,21 @@ public class CompositeHttpConfigurer extends ServiceSupport
implements HttpClien
}
}
+ /**
+ * Returns {@code true} if any configurer in this composite is an instance
of {@code type}, checked recursively.
+ */
+ boolean contains(Class<?> type) {
+ for (HttpClientConfigurer configurer : configurers) {
+ if (type.isInstance(configurer)) {
+ return true;
+ }
+ if (configurer instanceof CompositeHttpConfigurer composite &&
composite.contains(type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
@Override
protected void doStart() throws Exception {
super.doStart();
diff --git
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
index 5d10089250b4..0e4206055e8a 100644
---
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
+++
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
@@ -41,6 +41,7 @@ import org.apache.camel.spi.BodyTypes;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.OAuthHelper;
import org.apache.camel.support.jsse.SSLContextParameters;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.util.IOHelper;
@@ -57,6 +58,7 @@ import
org.apache.hc.client5.http.ssl.HostnameVerificationPolicy;
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpRequestInterceptor;
@@ -116,6 +118,8 @@ public class HttpEndpoint extends HttpCommonEndpoint
implements LineNumberAware
private HttpClientBuilder clientBuilder;
@UriParam(label = "advanced", description = "Sets a custom HttpClient to
be used by the producer")
private HttpClient httpClient;
+ // true when httpClient was injected via setHttpClient(); false for the
lazy-created internal client
+ private boolean externalHttpClient;
@UriParam(label = "advanced", defaultValue = "false",
description = "To use System Properties as fallback for
configuration for configuring HTTP Client")
private boolean useSystemProperties;
@@ -220,6 +224,14 @@ public class HttpEndpoint extends HttpCommonEndpoint
implements LineNumberAware
description = "To use a custom strategy to compute the key of
cached OAuth2 tokens when oauth2CacheTokens is"
+ " enabled. When set, oauth2CachedTokensKey is
not used.")
private OAuth2CachedTokensKeyResolver oauth2CachedTokensKeyResolver;
+ @UriParam(label = "producer,security",
+ description = "The name of a camel-oauth profile to use for
outgoing requests."
+ + " When set, a bearer token is resolved per HTTP
request using the named profile"
+ + " (properties under camel.oauth.NAME.*) and
injected as an"
+ + " Authorization: Bearer header. Requires
camel-oauth on the classpath."
+ + " The token is only attached to requests
directed at the endpoint's own authority;"
+ + " redirects to a different host or port do not
receive it.")
+ private String oauthProfile;
public HttpEndpoint() {
}
@@ -284,6 +296,7 @@ public class HttpEndpoint extends HttpCommonEndpoint
implements LineNumberAware
lock.lock();
try {
this.httpClient = httpClient;
+ this.externalHttpClient = httpClient != null;
} finally {
lock.unlock();
}
@@ -346,9 +359,41 @@ public class HttpEndpoint extends HttpCommonEndpoint
implements LineNumberAware
HttpClientConfigurer configurer = getHttpClientConfigurer();
if (configurer != null) {
+ // configurer must run first —
OAuth2ClientConfigurer.configureHttpClient() calls
+ // clientBuilder.build() on its first line to snapshot the builder
and create the
+ // token-endpoint HTTP client. Any interceptor already in the
builder at that point
+ // is baked into that snapshot. Registering the oauthProfile
interceptor AFTER the
+ // configurer avoids it being inherited by the token-POST client.
configurer.configureHttpClient(clientBuilder);
}
+ if (ObjectHelper.isNotEmpty(oauthProfile)) {
+ final String profile = oauthProfile;
+ final URI endpointUri = getHttpUri();
+ clientBuilder.addRequestInterceptorFirst((HttpRequest request,
EntityDetails entity, HttpContext context) -> {
+ try {
+ if (!OAuth2ClientConfigurer.isTargetAuthority(request,
endpointUri)) {
+ LOG.debug(
+ "Not attaching the oauthProfile bearer token
to request targeting {}, not the endpoint's authority {}",
+ request.getRequestUri(),
+ endpointUri.getAuthority());
+ return;
+ }
+ String token =
OAuthHelper.resolveOAuthToken(getCamelContext(), profile);
+ if (token == null || token.isBlank()) {
+ throw new HttpException(
+ "OAuth profile '" + profile + "' resolved a
null or blank token");
+ }
+ request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " +
token);
+ } catch (HttpException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new HttpException(
+ "Failed to resolve OAuth token for profile '" +
profile + "': " + e.getMessage(), e);
+ }
+ });
+ }
+
// Apply the shared-manager flag after all configurers have run so
that the endpoint's decision
// is final. An OAuth2ClientConfigurer sets connManagerShared=true
before building the token
// client, then resets it to false so the endpoint's own client is not
affected by that
@@ -404,6 +449,26 @@ public class HttpEndpoint extends HttpCommonEndpoint
implements LineNumberAware
}
CamelContextAware.trySetCamelContext(httpActivityListener,
getCamelContext());
ServiceHelper.startService(httpActivityListener, httpClientConfigurer);
+ if (ObjectHelper.isNotEmpty(oauthProfile) && externalHttpClient) {
+ LOG.warn(
+ "oauthProfile is set but a custom HttpClient was also
configured on endpoint {}."
+ + " The oauthProfile bearer token injection is applied
via a request interceptor"
+ + " registered in createHttpClient() — it will NOT be
applied to a pre-built custom HttpClient."
+ + " Remove the custom HttpClient to let Camel build one
with the interceptor included.",
+ this);
+ }
+ HttpClientConfigurer configurer = getHttpClientConfigurer();
+ boolean hasOauth2Configurer = configurer instanceof
OAuth2ClientConfigurer
+ || (configurer instanceof CompositeHttpConfigurer composite
+ && composite.contains(OAuth2ClientConfigurer.class));
+ if (ObjectHelper.isNotEmpty(oauthProfile) && hasOauth2Configurer) {
+ LOG.warn(
+ "oauthProfile and oauth2* options are both set on endpoint
{}."
+ + " Both inject an Authorization: Bearer header; the
oauth2* interceptor runs after the oauthProfile"
+ + " interceptor and overwrites it. The oauth2* token wins
and the oauthProfile token is computed"
+ + " but discarded on every request. Remove one of the two
options.",
+ this);
+ }
}
@Override
@@ -923,4 +988,22 @@ public class HttpEndpoint extends HttpCommonEndpoint
implements LineNumberAware
public void setOauth2CachedTokensKeyResolver(OAuth2CachedTokensKeyResolver
oauth2CachedTokensKeyResolver) {
this.oauth2CachedTokensKeyResolver = oauth2CachedTokensKeyResolver;
}
+
+ public String getOauthProfile() {
+ return oauthProfile;
+ }
+
+ /**
+ * The name of a camel-oauth profile to use for outgoing requests.
+ * <p>
+ * When set, a bearer token is resolved per HTTP request using the named
profile (properties under
+ * {@code camel.oauth.<profileName>.*}) and injected as an {@code
Authorization: Bearer} header. Requires
+ * camel-oauth on the classpath.
+ * <p>
+ * The token is only attached to requests directed at the endpoint's own
authority; redirects to a different host or
+ * port do not receive it.
+ */
+ public void setOauthProfile(String oauthProfile) {
+ this.oauthProfile = oauthProfile;
+ }
}
diff --git
a/components/camel-http/src/main/java/org/apache/camel/component/http/OAuth2ClientConfigurer.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/OAuth2ClientConfigurer.java
index 390bde04d003..662f9c7a12f2 100644
---
a/components/camel-http/src/main/java/org/apache/camel/component/http/OAuth2ClientConfigurer.java
+++
b/components/camel-http/src/main/java/org/apache/camel/component/http/OAuth2ClientConfigurer.java
@@ -151,16 +151,37 @@ public class OAuth2ClientConfigurer extends
ServiceSupport implements HttpClient
}
private boolean isTargetAuthority(URI requestUri) {
- if (targetUri == null) {
+ return sameAuthority(targetUri, requestUri);
+ }
+
+ /**
+ * Whether the given HTTP request targets the same authority (scheme,
host, effective port) as {@code endpointUri}.
+ * <p>
+ * Used by {@link HttpEndpoint} to guard against sending bearer tokens to
a redirect target chosen by the remote
+ * server rather than by the route author.
+ */
+ static boolean isTargetAuthority(HttpRequest request, URI endpointUri) {
+ try {
+ return sameAuthority(endpointUri, request.getUri());
+ } catch (URISyntaxException e) {
+ return false;
+ }
+ }
+
+ private static boolean sameAuthority(URI endpointUri, URI requestUri) {
+ if (endpointUri == null) {
return true;
}
- if (targetUri.getScheme() == null || targetUri.getHost() == null
- || requestUri == null || requestUri.getScheme() == null ||
requestUri.getHost() == null) {
+ if (requestUri == null) {
+ return false;
+ }
+ if (endpointUri.getScheme() == null || endpointUri.getHost() == null
+ || requestUri.getScheme() == null || requestUri.getHost() ==
null) {
return false;
}
- return targetUri.getScheme().equalsIgnoreCase(requestUri.getScheme())
- && targetUri.getHost().equalsIgnoreCase(requestUri.getHost())
- && effectivePort(targetUri) == effectivePort(requestUri);
+ return endpointUri.getScheme().equalsIgnoreCase(requestUri.getScheme())
+ && endpointUri.getHost().equalsIgnoreCase(requestUri.getHost())
+ && effectivePort(endpointUri) == effectivePort(requestUri);
}
/**
diff --git
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpOAuth2RedirectTokenLeakTest.java
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpOAuth2RedirectTokenLeakTest.java
index fab3014e7ab3..efeea6c27f00 100644
---
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpOAuth2RedirectTokenLeakTest.java
+++
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpOAuth2RedirectTokenLeakTest.java
@@ -43,6 +43,7 @@ public class HttpOAuth2RedirectTokenLeakTest extends
BaseHttpTest {
private static final String CLIENT_SECRET = "test-secret";
private final AtomicReference<String> authorizationSeenAfterRedirect = new
AtomicReference<>();
+ private final AtomicReference<String> authorizationSeenOnFirstHop = new
AtomicReference<>();
private HttpServer localServer;
private HttpServer differentHostRedirectTarget;
@@ -70,6 +71,24 @@ public class HttpOAuth2RedirectTokenLeakTest extends
BaseHttpTest {
"http://localhost:" +
differentPortRedirectTarget.getLocalPort() + "/elsewhere");
response.setCode(302);
})
+ // Dedicated paths for the oauthProfile redirect test: capture
the first-hop Authorization header
+ // before issuing the redirect, so the test can assert both
directions.
+ .register("/oauth-redirect-to-different-host", (request,
response, context) -> {
+ authorizationSeenOnFirstHop.set(
+ request.containsHeader("Authorization")
+ ?
request.getFirstHeader("Authorization").getValue() : null);
+ response.setHeader("Location",
+ "http://127.0.0.1:" +
differentHostRedirectTarget.getLocalPort() + "/elsewhere");
+ response.setCode(302);
+ })
+ .register("/oauth-redirect-to-different-port", (request,
response, context) -> {
+ authorizationSeenOnFirstHop.set(
+ request.containsHeader("Authorization")
+ ?
request.getFirstHeader("Authorization").getValue() : null);
+ response.setHeader("Location",
+ "http://localhost:" +
differentPortRedirectTarget.getLocalPort() + "/elsewhere");
+ response.setCode(302);
+ })
.register("/challenge-on-different-host", (request, response,
context) -> {
response.setHeader("Location",
"http://127.0.0.1:" +
differentHostRedirectTarget.getLocalPort() + "/challenge");
@@ -129,6 +148,30 @@ public class HttpOAuth2RedirectTokenLeakTest extends
BaseHttpTest {
.as("the bearer token must not be re-attached to the authority
the Location header named").isNull();
}
+ @ParameterizedTest
+ @ValueSource(booleans = { true, false })
+ public void
theBearerTokenFromOauthProfileIsNotSentToARedirectTarget(boolean differentHost)
{
+ HttpComponent http = context.getComponent("http", HttpComponent.class);
+ http.setFollowRedirects(true);
+
+ // Use dedicated paths that capture the first-hop Authorization header
before redirecting,
+ // so the test validates both: token present on hop 1, absent on the
cross-authority hop 2.
+ String redirectPath = differentHost ?
"/oauth-redirect-to-different-host" : "/oauth-redirect-to-different-port";
+ String uri = "http://localhost:" + localServer.getLocalPort() +
redirectPath + "?oauthProfile=myprofile";
+
+ authorizationSeenAfterRedirect.set(null);
+ authorizationSeenOnFirstHop.set(null);
+ String body = fluentTemplate.to(uri).request(String.class);
+
+ assertThat(body).as("the redirect should still have been
followed").isEqualTo("Bye World");
+ assertThat(authorizationSeenOnFirstHop.get())
+ .as("the oauthProfile bearer token must be attached to the
initial request")
+ .isEqualTo("Bearer stub-token-for-myprofile");
+ assertThat(authorizationSeenAfterRedirect.get())
+ .as("the oauthProfile bearer token must not be re-attached to
the authority the Location header named")
+ .isNull();
+ }
+
/**
* The basic-auth half of the same problem: authHost is optional and unset
in the common configuration, which made
* the credentials scope {@code new AuthScope(null, -1)} - any host, any
port, any scheme. HttpClient then offers
diff --git
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpOAuthProfileProducerTest.java
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpOAuthProfileProducerTest.java
new file mode 100644
index 000000000000..9f208ee04c41
--- /dev/null
+++
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpOAuthProfileProducerTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.component.http;
+
+import java.net.URI;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
+import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for the {@code oauthProfile} producer option.
+ * <p>
+ * The option resolves a bearer token per HTTP request via a named camel-oauth
profile and injects it as an
+ * {@code Authorization: Bearer} header. A {@link
StubOAuthClientAuthenticationFactory} registered via the service
+ * loader stands in for camel-oauth so the test does not need a real IdP.
+ */
+class HttpOAuthProfileProducerTest extends BaseHttpTest {
+
+ private static final String PROFILE = "myprofile";
+ private static final String EXPECTED_HEADER_VALUE = "Bearer " +
StubOAuthClientAuthenticationFactory.tokenFor(PROFILE);
+
+ /** The Authorization header value seen by the endpoint */
+ private final AtomicReference<String> authorizationSeen = new
AtomicReference<>();
+
+ private HttpServer localServer;
+
+ @Override
+ public void setupResources() throws Exception {
+ localServer = ServerBootstrap.bootstrap()
+
.setCanonicalHostName("localhost").setHttpProcessor(getBasicHttpProcessor())
+
.setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory())
+ .setSslContext(getSSLContext())
+ .register("/protected", (request, response, context) -> {
+ authorizationSeen.set(
+ request.containsHeader("Authorization")
+ ?
request.getFirstHeader("Authorization").getValue() : null);
+ response.setCode(200);
+ response.setEntity(new StringEntity("Hello World"));
+ })
+ .create();
+ localServer.start();
+ }
+
+ @Override
+ public void cleanupResources() throws Exception {
+ closeImmediately(localServer).close();
+ }
+
+ @AfterEach
+ void resetStubTokens() {
+ StubOAuthClientAuthenticationFactory.resetTokens();
+ }
+
+ @Test
+ void theBearerTokenIsInjectedForTheNamedProfile() {
+ String uri = "http://localhost:" + localServer.getLocalPort() +
"/protected?oauthProfile=" + PROFILE;
+
+ String body = fluentTemplate.to(uri).request(String.class);
+
+ assertThat(body).isEqualTo("Hello World");
+ assertThat(authorizationSeen.get())
+ .as("the Authorization header must carry the stub token for
profile '" + PROFILE + "'")
+ .isEqualTo(EXPECTED_HEADER_VALUE);
+ }
+
+ @Test
+ void theBearerTokenIsNotAttachedToADifferentAuthority() throws Exception {
+ // Unit-level guard: isTargetAuthority returns false when host or port
differs
+ URI endpointUri = new URI("http://localhost:8080/api");
+
+ // Same authority: matches
+ assertThat(OAuth2ClientConfigurer.isTargetAuthority(
+ new HttpGet("http://localhost:8080/api/data"),
+ endpointUri))
+ .as("same host and port must be recognised as same authority")
+ .isTrue();
+
+ // Different host
+ assertThat(OAuth2ClientConfigurer.isTargetAuthority(
+ new HttpGet("http://127.0.0.1:8080/api/data"),
+ endpointUri))
+ .as("different host must not be recognised as same authority")
+ .isFalse();
+
+ // Different port
+ assertThat(OAuth2ClientConfigurer.isTargetAuthority(
+ new HttpGet("http://localhost:9090/api/data"),
+ endpointUri))
+ .as("different port must not be recognised as same authority")
+ .isFalse();
+ }
+
+ @Test
+ void theBearerTokenIsResolvedPerHttpRequestNotCachedAtStartup() {
+ // Use a profile name unique to this test so that the setToken() call
below does not
+ // race with other test classes that use "myprofile" (TOKEN_OVERRIDES
is a shared static map).
+ String rotationProfile = "myprofile-rotation";
+ String uri = "http://localhost:" + localServer.getLocalPort() +
"/protected?oauthProfile=" + rotationProfile;
+
+ // First request with the default stub token
+ fluentTemplate.to(uri).request(String.class);
+ assertThat(authorizationSeen.get())
+ .as("first request must carry the initial stub token")
+ .isEqualTo("Bearer stub-token-for-" + rotationProfile);
+
+ // Rotate the stub token to simulate a token refresh
+ StubOAuthClientAuthenticationFactory.setToken(rotationProfile,
"rotated-token");
+ authorizationSeen.set(null);
+
+ // Second request must carry the rotated token, proving resolution is
per-HTTP-request
+ fluentTemplate.to(uri).request(String.class);
+ assertThat(authorizationSeen.get())
+ .as("second request must carry the rotated token, not the
initial one")
+ .isEqualTo("Bearer rotated-token");
+ }
+}
diff --git
a/components/camel-http/src/test/java/org/apache/camel/component/http/StubOAuthClientAuthenticationFactory.java
b/components/camel-http/src/test/java/org/apache/camel/component/http/StubOAuthClientAuthenticationFactory.java
new file mode 100644
index 000000000000..346bfd96ddf6
--- /dev/null
+++
b/components/camel-http/src/test/java/org/apache/camel/component/http/StubOAuthClientAuthenticationFactory.java
@@ -0,0 +1,66 @@
+/*
+ * 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.component.http;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.OAuthClientAuthenticationFactory;
+import org.apache.camel.spi.OAuthClientConfig;
+
+/**
+ * Stub {@link OAuthClientAuthenticationFactory} for tests: returns a
deterministic token per profile without calling a
+ * real token endpoint.
+ * <p>
+ * The default token for a profile is {@code "stub-token-for-<profileName>"}.
Use {@link #setToken(String, String)} to
+ * override the token for a specific profile during a test, and {@link
#resetTokens()} to restore defaults between
+ * tests.
+ * <p>
+ * Registered via {@code
src/test/resources/META-INF/services/org/apache/camel/oauth-client-authentication-factory}.
+ */
+public class StubOAuthClientAuthenticationFactory implements
OAuthClientAuthenticationFactory {
+
+ private static final ConcurrentMap<String, String> TOKEN_OVERRIDES = new
ConcurrentHashMap<>();
+
+ static String tokenFor(String profileName) {
+ return TOKEN_OVERRIDES.getOrDefault(profileName, "stub-token-for-" +
profileName);
+ }
+
+ static void setToken(String profileName, String token) {
+ TOKEN_OVERRIDES.put(profileName, token);
+ }
+
+ static void resetTokens() {
+ TOKEN_OVERRIDES.clear();
+ }
+
+ @Override
+ public String resolveToken(OAuthClientConfig config) {
+ throw new UnsupportedOperationException("Only named profiles are
supported by this stub");
+ }
+
+ @Override
+ public String resolveToken(CamelContext context, String profileName) {
+ return tokenFor(profileName);
+ }
+
+ @Override
+ public String resolveToken(CamelContext context) {
+ throw new UnsupportedOperationException("Only named profiles are
supported by this stub");
+ }
+}
diff --git
a/components/camel-http/src/test/resources/META-INF/services/org/apache/camel/oauth-client-authentication-factory
b/components/camel-http/src/test/resources/META-INF/services/org/apache/camel/oauth-client-authentication-factory
new file mode 100644
index 000000000000..3bdda2b57674
--- /dev/null
+++
b/components/camel-http/src/test/resources/META-INF/services/org/apache/camel/oauth-client-authentication-factory
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+class=org.apache.camel.component.http.StubOAuthClientAuthenticationFactory
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/HttpEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/HttpEndpointBuilderFactory.java
index a5b6c922cd04..e027223dd831 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/HttpEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/HttpEndpointBuilderFactory.java
@@ -1035,6 +1035,25 @@ public interface HttpEndpointBuilderFactory {
doSetProperty("oauth2TokenEndpoint", oauth2TokenEndpoint);
return this;
}
+ /**
+ * The name of a camel-oauth profile to use for outgoing requests. When
+ * set, a bearer token is resolved per HTTP request using the named
+ * profile (properties under camel.oauth.NAME.*) and injected as an
+ * Authorization: Bearer header. Requires camel-oauth on the classpath.
+ * The token is only attached to requests directed at the endpoint's
own
+ * authority; redirects to a different host or port do not receive it.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Group: security
+ *
+ * @param oauthProfile the value to set
+ * @return the dsl builder
+ */
+ default HttpEndpointBuilder oauthProfile(String oauthProfile) {
+ doSetProperty("oauthProfile", oauthProfile);
+ return this;
+ }
/**
* To configure security using SSLContextParameters. This takes
* precedence over the sslContextParameters of the component, so