|
|
|
@ -15,26 +15,21 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.redisson.tomcat;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import org.apache.catalina.session.StandardSession;
|
|
|
|
|
import org.redisson.api.RSet;
|
|
|
|
|
import org.redisson.api.RMap;
|
|
|
|
|
import org.redisson.api.RSet;
|
|
|
|
|
import org.redisson.api.RTopic;
|
|
|
|
|
import org.redisson.tomcat.RedissonSessionManager.ReadMode;
|
|
|
|
|
import org.redisson.tomcat.RedissonSessionManager.UpdateMode;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.security.Principal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Redisson Session object for Apache Tomcat
|
|
|
|
|
*
|
|
|
|
@ -50,6 +45,8 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
private static final String LAST_ACCESSED_TIME_ATTR = "session:lastAccessedTime";
|
|
|
|
|
private static final String CREATION_TIME_ATTR = "session:creationTime";
|
|
|
|
|
private static final String IS_EXPIRATION_LOCKED = "session:isExpirationLocked";
|
|
|
|
|
private static final String PRINCIPAL_ATTR = "session:principal";
|
|
|
|
|
private static final String AUTHTYPE_ATTR = "session:authtype";
|
|
|
|
|
|
|
|
|
|
public static final Set<String> ATTRS = new HashSet<String>(Arrays.asList(
|
|
|
|
|
IS_NEW_ATTR, IS_VALID_ATTR,
|
|
|
|
@ -63,7 +60,7 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
private final Map<String, Object> attrs;
|
|
|
|
|
private RMap<String, Object> map;
|
|
|
|
|
private final RTopic topic;
|
|
|
|
|
private final RedissonSessionManager.ReadMode readMode;
|
|
|
|
|
private final ReadMode readMode;
|
|
|
|
|
private final UpdateMode updateMode;
|
|
|
|
|
|
|
|
|
|
private Set<String> removedAttributes = Collections.emptySet();
|
|
|
|
@ -71,7 +68,7 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
|
|
|
|
|
private final boolean broadcastSessionEvents;
|
|
|
|
|
|
|
|
|
|
public RedissonSession(RedissonSessionManager manager, RedissonSessionManager.ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents) {
|
|
|
|
|
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents) {
|
|
|
|
|
super(manager);
|
|
|
|
|
this.redissonManager = manager;
|
|
|
|
|
this.readMode = readMode;
|
|
|
|
@ -248,6 +245,24 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setPrincipal(Principal principal) {
|
|
|
|
|
super.setPrincipal(principal);
|
|
|
|
|
|
|
|
|
|
if (map != null) {
|
|
|
|
|
fastPut(PRINCIPAL_ATTR, principal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setAuthType(String authType) {
|
|
|
|
|
super.setAuthType(authType);
|
|
|
|
|
|
|
|
|
|
if (map != null) {
|
|
|
|
|
fastPut(AUTHTYPE_ATTR, authType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setValid(boolean isValid) {
|
|
|
|
|
super.setValid(isValid);
|
|
|
|
@ -332,6 +347,12 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
|
|
|
|
|
newMap.put(IS_VALID_ATTR, isValid);
|
|
|
|
|
newMap.put(IS_NEW_ATTR, isNew);
|
|
|
|
|
if (principal != null) {
|
|
|
|
|
newMap.put(PRINCIPAL_ATTR, principal);
|
|
|
|
|
}
|
|
|
|
|
if (authType != null) {
|
|
|
|
|
newMap.put(AUTHTYPE_ATTR, authType);
|
|
|
|
|
}
|
|
|
|
|
if (broadcastSessionEvents) {
|
|
|
|
|
newMap.put(IS_EXPIRATION_LOCKED, isExpirationLocked);
|
|
|
|
|
}
|
|
|
|
@ -390,6 +411,14 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
if (isExpirationLocked != null) {
|
|
|
|
|
this.isExpirationLocked = isExpirationLocked;
|
|
|
|
|
}
|
|
|
|
|
Principal p = (Principal) attrs.remove(PRINCIPAL_ATTR);
|
|
|
|
|
if (p != null) {
|
|
|
|
|
this.principal = p;
|
|
|
|
|
}
|
|
|
|
|
String authType = (String) attrs.remove(AUTHTYPE_ATTR);
|
|
|
|
|
if (authType != null) {
|
|
|
|
|
this.authType = authType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Entry<String, Object> entry : attrs.entrySet()) {
|
|
|
|
|
super.setAttribute(entry.getKey(), entry.getValue(), false);
|
|
|
|
|