@@ -80,7 +80,6 @@ public final class MapSession implements Session {
|
||||
this.maxInactiveInterval = session.getMaxInactiveInterval();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastAccessedTime(long lastAccessedTime) {
|
||||
this.lastAccessedTime = lastAccessedTime;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,13 @@ public class MapSessionRepository implements SessionRepository<Session> {
|
||||
}
|
||||
|
||||
public Session getSession(String id) {
|
||||
Session result = sessions.get(id);
|
||||
return result == null ? null : new MapSession(result);
|
||||
Session saved = sessions.get(id);
|
||||
if(saved == null) {
|
||||
return null;
|
||||
}
|
||||
MapSession result = new MapSession(saved);
|
||||
result.setLastAccessedTime(System.currentTimeMillis());
|
||||
return result;
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
|
||||
@@ -26,12 +26,6 @@ import java.util.Set;
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface Session {
|
||||
/**
|
||||
* Allows setting the last time this {@link Session} was accessed.
|
||||
*
|
||||
* @param lastAccessedTime the last time the client sent a request associated with the session expressed in milliseconds since midnight of 1/1/1970 GMT
|
||||
*/
|
||||
void setLastAccessedTime(long lastAccessedTime);
|
||||
|
||||
/**
|
||||
* Gets the time when this session was created in milliseconds since midnight of 1/1/1970 GMT.
|
||||
|
||||
@@ -172,7 +172,9 @@ public class RedisOperationsSessionRepository implements SessionRepository<Redis
|
||||
loaded.setAttribute(key.substring(SESSION_ATTR_PREFIX.length()), entry.getValue());
|
||||
}
|
||||
}
|
||||
return new RedisSession(loaded);
|
||||
RedisSession result = new RedisSession(loaded);
|
||||
result.setLastAccessedTime(System.currentTimeMillis());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -253,7 +255,6 @@ public class RedisOperationsSessionRepository implements SessionRepository<Redis
|
||||
this.cached = cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastAccessedTime(long lastAccessedTime) {
|
||||
cached.setLastAccessedTime(lastAccessedTime);
|
||||
delta.put(LAST_ACCESSED_ATTR, getLastAccessedTime());
|
||||
|
||||
@@ -158,7 +158,6 @@ public class SessionRepositoryFilter<S extends Session> extends OncePerRequestFi
|
||||
S session = sessionRepository.getSession(requestedSessionId);
|
||||
if(session != null) {
|
||||
this.requestedValidSession = true;
|
||||
session.setLastAccessedTime(System.currentTimeMillis());
|
||||
currentSession = new HttpSessionWrapper(session, getServletContext());
|
||||
currentSession.setNew(false);
|
||||
return currentSession;
|
||||
@@ -199,11 +198,6 @@ public class SessionRepositoryFilter<S extends Session> extends OncePerRequestFi
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
void updateLastAccessedTime() {
|
||||
checkState();
|
||||
session.setLastAccessedTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreationTime() {
|
||||
checkState();
|
||||
|
||||
@@ -52,11 +52,6 @@ public class MapSessionTests {
|
||||
|
||||
static class CustomSession implements Session {
|
||||
|
||||
@Override
|
||||
public void setLastAccessedTime(long lastAccessedTime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreationTime() {
|
||||
return 0;
|
||||
|
||||
@@ -133,6 +133,7 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
public void getSessionFound() {
|
||||
String attrName = "attrName";
|
||||
MapSession expected = new MapSession();
|
||||
expected.setLastAccessedTime(System.currentTimeMillis() - 60000);
|
||||
expected.setAttribute(attrName, "attrValue");
|
||||
when(redisOperations.boundHashOps(getKey(expected.getId()))).thenReturn(boundHashOperations);
|
||||
Map map = map(
|
||||
@@ -142,13 +143,14 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
LAST_ACCESSED_ATTR, expected.getLastAccessedTime());
|
||||
when(boundHashOperations.entries()).thenReturn(map);
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
RedisSession session = redisRepository.getSession(expected.getId());
|
||||
assertThat(session.getId()).isEqualTo(expected.getId());
|
||||
assertThat(session.getAttributeNames()).isEqualTo(expected.getAttributeNames());
|
||||
assertThat(session.getAttribute(attrName)).isEqualTo(expected.getAttribute(attrName));
|
||||
assertThat(session.getCreationTime()).isEqualTo(expected.getCreationTime());
|
||||
assertThat(session.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval());
|
||||
assertThat(session.getLastAccessedTime()).isEqualTo(expected.getLastAccessedTime());
|
||||
assertThat(session.getLastAccessedTime()).isGreaterThanOrEqualTo(now);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user