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

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

commit 87af29a4214b3ec906576765c3aa73ddfffb9190
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Tue Nov 17 11:54:26 2026 +0000

    Report the max TTL of JCacheReplayCache to WSS4J (#3731)
    
    (cherry picked from commit 7b719b67798a6c2c80325b699ced1a183bd769f0)
---
 .../cxf/ws/security/cache/jcache/JCacheReplayCache.java    | 10 ++++++++++
 .../ws/security/cache/jcache/JCacheReplayCacheTest.java    | 14 ++++++++++++++
 2 files changed, 24 insertions(+)

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 a103649eb99..ac0ba68a36d 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
@@ -133,6 +133,16 @@ class JCacheReplayCache implements ReplayCache {
         return element != null;
     }
 
+    /**
+     * Return the maximum time for which this cache holds an identifier. WSS4J 
uses this to reject a
+     * SAML OneTimeUse Assertion that is valid for longer, as it could be 
replayed once its identifier
+     * had expired from the cache. This implements ReplayCache.getMaxTTL() in 
versions of WSS4J that
+     * define it, so it is declared without @Override.
+     */
+    public java.time.Duration getMaxTTL() {
+        return java.time.Duration.ofSeconds(EHCacheExpiry.DEFAULT_TTL);
+    }
+
     // Only exposed for testing
     EHCacheValue get(String identifier) {
         return cache.get(identifier);
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 0f9a682648f..8aba1daeb1a 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
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.ws.security.cache.jcache;
 
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
@@ -27,6 +28,8 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicIntegerArray;
 
+import org.apache.wss4j.common.cache.EHCacheExpiry;
+
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -104,4 +107,15 @@ public class JCacheReplayCacheTest {
             assertEquals("Identifier " + i + " was accepted more than once", 
1, accepted.get(i));
         }
     }
+
+    // The cache keeps every entry for the default TTL, so that is the longest 
it can hold one for
+    @Test
+    public void testMaxTTL() throws Exception {
+        JCacheReplayCache replayCache = new 
JCacheReplayCache("cxf.jcache.replay.test-" + UUID.randomUUID());
+        try {
+            assertEquals(Duration.ofSeconds(EHCacheExpiry.DEFAULT_TTL), 
replayCache.getMaxTTL());
+        } finally {
+            replayCache.close();
+        }
+    }
 }

Reply via email to