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

   JIRA: https://issues.apache.org/jira/browse/CAMEL-27723
   
   ## What was wrong
   
   With `authenticationType=JWT`, `JwtHelper.createJwtToken()` created one 
token when the producer started, without the
   `iat` (issued at) and `exp` (expires at) claims, and the producer sent it on 
every call. The consumer
   (`JwtServerInterceptor`) required neither claim, so a token stayed valid 
until `jwtSecret` changed. The doc table also
   listed negotiationType "NONE or TLS" for JWT; the values are PLAINTEXT and 
TLS.
   
   ## What changed
   
   Producer:
   - New option `jwtTokenLifetime` (duration, default 1 hour). Tokens carry 
`iat` and `exp = iat + lifetime`.
   - New `JwtTokenSupplier`, used by `JwtCallCredentials` on each call: a 
volatile read and a clock read per call, and a
     new token (under a lock, double-checked) when less than a tenth of the 
lifetime, at most one minute, is left. The
     first token is created at startup, so a wrong configuration still fails 
then.
   - `jwtTokenLifetime=0` sends the old token without `iat`/`exp`. Lifetimes 
between 0 and 1 second are refused (the claims
     are in seconds).
   
   Consumer:
   - New option `jwtMaxTokenAge` (duration, default 0 = not checked). When set, 
tokens older than this by `iat`, or without
     `iat`, are rejected with UNAUTHENTICATED.
   - Expired tokens were already rejected by java-jwt 4.6.2 when they have 
`exp` (it also rejects an `iat` in the future).
     The verifier now accepts a clock difference of one minute 
(`acceptLeeway(60)`), so that the new `iat` from a producer
     whose clock is slightly ahead does not fail the call.
   - Tokens without `exp` (from non-Camel clients) keep working by default.
   
   `JwtHelper.createJwtToken` gets an overload with `issuedAt`/`expiresAt`, and 
`JwtCallCredentials` a constructor that
   takes a `Supplier<String>`. The existing signatures are kept.
   
   Docs: the table says PLAINTEXT or TLS and strongly recommends TLS with JWT, 
lists the two new options, and a new
   "JSON Web Token expiry" section explains both sides. TLS setup of the 
consumer is unchanged.
   
   ## Tests
   
   - `JwtTokenSupplierTest` (5 tests, mutable clock, no sleeps): tokens carry 
iat/exp; the 1 hour token is refreshed one
     minute before expiry and not earlier; a 10 second token is refreshed when 
a tenth is left; lifetime 0 has no claims
     and is never replaced; a lifetime under 1 second is refused.
   - `GrpcConsumerJwtExpiryTest` (8 tests, real consumers on port 0): an 
expired token is rejected; a token without exp
     is accepted without max age; a token older than `jwtMaxTokenAge` and one 
without iat are rejected; a recent token is
     accepted; a clock difference of 20 seconds is accepted; a Camel producer 
with the default lifetime passes a consumer
     with `jwtMaxTokenAge`, and one with `jwtTokenLifetime=0` is rejected.
   - With the consumer changes reverted, 4 of the 8 `GrpcConsumerJwtExpiryTest` 
tests fail (max age, missing iat,
     producer without expiry, clock difference).
   - All 103 tests of the module pass.
   
   ## Upgrade guide and generated files
   
   - Upgrade guide 4.24: `camel-grpc - JSON Web Tokens expire after one hour` 
(the producer's tokens change by default;
     `jwtTokenLifetime=0` keeps the old ones).
   - Regenerated the component JSON, configurer, URI factory, the catalog 
copies of the JSON and doc, and the endpoint DSL.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to