Search in sources :

Example 51 with MapSession

use of org.springframework.session.MapSession in project redisson by redisson.

the class RedissonSessionRepository method loadSession.

private MapSession loadSession(String sessionId) {
    RMap<String, Object> map = redisson.getMap(keyPrefix + sessionId, new CompositeCodec(StringCodec.INSTANCE, redisson.getConfig().getCodec()));
    Set<Entry<String, Object>> entrySet = map.readAllEntrySet();
    if (entrySet.isEmpty()) {
        return null;
    }
    MapSession delegate = new MapSession(sessionId);
    for (Entry<String, Object> entry : entrySet) {
        if ("session:creationTime".equals(entry.getKey())) {
            delegate.setCreationTime(Instant.ofEpochMilli((Long) entry.getValue()));
        } else if ("session:lastAccessedTime".equals(entry.getKey())) {
            delegate.setLastAccessedTime(Instant.ofEpochMilli((Long) entry.getValue()));
        } else if ("session:maxInactiveInterval".equals(entry.getKey())) {
            delegate.setMaxInactiveInterval(Duration.ofSeconds((Long) entry.getValue()));
        } else if (entry.getKey().startsWith(SESSION_ATTR_PREFIX)) {
            delegate.setAttribute(entry.getKey().substring(SESSION_ATTR_PREFIX.length()), entry.getValue());
        }
    }
    return delegate;
}
Also used : CompositeCodec(org.redisson.codec.CompositeCodec) Entry(java.util.Map.Entry) MapSession(org.springframework.session.MapSession)

Aggregations

MapSession (org.springframework.session.MapSession)51 Test (org.junit.Test)37 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 RedisSession (org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession)7 HashMap (java.util.HashMap)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 MapSessionRepository (org.springframework.session.MapSessionRepository)6 IOException (java.io.IOException)5 Before (org.junit.Before)5 Session (org.springframework.session.Session)5 HazelcastSession (org.springframework.session.hazelcast.HazelcastSessionRepository.HazelcastSession)5 MapListener (com.hazelcast.map.listener.MapListener)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Map (java.util.Map)3 BatchPreparedStatementSetter (org.springframework.jdbc.core.BatchPreparedStatementSetter)3 PreparedStatementSetter (org.springframework.jdbc.core.PreparedStatementSetter)3 SessionCreatedEvent (org.springframework.session.events.SessionCreatedEvent)3