This is an automated email from the ASF dual-hosted git repository.
gnodet 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 3f4254ace055 CAMEL-27123: Support RFC 9470 step-up authentication in
camel-oauth validation profiles (#30664)
3f4254ace055 is described below
commit 3f4254ace055de49d3d729719391881471b5a289
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Nov 24 18:09:24 2026 +0100
CAMEL-27123: Support RFC 9470 step-up authentication in camel-oauth
validation profiles (#30664)
Add step-up authentication (RFC 9470) support to camel-oauth validation
profiles used by HTTP consumers (platform-http, servlet, ...) and the MCP
server:
- Add INSUFFICIENT_USER_AUTHENTICATION to
OAuthTokenValidationResult.ErrorCode
for the new validation failure category.
- Add requiredAcr (Set<String>) and maxAuthAgeSeconds (int) fields to
OAuthTokenValidationConfig, with copy-constructor support and property
binding in OAuthTokenValidationConfigResolver (required-acr and
max-auth-age-seconds keys).
- Add acr/auth_time claim validation in JwtTokenValidator and
DefaultOAuthTokenValidationFactory (both JWT and introspection paths):
the token acr claim must match one of the required values, and the
auth_time claim must be within maxAuthAgeSeconds.
- Add RFC 9470 WWW-Authenticate: Bearer
error="insufficient_user_authentication",
acr_values="...", max_age=... response in OAuthHttpSecuritySupport when
token validation returns INSUFFICIENT_USER_AUTHENTICATION.
- Tests in JwtTokenValidatorTest (9 new cases) and
OAuthHttpSecuritySupportTest
(5 new cases).
No new SPI interfaces required -- all changes are backward-compatible
additions to existing types.
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../org/apache/camel/catalog/docs/mcp-server.adoc | 5 +-
.../org/apache/camel/catalog/docs/oauth.adoc | 35 +++-
.../catalog/docs/platform-http-component.adoc | 5 +-
.../camel-mcp-server/src/main/docs/mcp-server.adoc | 5 +-
.../camel/http/base/OAuthHttpSecuritySupport.java | 30 ++++
.../http/base/OAuthHttpSecuritySupportTest.java | 108 ++++++++++++
components/camel-oauth/src/main/docs/oauth.adoc | 35 +++-
.../oauth/DefaultOAuthTokenValidationFactory.java | 45 ++++-
.../org/apache/camel/oauth/JwtTokenValidator.java | 77 ++++++++
.../DefaultOAuthTokenValidationFactoryTest.java | 193 +++++++++++++++++++++
.../apache/camel/oauth/JwtTokenValidatorTest.java | 185 ++++++++++++++++++++
.../src/main/docs/platform-http-component.adoc | 5 +-
.../camel/spi/OAuthTokenValidationConfig.java | 53 ++++++
.../spi/OAuthTokenValidationConfigResolver.java | 8 +
.../camel/spi/OAuthTokenValidationResult.java | 9 +-
15 files changed, 788 insertions(+), 10 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mcp-server.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mcp-server.adoc
index 5a7144f9e767..5ebc474dac0e 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mcp-server.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mcp-server.adoc
@@ -600,7 +600,10 @@ The unauthenticated RFC 9728 document is served at
`/.well-known/oauth-protected-resource` followed by the MCP resource path.
Requests without a
bearer token or with an invalid token receive HTTP 401 and a
`WWW-Authenticate` challenge containing
`resource_metadata`; a valid token missing a required scope receives HTTP 403
with
-`error="insufficient_scope"`, the required scopes, and the metadata URL.
Identity-provider
+`error="insufficient_scope"`, the required scopes, and the metadata URL. A
valid token that does not
+meet the configured step-up requirements (see `required-acr` and
`max-auth-age-seconds` in the OAuth
+profile) receives HTTP 401 with `error="insufficient_user_authentication"` and
`acr_values` and/or
+`max_age` hints per RFC 9470. Identity-provider
infrastructure failures return HTTP 503. Error responses do not expose the
token, client secret, or
internal validation details.
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/oauth.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/oauth.adoc
index c29cb7a48eab..da3533605b07 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/oauth.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/oauth.adoc
@@ -173,7 +173,12 @@ values to Camel, they are also treated as malformed.
HTTP integrations reject missing credentials and invalid tokens with HTTP 401.
Missing
credentials receive the bare `WWW-Authenticate: Bearer` challenge, while
invalid tokens receive
-the RFC 6750 `WWW-Authenticate: Bearer error="invalid_token"` challenge.
Malformed `Authorization`
+the RFC 6750 `WWW-Authenticate: Bearer error="invalid_token"` challenge.
+When a token does not meet the configured step-up requirements (see
`required-acr` and
+`max-auth-age-seconds`), it is rejected with HTTP 401 and a
+`WWW-Authenticate: Bearer error="insufficient_user_authentication"` challenge
including
+`acr_values` and/or `max_age` hints per RFC 9470.
+Malformed `Authorization`
headers are rejected with HTTP 400 and the
RFC 6750 `WWW-Authenticate: Bearer error="invalid_request"` challenge. Token
validation
infrastructure failures are rejected with HTTP 503. For valid tokens, the
validation result is
@@ -248,6 +253,10 @@ values require restarting the route or Camel context
before they are used for to
|`camel.oauth.<profile>.allow-missing-issuer` |No |Set to `true` to accept
tokens without configuring an expected issuer. Default: `false`.
|`camel.oauth.<profile>.allow-insecure-http` |No |Set to `true` to allow plain
HTTP OIDC discovery, JWKS, or introspection endpoints for local development.
Default: `false`.
+
+|`camel.oauth.<profile>.required-acr` |No |Comma-separated accepted `acr`
(Authentication Context Class Reference) values for RFC 9470 step-up
authentication. When set, tokens whose `acr` claim is missing or does not match
one of the listed values are rejected with HTTP 401 and a `WWW-Authenticate:
Bearer error="insufficient_user_authentication"` challenge.
+
+|`camel.oauth.<profile>.max-auth-age-seconds` |No |Maximum age in seconds for
the user's authentication (RFC 9470 step-up). When positive, tokens whose
`auth_time` claim is missing or indicates an authentication older than this
value are rejected with HTTP 401 and a `WWW-Authenticate: Bearer
error="insufficient_user_authentication"` challenge.
|===
==== Choosing JWT Validation, OIDC Discovery, or Opaque Introspection
@@ -327,6 +336,28 @@ camel.oauth.myprofile.connect-timeout-seconds=5
camel.oauth.myprofile.read-timeout-seconds=10
----
+===== RFC 9470 Step-Up Authentication
+
+Step-up authentication rejects tokens whose authentication context does not
meet the required
+security level, prompting the client to re-authenticate with stronger
assurance. Configure
+`required-acr` and/or `max-auth-age-seconds` on the validation profile to
enforce step-up:
+
+[source,properties]
+----
+camel.oauth.myprofile.base-uri=https://idp.example.com/realms/main
+camel.oauth.myprofile.expected-audience=my-api
+# Require high assurance authentication context
+camel.oauth.myprofile.required-acr=high
+# Require re-authentication if the user authenticated more than 1 hour ago
+camel.oauth.myprofile.max-auth-age-seconds=3600
+----
+
+When a token fails the step-up check, the HTTP response includes a
`WWW-Authenticate` challenge
+with `error="insufficient_user_authentication"`, and `acr_values` and/or
`max_age` hints so the
+client can redirect the user to re-authenticate at the appropriate assurance
level. Both options
+apply to JWT and opaque token introspection validation paths. Both options are
off by default;
+existing profiles are unchanged.
+
To use a runtime-specific or application-specific validator for one profile,
bind an
`OAuthTokenValidationFactory` bean and reference it from the profile:
@@ -352,7 +383,7 @@ Validation error details are intended for logs and
diagnostics. Do not return
generic messages such as `Unauthorized`.
Stable error categories are available through
`OAuthTokenValidationResult.getErrorCode()`: `INVALID_TOKEN`,
`INACTIVE_TOKEN`, `EXPIRED_TOKEN`, `NOT_YET_VALID`, `MISSING_EXPIRATION`,
`INVALID_SIGNATURE`,
-`NO_MATCHING_KEY`, `UNSUPPORTED_ALGORITHM`, `INVALID_ISSUER`, and
`INVALID_AUDIENCE`.
+`NO_MATCHING_KEY`, `UNSUPPORTED_ALGORITHM`, `INVALID_ISSUER`,
`INVALID_AUDIENCE`, and `INSUFFICIENT_USER_AUTHENTICATION`.
=== Using OAuth Programmatically
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/platform-http-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/platform-http-component.adoc
index 5e1dd76d3123..ae490f10b76f 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/platform-http-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/platform-http-component.adoc
@@ -170,7 +170,10 @@ When `oauthProfile` is set, static profile configuration
is resolved and validat
Updates to OAuth profile properties require restarting the route or Camel
context before they take effect.
Requests without a Bearer token or with an invalid token are rejected with
HTTP 401 before the
route is processed; missing credentials receive a `WWW-Authenticate: Bearer`
response header and
-invalid tokens receive `WWW-Authenticate: Bearer error="invalid_token"`.
Malformed
+invalid tokens receive `WWW-Authenticate: Bearer error="invalid_token"`, and
tokens not meeting
+step-up requirements (see `required-acr` and `max-auth-age-seconds` in
+xref:components:others:oauth.adoc[camel-oauth]) receive `WWW-Authenticate:
Bearer
+error="insufficient_user_authentication"`. Malformed
`Authorization` headers are rejected with HTTP 400 and
`WWW-Authenticate: Bearer error="invalid_request"`. Token validation
infrastructure failures are
rejected with HTTP 503.
diff --git a/components/camel-ai/camel-mcp-server/src/main/docs/mcp-server.adoc
b/components/camel-ai/camel-mcp-server/src/main/docs/mcp-server.adoc
index 5a7144f9e767..5ebc474dac0e 100644
--- a/components/camel-ai/camel-mcp-server/src/main/docs/mcp-server.adoc
+++ b/components/camel-ai/camel-mcp-server/src/main/docs/mcp-server.adoc
@@ -600,7 +600,10 @@ The unauthenticated RFC 9728 document is served at
`/.well-known/oauth-protected-resource` followed by the MCP resource path.
Requests without a
bearer token or with an invalid token receive HTTP 401 and a
`WWW-Authenticate` challenge containing
`resource_metadata`; a valid token missing a required scope receives HTTP 403
with
-`error="insufficient_scope"`, the required scopes, and the metadata URL.
Identity-provider
+`error="insufficient_scope"`, the required scopes, and the metadata URL. A
valid token that does not
+meet the configured step-up requirements (see `required-acr` and
`max-auth-age-seconds` in the OAuth
+profile) receives HTTP 401 with `error="insufficient_user_authentication"` and
`acr_values` and/or
+`max_age` hints per RFC 9470. Identity-provider
infrastructure failures return HTTP 503. Error responses do not expose the
token, client secret, or
internal validation details.
diff --git
a/components/camel-http-base/src/main/java/org/apache/camel/http/base/OAuthHttpSecuritySupport.java
b/components/camel-http-base/src/main/java/org/apache/camel/http/base/OAuthHttpSecuritySupport.java
index 18e1b500a459..a9b3e3391220 100644
---
a/components/camel-http-base/src/main/java/org/apache/camel/http/base/OAuthHttpSecuritySupport.java
+++
b/components/camel-http-base/src/main/java/org/apache/camel/http/base/OAuthHttpSecuritySupport.java
@@ -181,6 +181,9 @@ public final class OAuthHttpSecuritySupport {
if (!result.isValid()) {
LOG.debug("OAuth token rejected: {}", result.getError());
+ if (result.getErrorCode() ==
OAuthTokenValidationResult.ErrorCode.INSUFFICIENT_USER_AUTHENTICATION) {
+ return
Validation.insufficientUserAuthentication(validationConfig);
+ }
return Validation.invalidToken();
}
@@ -461,6 +464,33 @@ public final class OAuthHttpSecuritySupport {
return new Validation(SERVICE_UNAVAILABLE, null,
SERVICE_UNAVAILABLE_BODY, null);
}
+ /**
+ * Creates unauthorized validation state for tokens that do not meet
RFC 9470 step-up authentication
+ * requirements. The {@code WWW-Authenticate} challenge includes
{@code acr_values} and/or {@code max_age}
+ * directives from the validation configuration so the client can
re-authenticate appropriately.
+ *
+ * @since 4.24
+ */
+ static Validation
insufficientUserAuthentication(OAuthTokenValidationConfig config) {
+ String challenge = buildStepUpChallenge(config);
+ return new Validation(UNAUTHORIZED, challenge, UNAUTHORIZED_BODY,
null);
+ }
+
+ private static String buildStepUpChallenge(OAuthTokenValidationConfig
config) {
+ StringBuilder sb = new StringBuilder(BEARER);
+ sb.append(" error=\"insufficient_user_authentication\"");
+ sb.append(", error_description=\"Step-up authentication
required\"");
+ if (config != null && config.getRequiredAcr() != null &&
!config.getRequiredAcr().isEmpty()) {
+ // acr_values is a space-separated list per RFC 9470
+ String acrValues = String.join(" ", config.getRequiredAcr());
+ sb.append(", acr_values=\"").append(acrValues).append('"');
+ }
+ if (config != null && config.getMaxAuthAgeSeconds() > 0) {
+ sb.append(", max_age=").append(config.getMaxAuthAgeSeconds());
+ }
+ return sb.toString();
+ }
+
/**
* Whether validation succeeded.
*/
diff --git
a/components/camel-http-base/src/test/java/org/apache/camel/http/base/OAuthHttpSecuritySupportTest.java
b/components/camel-http-base/src/test/java/org/apache/camel/http/base/OAuthHttpSecuritySupportTest.java
index c4ad07b72409..8f7609efd2cf 100644
---
a/components/camel-http-base/src/test/java/org/apache/camel/http/base/OAuthHttpSecuritySupportTest.java
+++
b/components/camel-http-base/src/test/java/org/apache/camel/http/base/OAuthHttpSecuritySupportTest.java
@@ -330,4 +330,112 @@ class OAuthHttpSecuritySupportTest {
throw new IllegalArgumentException("invalid profile");
}
}
+
+ // --- RFC 9470 step-up authentication tests ---
+
+ @Test
+ void rejectsInsufficientUserAuthenticationWithStepUpChallenge() {
+ OAuthTokenValidationResult result = OAuthTokenValidationResult.invalid(
+ ErrorCode.INSUFFICIENT_USER_AUTHENTICATION, "acr mismatch");
+ OAuthHttpSecuritySupport security = new
OAuthHttpSecuritySupport("myprofile", new StubFactory(result));
+ Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+
exchange.getMessage().setHeader(OAuthHttpSecuritySupport.AUTHORIZATION, "Bearer
token");
+
+ assertFalse(security.authenticate(exchange));
+ assertEquals(OAuthHttpSecuritySupport.UNAUTHORIZED,
+ exchange.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE));
+ String wwwAuth =
exchange.getMessage().getHeader(OAuthHttpSecuritySupport.WWW_AUTHENTICATE,
String.class);
+ assertNotNull(wwwAuth);
+ assertTrue(wwwAuth.contains("insufficient_user_authentication"));
+ assertTrue(exchange.isRouteStop());
+ }
+
+ @Test
+ void stepUpChallengeIncludesHintsFromWiredValidationConfig() {
+ // End-to-end test: config is wired via create(), so validationConfig
carries
+ // requiredAcr and maxAuthAgeSeconds, and authenticate() emits the
full challenge.
+ OAuthTokenValidationResult stepUpResult =
OAuthTokenValidationResult.invalid(
+ ErrorCode.INSUFFICIENT_USER_AUTHENTICATION, "acr mismatch");
+ DefaultCamelContext context = new DefaultCamelContext();
+ context.getRegistry().bind(OAuthTokenValidationFactory.FACTORY, new
StubFactory(stepUpResult));
+
context.getPropertiesComponent().addInitialProperty("camel.oauth.stepup.required-acr",
"2");
+
context.getPropertiesComponent().addInitialProperty("camel.oauth.stepup.max-auth-age-seconds",
"300");
+
+ OAuthHttpSecuritySupport security =
OAuthHttpSecuritySupport.create(context, "stepup");
+ assertNotNull(security);
+
+ Exchange exchange = new DefaultExchange(context);
+
exchange.getMessage().setHeader(OAuthHttpSecuritySupport.AUTHORIZATION, "Bearer
token");
+
+ assertFalse(security.authenticate(exchange));
+ assertEquals(OAuthHttpSecuritySupport.UNAUTHORIZED,
+ exchange.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE));
+ String wwwAuth =
exchange.getMessage().getHeader(OAuthHttpSecuritySupport.WWW_AUTHENTICATE,
String.class);
+ assertNotNull(wwwAuth);
+ assertTrue(wwwAuth.contains("insufficient_user_authentication"));
+ assertTrue(wwwAuth.contains("acr_values=\"2\""));
+ assertTrue(wwwAuth.contains("max_age=300"));
+ assertTrue(exchange.isRouteStop());
+ }
+
+ @Test
+ void insufficientUserAuthenticationChallengeIncludesAcrValues() {
+ OAuthTokenValidationConfig config = new OAuthTokenValidationConfig()
+ .setRequiredAcr(Set.of("2"))
+ .setMaxAuthAgeSeconds(300);
+
+ OAuthHttpSecuritySupport.Validation validation
+ =
OAuthHttpSecuritySupport.Validation.insufficientUserAuthentication(config);
+
+ assertFalse(validation.isAuthenticated());
+ assertEquals(OAuthHttpSecuritySupport.UNAUTHORIZED,
validation.getRejectionStatusCode());
+ String wwwAuth = validation.getWwwAuthenticate();
+ assertNotNull(wwwAuth);
+ assertTrue(wwwAuth.startsWith("Bearer "));
+
assertTrue(wwwAuth.contains("error=\"insufficient_user_authentication\""));
+ assertTrue(wwwAuth.contains("acr_values=\"2\""));
+ assertTrue(wwwAuth.contains("max_age=300"));
+ }
+
+ @Test
+ void insufficientUserAuthenticationChallengeWithAcrOnly() {
+ OAuthTokenValidationConfig config = new OAuthTokenValidationConfig()
+ .setRequiredAcr(Set.of("gold", "silver"));
+
+ OAuthHttpSecuritySupport.Validation validation
+ =
OAuthHttpSecuritySupport.Validation.insufficientUserAuthentication(config);
+
+ String wwwAuth = validation.getWwwAuthenticate();
+ assertNotNull(wwwAuth);
+ assertTrue(wwwAuth.contains("insufficient_user_authentication"));
+ assertTrue(wwwAuth.contains("acr_values="));
+ assertFalse(wwwAuth.contains("max_age="));
+ }
+
+ @Test
+ void insufficientUserAuthenticationChallengeWithMaxAgeOnly() {
+ OAuthTokenValidationConfig config = new OAuthTokenValidationConfig()
+ .setMaxAuthAgeSeconds(600);
+
+ OAuthHttpSecuritySupport.Validation validation
+ =
OAuthHttpSecuritySupport.Validation.insufficientUserAuthentication(config);
+
+ String wwwAuth = validation.getWwwAuthenticate();
+ assertNotNull(wwwAuth);
+ assertTrue(wwwAuth.contains("insufficient_user_authentication"));
+ assertFalse(wwwAuth.contains("acr_values="));
+ assertTrue(wwwAuth.contains("max_age=600"));
+ }
+
+ @Test
+ void insufficientUserAuthenticationChallengeWithNullConfig() {
+ OAuthHttpSecuritySupport.Validation validation
+ =
OAuthHttpSecuritySupport.Validation.insufficientUserAuthentication(null);
+
+ String wwwAuth = validation.getWwwAuthenticate();
+ assertNotNull(wwwAuth);
+ assertTrue(wwwAuth.contains("insufficient_user_authentication"));
+ assertFalse(wwwAuth.contains("acr_values="));
+ assertFalse(wwwAuth.contains("max_age="));
+ }
}
diff --git a/components/camel-oauth/src/main/docs/oauth.adoc
b/components/camel-oauth/src/main/docs/oauth.adoc
index c29cb7a48eab..da3533605b07 100644
--- a/components/camel-oauth/src/main/docs/oauth.adoc
+++ b/components/camel-oauth/src/main/docs/oauth.adoc
@@ -173,7 +173,12 @@ values to Camel, they are also treated as malformed.
HTTP integrations reject missing credentials and invalid tokens with HTTP 401.
Missing
credentials receive the bare `WWW-Authenticate: Bearer` challenge, while
invalid tokens receive
-the RFC 6750 `WWW-Authenticate: Bearer error="invalid_token"` challenge.
Malformed `Authorization`
+the RFC 6750 `WWW-Authenticate: Bearer error="invalid_token"` challenge.
+When a token does not meet the configured step-up requirements (see
`required-acr` and
+`max-auth-age-seconds`), it is rejected with HTTP 401 and a
+`WWW-Authenticate: Bearer error="insufficient_user_authentication"` challenge
including
+`acr_values` and/or `max_age` hints per RFC 9470.
+Malformed `Authorization`
headers are rejected with HTTP 400 and the
RFC 6750 `WWW-Authenticate: Bearer error="invalid_request"` challenge. Token
validation
infrastructure failures are rejected with HTTP 503. For valid tokens, the
validation result is
@@ -248,6 +253,10 @@ values require restarting the route or Camel context
before they are used for to
|`camel.oauth.<profile>.allow-missing-issuer` |No |Set to `true` to accept
tokens without configuring an expected issuer. Default: `false`.
|`camel.oauth.<profile>.allow-insecure-http` |No |Set to `true` to allow plain
HTTP OIDC discovery, JWKS, or introspection endpoints for local development.
Default: `false`.
+
+|`camel.oauth.<profile>.required-acr` |No |Comma-separated accepted `acr`
(Authentication Context Class Reference) values for RFC 9470 step-up
authentication. When set, tokens whose `acr` claim is missing or does not match
one of the listed values are rejected with HTTP 401 and a `WWW-Authenticate:
Bearer error="insufficient_user_authentication"` challenge.
+
+|`camel.oauth.<profile>.max-auth-age-seconds` |No |Maximum age in seconds for
the user's authentication (RFC 9470 step-up). When positive, tokens whose
`auth_time` claim is missing or indicates an authentication older than this
value are rejected with HTTP 401 and a `WWW-Authenticate: Bearer
error="insufficient_user_authentication"` challenge.
|===
==== Choosing JWT Validation, OIDC Discovery, or Opaque Introspection
@@ -327,6 +336,28 @@ camel.oauth.myprofile.connect-timeout-seconds=5
camel.oauth.myprofile.read-timeout-seconds=10
----
+===== RFC 9470 Step-Up Authentication
+
+Step-up authentication rejects tokens whose authentication context does not
meet the required
+security level, prompting the client to re-authenticate with stronger
assurance. Configure
+`required-acr` and/or `max-auth-age-seconds` on the validation profile to
enforce step-up:
+
+[source,properties]
+----
+camel.oauth.myprofile.base-uri=https://idp.example.com/realms/main
+camel.oauth.myprofile.expected-audience=my-api
+# Require high assurance authentication context
+camel.oauth.myprofile.required-acr=high
+# Require re-authentication if the user authenticated more than 1 hour ago
+camel.oauth.myprofile.max-auth-age-seconds=3600
+----
+
+When a token fails the step-up check, the HTTP response includes a
`WWW-Authenticate` challenge
+with `error="insufficient_user_authentication"`, and `acr_values` and/or
`max_age` hints so the
+client can redirect the user to re-authenticate at the appropriate assurance
level. Both options
+apply to JWT and opaque token introspection validation paths. Both options are
off by default;
+existing profiles are unchanged.
+
To use a runtime-specific or application-specific validator for one profile,
bind an
`OAuthTokenValidationFactory` bean and reference it from the profile:
@@ -352,7 +383,7 @@ Validation error details are intended for logs and
diagnostics. Do not return
generic messages such as `Unauthorized`.
Stable error categories are available through
`OAuthTokenValidationResult.getErrorCode()`: `INVALID_TOKEN`,
`INACTIVE_TOKEN`, `EXPIRED_TOKEN`, `NOT_YET_VALID`, `MISSING_EXPIRATION`,
`INVALID_SIGNATURE`,
-`NO_MATCHING_KEY`, `UNSUPPORTED_ALGORITHM`, `INVALID_ISSUER`, and
`INVALID_AUDIENCE`.
+`NO_MATCHING_KEY`, `UNSUPPORTED_ALGORITHM`, `INVALID_ISSUER`,
`INVALID_AUDIENCE`, and `INSUFFICIENT_USER_AUTHENTICATION`.
=== Using OAuth Programmatically
diff --git
a/components/camel-oauth/src/main/java/org/apache/camel/oauth/DefaultOAuthTokenValidationFactory.java
b/components/camel-oauth/src/main/java/org/apache/camel/oauth/DefaultOAuthTokenValidationFactory.java
index b5f2d3d1c5f7..b70bb61366d0 100644
---
a/components/camel-oauth/src/main/java/org/apache/camel/oauth/DefaultOAuthTokenValidationFactory.java
+++
b/components/camel-oauth/src/main/java/org/apache/camel/oauth/DefaultOAuthTokenValidationFactory.java
@@ -80,7 +80,9 @@ public class DefaultOAuthTokenValidationFactory implements
OAuthTokenValidationF
resolved.getConnectTimeoutSeconds() * 1000,
resolved.getReadTimeoutSeconds() * 1000,
resolved.getAllowedJwsAlgorithms(),
- resolved.getExpectedTokenType());
+ resolved.getExpectedTokenType(),
+ resolved.getRequiredAcr(),
+ resolved.getMaxAuthAgeSeconds());
}
return introspectToken(resolved, token);
@@ -222,10 +224,51 @@ public class DefaultOAuthTokenValidationFactory
implements OAuthTokenValidationF
"Invalid audience: expected to contain one of " +
config.getExpectedAudiences());
}
+ OAuthTokenValidationResult stepUpResult
+ = checkIntrospectionStepUpClaims(
+ claimsJson, config.getRequiredAcr(),
config.getMaxAuthAgeSeconds(),
+ config.getClockSkewSeconds());
+ if (stepUpResult != null) {
+ return stepUpResult;
+ }
+
LOG.debug("Introspection validated successfully: sub={}, iss={},
exp={}", subject, issuer, expiresAt);
return OAuthTokenValidationResult.valid(subject, issuer, audience,
scopes, claims, expiresAt);
}
+ private static OAuthTokenValidationResult checkIntrospectionStepUpClaims(
+ JsonObject claimsJson, Set<String> requiredAcr, int
maxAuthAgeSeconds, int clockSkewSeconds) {
+ if (requiredAcr != null && !requiredAcr.isEmpty()) {
+ String acr = readOptionalString(claimsJson, "acr");
+ if (acr == null || !requiredAcr.contains(acr)) {
+ return OAuthTokenValidationResult.invalid(
+ ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
+ "Insufficient authentication context: acr claim " + acr
+ + " does
not satisfy required values " + requiredAcr);
+ }
+ }
+
+ if (maxAuthAgeSeconds > 0) {
+ if (!claimsJson.has("auth_time")) {
+ return OAuthTokenValidationResult.invalid(
+ ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
+ "Insufficient authentication context: auth_time claim
is missing (max-auth-age-seconds="
+ +
maxAuthAgeSeconds + ")");
+ }
+ long authTime = readOptionalNumericDate(claimsJson, "auth_time",
0);
+ long now = now() / 1000L;
+ if (now - authTime > maxAuthAgeSeconds + clockSkewSeconds) {
+ return OAuthTokenValidationResult.invalid(
+ ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
+ "Insufficient authentication context: user
authentication is too old (auth_time="
+ + authTime
+ ", max-auth-age-seconds=" + maxAuthAgeSeconds
+ + ")");
+ }
+ }
+
+ return null;
+ }
+
static boolean isSignedJwt(String token) {
try {
SignedJWT.parse(token);
diff --git
a/components/camel-oauth/src/main/java/org/apache/camel/oauth/JwtTokenValidator.java
b/components/camel-oauth/src/main/java/org/apache/camel/oauth/JwtTokenValidator.java
index 7350c12ae6a5..2fc5ba3b79d5 100644
---
a/components/camel-oauth/src/main/java/org/apache/camel/oauth/JwtTokenValidator.java
+++
b/components/camel-oauth/src/main/java/org/apache/camel/oauth/JwtTokenValidator.java
@@ -80,6 +80,25 @@ final class JwtTokenValidator {
int readTimeoutMs,
Set<String> allowedAlgorithms,
String expectedTokenType) {
+ return validate(
+ token, jwksEndpoint, jwksCacheTtlSeconds, expectedIssuer,
expectedAudiences, clockSkewSeconds,
+ requireExpiration, connectTimeoutMs, readTimeoutMs,
allowedAlgorithms, expectedTokenType, null, 0);
+ }
+
+ static OAuthTokenValidationResult validate(
+ String token,
+ String jwksEndpoint,
+ long jwksCacheTtlSeconds,
+ String expectedIssuer,
+ Set<String> expectedAudiences,
+ int clockSkewSeconds,
+ boolean requireExpiration,
+ int connectTimeoutMs,
+ int readTimeoutMs,
+ Set<String> allowedAlgorithms,
+ String expectedTokenType,
+ Set<String> requiredAcr,
+ int maxAuthAgeSeconds) {
SignedJWT signedJWT;
try {
@@ -189,10 +208,68 @@ final class JwtTokenValidator {
Map<String, Object> allClaims = claims.getClaims();
+ OAuthTokenValidationResult stepUpResult
+ = checkStepUpClaims(claims, now, requiredAcr,
maxAuthAgeSeconds, clockSkewSeconds);
+ if (stepUpResult != null) {
+ return stepUpResult;
+ }
+
LOG.debug("JWT validated successfully: sub={}, iss={}, exp={}",
subject, issuer, expiresAt);
return OAuthTokenValidationResult.valid(subject, issuer, audience,
scopes, allClaims, expiresAt);
}
+ /**
+ * Validates RFC 9470 step-up authentication claims: acr (Authentication
Context Class Reference) and auth_time
+ * (user authentication timestamp).
+ *
+ * @param claims the JWT claims
+ * @param now the current time in epoch seconds
+ * @param requiredAcr accepted acr values; null or empty means no
check
+ * @param maxAuthAgeSeconds maximum authentication age in seconds; 0
means no check
+ * @param clockSkewSeconds clock skew leeway in seconds for the
auth_time check
+ * @return an invalid result when step-up requirements
are not met, or null when they pass
+ */
+ private static OAuthTokenValidationResult checkStepUpClaims(
+ JWTClaimsSet claims, long now, Set<String> requiredAcr, int
maxAuthAgeSeconds, int clockSkewSeconds) {
+ if (requiredAcr != null && !requiredAcr.isEmpty()) {
+ Object acrClaim = claims.getClaim("acr");
+ String acr = acrClaim instanceof String ? (String) acrClaim : null;
+ if (acr == null || !requiredAcr.contains(acr)) {
+ return OAuthTokenValidationResult.invalid(
+ ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
+ "Insufficient authentication context: acr claim " + acr
+ + " does
not satisfy required values " + requiredAcr);
+ }
+ }
+
+ if (maxAuthAgeSeconds > 0) {
+ Object authTimeClaim = claims.getClaim("auth_time");
+ if (authTimeClaim == null) {
+ return OAuthTokenValidationResult.invalid(
+ ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
+ "Insufficient authentication context: auth_time claim
is missing (max-auth-age-seconds="
+ +
maxAuthAgeSeconds + ")");
+ }
+ long authTime;
+ if (authTimeClaim instanceof Number number) {
+ authTime = number.longValue();
+ } else {
+ return OAuthTokenValidationResult.invalid(
+ ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
+ "Insufficient authentication context: auth_time claim
is not a number");
+ }
+ if (now - authTime > maxAuthAgeSeconds + clockSkewSeconds) {
+ return OAuthTokenValidationResult.invalid(
+ ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
+ "Insufficient authentication context: user
authentication is too old (auth_time="
+ + authTime
+ ", max-auth-age-seconds=" + maxAuthAgeSeconds
+ + ")");
+ }
+ }
+
+ return null;
+ }
+
/**
* Reads OAuth scopes from the standard scope claim and the scp claim used
by some identity providers. Both claims
* may be space-delimited strings or collections of scope strings.
diff --git
a/components/camel-oauth/src/test/java/org/apache/camel/oauth/DefaultOAuthTokenValidationFactoryTest.java
b/components/camel-oauth/src/test/java/org/apache/camel/oauth/DefaultOAuthTokenValidationFactoryTest.java
index 71682143f137..6d1dddc27d1d 100644
---
a/components/camel-oauth/src/test/java/org/apache/camel/oauth/DefaultOAuthTokenValidationFactoryTest.java
+++
b/components/camel-oauth/src/test/java/org/apache/camel/oauth/DefaultOAuthTokenValidationFactoryTest.java
@@ -1585,6 +1585,199 @@ class DefaultOAuthTokenValidationFactoryTest {
assertNull(result);
}
+ @Test
+ void introspectionStepUpAcrRejectedWhenMissing() throws Exception {
+ long exp = System.currentTimeMillis() / 1000L + 300;
+ HttpServer server = startIntrospectionServer(new AtomicInteger(), new
AtomicReference<>(), new AtomicReference<>(),
+ new AtomicReference<>(),
+ """
+
{"active":true,"sub":"user","iss":"%s","aud":"%s","exp":%d}
+ """
+ .formatted(ISSUER, AUDIENCE, exp));
+ try {
+ OAuthTokenValidationConfig config = new
OAuthTokenValidationConfig()
+ .setIntrospectionEndpoint("http://127.0.0.1:" +
server.getAddress().getPort() + "/introspect")
+ .setIntrospectionClientId("client")
+ .setIntrospectionClientSecret("secret")
+ .setAllowInsecureHttp(true)
+ .setExpectedIssuer(ISSUER)
+ .setExpectedAudience(AUDIENCE)
+ .setRequiredAcr(Set.of("high"));
+
+ OAuthTokenValidationResult result = factory.validateToken(config,
"opaque-token-no-dots");
+
+ assertFalse(result.isValid());
+ assertEquals(ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
result.getErrorCode());
+ assertTrue(result.getError().contains("acr"));
+ } finally {
+ server.stop(0);
+ }
+ }
+
+ @Test
+ void introspectionStepUpAcrAcceptedWhenPresent() throws Exception {
+ long exp = System.currentTimeMillis() / 1000L + 300;
+ HttpServer server = startIntrospectionServer(new AtomicInteger(), new
AtomicReference<>(), new AtomicReference<>(),
+ new AtomicReference<>(),
+ """
+
{"active":true,"sub":"user","iss":"%s","aud":"%s","exp":%d,"acr":"high"}
+ """
+ .formatted(ISSUER, AUDIENCE, exp));
+ try {
+ OAuthTokenValidationConfig config = new
OAuthTokenValidationConfig()
+ .setIntrospectionEndpoint("http://127.0.0.1:" +
server.getAddress().getPort() + "/introspect")
+ .setIntrospectionClientId("client")
+ .setIntrospectionClientSecret("secret")
+ .setAllowInsecureHttp(true)
+ .setExpectedIssuer(ISSUER)
+ .setExpectedAudience(AUDIENCE)
+ .setRequiredAcr(Set.of("high"));
+
+ OAuthTokenValidationResult result = factory.validateToken(config,
"opaque-token-no-dots");
+
+ assertTrue(result.isValid());
+ } finally {
+ server.stop(0);
+ }
+ }
+
+ @Test
+ void introspectionStepUpMaxAuthAgeRejectedWhenTooOld() throws Exception {
+ long exp = System.currentTimeMillis() / 1000L + 300;
+ long authTime = System.currentTimeMillis() / 1000L - 7200; // 2 hours
ago
+ HttpServer server = startIntrospectionServer(new AtomicInteger(), new
AtomicReference<>(), new AtomicReference<>(),
+ new AtomicReference<>(),
+ """
+
{"active":true,"sub":"user","iss":"%s","aud":"%s","exp":%d,"auth_time":%d}
+ """
+ .formatted(ISSUER, AUDIENCE, exp, authTime));
+ try {
+ OAuthTokenValidationConfig config = new
OAuthTokenValidationConfig()
+ .setIntrospectionEndpoint("http://127.0.0.1:" +
server.getAddress().getPort() + "/introspect")
+ .setIntrospectionClientId("client")
+ .setIntrospectionClientSecret("secret")
+ .setAllowInsecureHttp(true)
+ .setExpectedIssuer(ISSUER)
+ .setExpectedAudience(AUDIENCE)
+ .setMaxAuthAgeSeconds(3600);
+
+ OAuthTokenValidationResult result = factory.validateToken(config,
"opaque-token-no-dots");
+
+ assertFalse(result.isValid());
+ assertEquals(ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
result.getErrorCode());
+ assertTrue(result.getError().contains("auth_time"));
+ } finally {
+ server.stop(0);
+ }
+ }
+
+ @Test
+ void introspectionStepUpMaxAuthAgeAllowedWithClockSkew() throws Exception {
+ long exp = System.currentTimeMillis() / 1000L + 300;
+ long authTime = System.currentTimeMillis() / 1000L - 3610; // 10
seconds beyond max age
+ HttpServer server = startIntrospectionServer(new AtomicInteger(), new
AtomicReference<>(), new AtomicReference<>(),
+ new AtomicReference<>(),
+ """
+
{"active":true,"sub":"user","iss":"%s","aud":"%s","exp":%d,"auth_time":%d}
+ """
+ .formatted(ISSUER, AUDIENCE, exp, authTime));
+ try {
+ OAuthTokenValidationConfig config = new
OAuthTokenValidationConfig()
+ .setIntrospectionEndpoint("http://127.0.0.1:" +
server.getAddress().getPort() + "/introspect")
+ .setIntrospectionClientId("client")
+ .setIntrospectionClientSecret("secret")
+ .setAllowInsecureHttp(true)
+ .setExpectedIssuer(ISSUER)
+ .setExpectedAudience(AUDIENCE)
+ .setMaxAuthAgeSeconds(3600)
+ .setClockSkewSeconds(30); // 30-second skew covers the
10-second overage
+
+ OAuthTokenValidationResult result = factory.validateToken(config,
"opaque-token-no-dots");
+
+ assertTrue(result.isValid());
+ } finally {
+ server.stop(0);
+ }
+ }
+
+ @Test
+ void stepUpPropertiesResolvedFromProfile() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ PropertiesComponent pc = new PropertiesComponent();
+ pc.addInitialProperty("camel.oauth.myprofile.jwks-endpoint",
JWKS_ENDPOINT);
+ pc.addInitialProperty("camel.oauth.myprofile.expected-issuer",
ISSUER);
+ pc.addInitialProperty("camel.oauth.myprofile.expected-audience",
AUDIENCE);
+ pc.addInitialProperty("camel.oauth.myprofile.required-acr", "high,
medium");
+
pc.addInitialProperty("camel.oauth.myprofile.max-auth-age-seconds", "3600");
+ context.setPropertiesComponent(pc);
+ context.start();
+
+ OAuthTokenValidationConfig config =
OAuthTokenValidationConfigResolver.resolveProfileConfig(context, "myprofile");
+
+ assertEquals(Set.of("high", "medium"), config.getRequiredAcr());
+ assertEquals(3600, config.getMaxAuthAgeSeconds());
+ }
+ }
+
+ @Test
+ void jwtStepUpRejectedThroughFactory() throws Exception {
+ long authTime = System.currentTimeMillis() / 1000L - 7200; // 2 hours
ago
+ JWTClaimsSet claims = new JWTClaimsSet.Builder()
+ .subject("test-user")
+ .issuer(ISSUER)
+ .audience(AUDIENCE)
+ .expirationTime(futureDate(300))
+ .issueTime(new Date())
+ .claim("acr", "low")
+ .claim("auth_time", authTime)
+ .build();
+ JWSHeader header = new
JWSHeader.Builder(JWSAlgorithm.RS256).keyID(KID).build();
+ SignedJWT signedJWT = new SignedJWT(header, claims);
+ signedJWT.sign(new RSASSASigner(rsaKey));
+ String token = signedJWT.serialize();
+
+ OAuthTokenValidationConfig config = new OAuthTokenValidationConfig()
+ .setJwksEndpoint(JWKS_ENDPOINT)
+ .setExpectedIssuer(ISSUER)
+ .setExpectedAudience(AUDIENCE)
+ .setRequiredAcr(Set.of("high"));
+
+ OAuthTokenValidationResult result = factory.validateToken(config,
token);
+
+ assertFalse(result.isValid());
+ assertEquals(ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
result.getErrorCode());
+ assertTrue(result.getError().contains("acr"));
+ }
+
+ @Test
+ void jwtStepUpAcceptedWhenAcrMatches() throws Exception {
+ long authTime = System.currentTimeMillis() / 1000L - 60;
+ JWTClaimsSet claims = new JWTClaimsSet.Builder()
+ .subject("test-user")
+ .issuer(ISSUER)
+ .audience(AUDIENCE)
+ .expirationTime(futureDate(300))
+ .issueTime(new Date())
+ .claim("acr", "high")
+ .claim("auth_time", authTime)
+ .build();
+ JWSHeader header = new
JWSHeader.Builder(JWSAlgorithm.RS256).keyID(KID).build();
+ SignedJWT signedJWT = new SignedJWT(header, claims);
+ signedJWT.sign(new RSASSASigner(rsaKey));
+ String token = signedJWT.serialize();
+
+ OAuthTokenValidationConfig config = new OAuthTokenValidationConfig()
+ .setJwksEndpoint(JWKS_ENDPOINT)
+ .setExpectedIssuer(ISSUER)
+ .setExpectedAudience(AUDIENCE)
+ .setRequiredAcr(Set.of("high"))
+ .setMaxAuthAgeSeconds(3600);
+
+ OAuthTokenValidationResult result = factory.validateToken(config,
token);
+
+ assertTrue(result.isValid());
+ }
+
private static OAuthTokenValidationConfig discoveryConfig(String
discoveryUrl) {
return new OAuthTokenValidationConfig()
.setOidcDiscoveryUrl(discoveryUrl)
diff --git
a/components/camel-oauth/src/test/java/org/apache/camel/oauth/JwtTokenValidatorTest.java
b/components/camel-oauth/src/test/java/org/apache/camel/oauth/JwtTokenValidatorTest.java
index 3f7aa7af72a1..411a87b1c5fa 100644
---
a/components/camel-oauth/src/test/java/org/apache/camel/oauth/JwtTokenValidatorTest.java
+++
b/components/camel-oauth/src/test/java/org/apache/camel/oauth/JwtTokenValidatorTest.java
@@ -866,6 +866,191 @@ class JwtTokenValidatorTest {
assertFalse(DefaultOAuthTokenValidationFactory.isSignedJwt("opaque-token-no-dots"));
}
+ // --- RFC 9470 step-up authentication tests ---
+
+ @Test
+ void requiredAcrAcceptedWhenClaimMatches() throws Exception {
+ JWTClaimsSet claims = new JWTClaimsSet.Builder()
+ .subject("user1")
+ .issuer(ISSUER)
+ .audience(AUDIENCE)
+ .expirationTime(futureDate(300))
+ .issueTime(new Date())
+ .claim("acr", "2")
+ .build();
+ String token = signClaims(claims);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ Set.of("2"), 0);
+
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ void requiredAcrRejectedWhenClaimDoesNotMatch() throws Exception {
+ JWTClaimsSet claims = new JWTClaimsSet.Builder()
+ .subject("user1")
+ .issuer(ISSUER)
+ .audience(AUDIENCE)
+ .expirationTime(futureDate(300))
+ .issueTime(new Date())
+ .claim("acr", "1")
+ .build();
+ String token = signClaims(claims);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ Set.of("2"), 0);
+
+ assertFalse(result.isValid());
+ assertEquals(ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
result.getErrorCode());
+ assertTrue(result.getError().contains("acr"));
+ }
+
+ @Test
+ void requiredAcrRejectedWhenClaimAbsent() throws Exception {
+ String token = createToken(ISSUER, AUDIENCE, futureDate(300), null);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ Set.of("2"), 0);
+
+ assertFalse(result.isValid());
+ assertEquals(ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
result.getErrorCode());
+ assertTrue(result.getError().contains("acr"));
+ }
+
+ @Test
+ void requiredAcrAcceptsAnyMatchingValue() throws Exception {
+ JWTClaimsSet claims = new JWTClaimsSet.Builder()
+ .subject("user1")
+ .issuer(ISSUER)
+ .audience(AUDIENCE)
+ .expirationTime(futureDate(300))
+ .issueTime(new Date())
+ .claim("acr", "silver")
+ .build();
+ String token = signClaims(claims);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ Set.of("gold", "silver"), 0);
+
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ void maxAuthAgeAcceptedWhenAuthTimeRecent() throws Exception {
+ long authTime = System.currentTimeMillis() / 1000L - 60; // 60 seconds
ago
+ JWTClaimsSet claims = new JWTClaimsSet.Builder()
+ .subject("user1")
+ .issuer(ISSUER)
+ .audience(AUDIENCE)
+ .expirationTime(futureDate(300))
+ .issueTime(new Date())
+ .claim("auth_time", authTime)
+ .build();
+ String token = signClaims(claims);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ null, 300);
+
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ void maxAuthAgeRejectedWhenAuthTimeTooOld() throws Exception {
+ long authTime = System.currentTimeMillis() / 1000L - 400; // 400
seconds ago
+ JWTClaimsSet claims = new JWTClaimsSet.Builder()
+ .subject("user1")
+ .issuer(ISSUER)
+ .audience(AUDIENCE)
+ .expirationTime(futureDate(300))
+ .issueTime(new Date())
+ .claim("auth_time", authTime)
+ .build();
+ String token = signClaims(claims);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ null, 300);
+
+ assertFalse(result.isValid());
+ assertEquals(ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
result.getErrorCode());
+ assertTrue(result.getError().contains("auth_time"));
+ }
+
+ @Test
+ void maxAuthAgeRejectedWhenAuthTimeAbsent() throws Exception {
+ String token = createToken(ISSUER, AUDIENCE, futureDate(300), null);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ null, 300);
+
+ assertFalse(result.isValid());
+ assertEquals(ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
result.getErrorCode());
+ assertTrue(result.getError().contains("auth_time"));
+ }
+
+ @Test
+ void stepUpCheckSkippedWhenRequiredAcrNullAndMaxAuthAgeZero() throws
Exception {
+ String token = createToken(ISSUER, AUDIENCE, futureDate(300), null);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ null, 0);
+
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ void bothAcrAndMaxAuthAgeRequiredAndBothSatisfied() throws Exception {
+ long authTime = System.currentTimeMillis() / 1000L - 60;
+ JWTClaimsSet claims = new JWTClaimsSet.Builder()
+ .subject("user1")
+ .issuer(ISSUER)
+ .audience(AUDIENCE)
+ .expirationTime(futureDate(300))
+ .issueTime(new Date())
+ .claim("acr", "2")
+ .claim("auth_time", authTime)
+ .build();
+ String token = signClaims(claims);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ Set.of("2"), 300);
+
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ void acrRejectedBeforeAuthTimeCheck() throws Exception {
+ // acr fails; auth_time would also fail — verify
INSUFFICIENT_USER_AUTHENTICATION returned first
+ long authTime = System.currentTimeMillis() / 1000L - 400;
+ JWTClaimsSet claims = new JWTClaimsSet.Builder()
+ .subject("user1")
+ .issuer(ISSUER)
+ .audience(AUDIENCE)
+ .expirationTime(futureDate(300))
+ .issueTime(new Date())
+ .claim("acr", "1")
+ .claim("auth_time", authTime)
+ .build();
+ String token = signClaims(claims);
+
+ OAuthTokenValidationResult result = JwtTokenValidator.validate(
+ token, TEST_ENDPOINT, 600, ISSUER, Set.of(AUDIENCE), 0, true,
5000, 10000, null, null,
+ Set.of("2"), 300);
+
+ assertFalse(result.isValid());
+ assertEquals(ErrorCode.INSUFFICIENT_USER_AUTHENTICATION,
result.getErrorCode());
+ assertTrue(result.getError().contains("acr"));
+ }
+
private String createToken(String issuer, String audience, Date
expiration, Date notBefore) throws Exception {
return createToken(issuer, List.of(audience), expiration, notBefore);
}
diff --git
a/components/camel-platform-http/src/main/docs/platform-http-component.adoc
b/components/camel-platform-http/src/main/docs/platform-http-component.adoc
index 5e1dd76d3123..ae490f10b76f 100644
--- a/components/camel-platform-http/src/main/docs/platform-http-component.adoc
+++ b/components/camel-platform-http/src/main/docs/platform-http-component.adoc
@@ -170,7 +170,10 @@ When `oauthProfile` is set, static profile configuration
is resolved and validat
Updates to OAuth profile properties require restarting the route or Camel
context before they take effect.
Requests without a Bearer token or with an invalid token are rejected with
HTTP 401 before the
route is processed; missing credentials receive a `WWW-Authenticate: Bearer`
response header and
-invalid tokens receive `WWW-Authenticate: Bearer error="invalid_token"`.
Malformed
+invalid tokens receive `WWW-Authenticate: Bearer error="invalid_token"`, and
tokens not meeting
+step-up requirements (see `required-acr` and `max-auth-age-seconds` in
+xref:components:others:oauth.adoc[camel-oauth]) receive `WWW-Authenticate:
Bearer
+error="insufficient_user_authentication"`. Malformed
`Authorization` headers are rejected with HTTP 400 and
`WWW-Authenticate: Bearer error="invalid_request"`. Token validation
infrastructure failures are
rejected with HTTP 503.
diff --git
a/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationConfig.java
b/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationConfig.java
index 2c0b23a71159..f0401376df99 100644
---
a/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationConfig.java
+++
b/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationConfig.java
@@ -51,6 +51,8 @@ public class OAuthTokenValidationConfig {
private boolean allowMissingAudience;
private boolean allowMissingIssuer;
private boolean allowInsecureHttp;
+ private @Nullable Set<String> requiredAcr;
+ private int maxAuthAgeSeconds;
public OAuthTokenValidationConfig() {
}
@@ -80,6 +82,8 @@ public class OAuthTokenValidationConfig {
this.allowMissingAudience = source.isAllowMissingAudience();
this.allowMissingIssuer = source.isAllowMissingIssuer();
this.allowInsecureHttp = source.isAllowInsecureHttp();
+ this.requiredAcr = source.getRequiredAcr() != null ?
copyStringSet(source.getRequiredAcr()) : null;
+ this.maxAuthAgeSeconds = source.getMaxAuthAgeSeconds();
}
/**
@@ -475,6 +479,55 @@ public class OAuthTokenValidationConfig {
return this;
}
+ /**
+ * Required Authentication Context Class Reference (ACR) values for RFC
9470 step-up authentication. When set, the
+ * token {@code acr} claim must be one of these values; otherwise the
token is rejected with
+ * {@link
org.apache.camel.spi.OAuthTokenValidationResult.ErrorCode#INSUFFICIENT_USER_AUTHENTICATION}.
+ * <p>
+ * Example values: {@code "2"} (Keycloak MFA level), {@code
"urn:mace:incommon:iap:silver"}.
+ *
+ * @since 4.24
+ */
+ public @Nullable Set<String> getRequiredAcr() {
+ return requiredAcr;
+ }
+
+ /**
+ * Sets the required ACR values for RFC 9470 step-up authentication. Blank
values are ignored.
+ *
+ * @since 4.24
+ */
+ public OAuthTokenValidationConfig setRequiredAcr(@Nullable Set<String>
requiredAcr) {
+ Set<String> values = copyStringSet(requiredAcr);
+ this.requiredAcr = values.isEmpty() ? null : values;
+ return this;
+ }
+
+ /**
+ * Maximum user authentication age in seconds for RFC 9470 step-up
authentication. When set to a positive value, the
+ * token {@code auth_time} claim must be present and must be no older than
this many seconds; otherwise the token is
+ * rejected with {@link
org.apache.camel.spi.OAuthTokenValidationResult.ErrorCode#INSUFFICIENT_USER_AUTHENTICATION}.
+ * Zero (the default) disables the check.
+ *
+ * @since 4.24
+ */
+ public int getMaxAuthAgeSeconds() {
+ return maxAuthAgeSeconds;
+ }
+
+ /**
+ * Sets the maximum user authentication age in seconds for RFC 9470
step-up authentication. Zero disables the check.
+ *
+ * @since 4.24
+ */
+ public OAuthTokenValidationConfig setMaxAuthAgeSeconds(int
maxAuthAgeSeconds) {
+ if (maxAuthAgeSeconds < 0) {
+ throw new IllegalArgumentException("maxAuthAgeSeconds must be >=
0");
+ }
+ this.maxAuthAgeSeconds = maxAuthAgeSeconds;
+ return this;
+ }
+
private static Set<String> copyStringSet(@Nullable Set<String> values) {
if (values == null || values.isEmpty()) {
return Collections.emptySet();
diff --git
a/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationConfigResolver.java
b/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationConfigResolver.java
index 2be9e66186aa..854d1b54bf8c 100644
---
a/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationConfigResolver.java
+++
b/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationConfigResolver.java
@@ -112,6 +112,14 @@ public final class OAuthTokenValidationConfigResolver {
.map(Boolean::parseBoolean)
.ifPresent(config::setAllowInsecureHttp);
+ resolveOptionalProperty(context, prefix + "required-acr")
+ .map(OAuthTokenValidationConfigResolver::parseStringSet)
+ .filter(values -> !values.isEmpty())
+ .ifPresent(config::setRequiredAcr);
+ resolveOptionalProperty(context, prefix + "max-auth-age-seconds")
+ .map(Integer::parseInt)
+ .ifPresent(config::setMaxAuthAgeSeconds);
+
resolveOptionalProperty(context, prefix + "base-uri")
.map(String::trim)
.filter(baseUri -> !baseUri.isEmpty())
diff --git
a/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationResult.java
b/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationResult.java
index 85d0eb095f1c..4f15f9561794 100644
---
a/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationResult.java
+++
b/core/camel-api/src/main/java/org/apache/camel/spi/OAuthTokenValidationResult.java
@@ -80,7 +80,14 @@ public final class OAuthTokenValidationResult {
/**
* The token audience does not match the expected audience.
*/
- INVALID_AUDIENCE
+ INVALID_AUDIENCE,
+ /**
+ * The token does not meet the step-up authentication requirements
(RFC 9470): the {@code acr} claim does not
+ * match a required value or the user authentication is older than
allowed by {@code max-auth-age-seconds}.
+ *
+ * @since 4.24
+ */
+ INSUFFICIENT_USER_AUTHENTICATION
}
private final boolean valid;