25 lines
621 B
Java
25 lines
621 B
Java
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<Boolean> claim(String jwtId, Duration remainingLifetime) {
|
|
return cache.putIfAbsent(NAMESPACE, jwtId, "used", remainingLifetime);
|
|
}
|
|
}
|