This is an automated email from the ASF dual-hosted git repository.

ffang pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 2be454a89d6e7cf69533fb1263534495ade1a4f9
Author: Freeman(Yue) Fang <[email protected]>
AuthorDate: Fri Nov 27 09:24:42 2026 -0500

    CXF-9283: Hold a replay identifier that expires beyond the max TTL for the 
max TTL (#3791)
    
    JCacheReplayCache replaced an expiry beyond the max TTL (12 hours) with the 
default TTL (1 hour), so an
    identifier with a long expiry was held for less time than one that expires 
sooner. Hold it for the max
    TTL instead, as WSS4J's EHCacheExpiry and MemoryReplayCache do. An expiry 
that is missing or not in the
    future still gets the default TTL.
    
    (cherry picked from commit e4e8cb15f16ff5cc407baf667313219bad12ff3b)
    (cherry picked from commit e015a012af7ebc07ca39ce13ca3c0126416a524a)
---
 .../org/apache/cxf/ws/security/cache/jcache/JCacheReplayCache.java | 7 +++++--
 .../apache/cxf/ws/security/cache/jcache/JCacheReplayCacheTest.java | 4 +++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git 
a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/jcache/JCacheReplayCache.java
 
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/jcache/JCacheReplayCache.java
index e2de6f511d4..8c73d2d9d92 100644
--- 
a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/jcache/JCacheReplayCache.java
+++ 
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/jcache/JCacheReplayCache.java
@@ -222,9 +222,12 @@ class JCacheReplayCache implements ReplayCache {
     }
 
     private EHCacheValue value(String identifier, Instant expiry, Instant now) 
{
-        // as EHCacheExpiry does, an expiry that is not in the future gets the 
default TTL
-        if (expiry == null || !expiry.isAfter(now) || 
expiry.isAfter(now.plusSeconds(EHCacheExpiry.MAX_TTL))) {
+        // as EHCacheExpiry does, an expiry that is not in the future gets the 
default TTL, and one beyond
+        // the max TTL is held for the max TTL (rather than for less than an 
identifier that expires sooner)
+        if (expiry == null || !expiry.isAfter(now)) {
             expiry = now.plusSeconds(EHCacheExpiry.DEFAULT_TTL);
+        } else if (expiry.isAfter(now.plusSeconds(EHCacheExpiry.MAX_TTL))) {
+            expiry = now.plusSeconds(EHCacheExpiry.MAX_TTL);
         }
         return new EHCacheValue(identifier, expiry);
     }
diff --git 
a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/jcache/JCacheReplayCacheTest.java
 
b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/jcache/JCacheReplayCacheTest.java
index 3612032bd23..25eb468b3e6 100644
--- 
a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/jcache/JCacheReplayCacheTest.java
+++ 
b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/jcache/JCacheReplayCacheTest.java
@@ -107,13 +107,15 @@ public class JCacheReplayCacheTest {
             assertEquals(longExpiry, cache.get("long").getExpiry());
             assertEquals(clock.instant().plusSeconds(3600), 
cache.get("past").getExpiry());
             assertEquals(cache.get("past").getExpiry(), 
cache.get("now").getExpiry());
-            assertEquals(cache.get("past").getExpiry(), 
cache.get("too-long").getExpiry());
+            // beyond the max TTL: held for the max TTL, as with EHCacheExpiry
+            assertEquals(clock.instant().plusSeconds(43200), 
cache.get("too-long").getExpiry());
             clock.advance(3601);
             assertTrue(cache.contains("long"));
             assertFalse(cache.contains("default"));
             assertFalse(cache.contains("past"));
             clock.advance(3600);
             assertFalse(cache.contains("long"));
+            assertTrue(cache.contains("too-long"));
         } finally {
             cache.close();
         }

Reply via email to