com.github.lontime.extpac4j.impl.LocalJEESessionStore Maven / Gradle / Ivy
The newest version!
package com.github.lontime.extpac4j.impl;
import java.time.Duration;
import com.github.lontime.extredisson.RedissonInstance;
import com.github.lontime.shaded.com.github.benmanes.caffeine.cache.Cache;
import com.github.lontime.shaded.com.github.benmanes.caffeine.cache.Caffeine;
import com.github.lontime.shaded.org.redisson.api.RedissonClient;
import org.pac4j.core.context.JEEContext;
/**
* LocalJEESessionStore.
* @author lontime
* @since 1.0
*/
public class LocalJEESessionStore extends LocalSimpleJEESessionStore {
public static final LocalJEESessionStore INSTANCE = new LocalJEESessionStore();
public static final String TOPIC_SESSION_REMOVED = "sessionRemoved";
private final RedissonClient redissonClient;
private Cache removed;
public LocalJEESessionStore() {
this(null);
}
public LocalJEESessionStore(String redissonName) {
super();
this.redissonClient = RedissonInstance.get().client(redissonName);
this.removed = Caffeine.newBuilder().expireAfterAccess(Duration.ofMinutes(10)).build();
redissonClient.getTopic(TOPIC_SESSION_REMOVED).addListener(String.class, (channel, msg) -> {
if (cache.getIfPresent(msg) != null) {
removed.put(msg, true);
}
});
}
@Override
protected boolean check(JEEContext context) {
final String sid = getSessionId(context);
if (removed.getIfPresent(sid) != null) {
delegate.destroySession(context);
cache.invalidate(sid);
removed.invalidate(sid);
return true;
}
return false;
}
@Override
protected void cleanup(String id) {
redissonClient.getTopic(TOPIC_SESSION_REMOVED).publish(id);
removed.invalidate(id);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy