package com.cygnus.cloud.security; import java.time.Duration; import com.cygnus.cloud.cache.ReactiveCacheService; import org.springframework.stereotype.Service; import reactor.core.publisher.Mono; @Service public class JwtReplayProtectionService { private static final String NAMESPACE = "jwt-jti"; private final ReactiveCacheService cache; public JwtReplayProtectionService(ReactiveCacheService cache) { this.cache = cache; } public Mono claim(String jwtId, Duration remainingLifetime) { return cache.putIfAbsent(NAMESPACE, jwtId, "used", remainingLifetime); } }