io.scalecube.security.tokens.jwt.JwtTokenResolverImpl Maven / Gradle / Ivy
package io.scalecube.security.tokens.jwt;
import java.security.Key;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;
public final class JwtTokenResolverImpl implements JwtTokenResolver {
private static final Logger LOGGER = LoggerFactory.getLogger(JwtTokenResolver.class);
private final KeyProvider keyProvider;
private final JwtTokenParserFactory tokenParserFactory;
private final int cleanupIntervalSec;
private final Scheduler scheduler;
private final Map> keyResolutions = new ConcurrentHashMap<>();
/**
* Constructor.
*
* @param keyProvider key provider
* @param tokenParserFactory token parser factoty
*/
public JwtTokenResolverImpl(KeyProvider keyProvider, JwtTokenParserFactory tokenParserFactory) {
this(keyProvider, tokenParserFactory, 3600, Schedulers.newSingle("caching-key-provider", true));
}
/**
* Constructor.
*
* @param keyProvider key provider
* @param tokenParserFactory token parser factoty
* @param cleanupIntervalSec cleanup interval (in sec) for resolved cached keys
* @param scheduler cleanup scheduler
*/
public JwtTokenResolverImpl(
KeyProvider keyProvider,
JwtTokenParserFactory tokenParserFactory,
int cleanupIntervalSec,
Scheduler scheduler) {
this.keyProvider = keyProvider;
this.tokenParserFactory = tokenParserFactory;
this.cleanupIntervalSec = cleanupIntervalSec;
this.scheduler = scheduler;
}
@Override
public Mono