Package org.springframework.session

Examples of org.springframework.session.MapSession


    private RedisSession getSession(String id, boolean allowExpired) {
        Map<Object, Object> entries = getSessionBoundHashOperations(id).entries();
        if(entries.isEmpty()) {
            return null;
        }
        MapSession loaded = new MapSession();
        loaded.setId(id);
        for(Map.Entry<Object,Object> entry : entries.entrySet()) {
            String key = (String) entry.getKey();
            if(CREATION_TIME_ATTR.equals(key)) {
                loaded.setCreationTime((Long) entry.getValue());
            } else if(MAX_INACTIVE_ATTR.equals(key)) {
                loaded.setMaxInactiveInterval((Integer) entry.getValue());
            } else if(LAST_ACCESSED_ATTR.equals(key)) {
                loaded.setLastAccessedTime((Long) entry.getValue());
            } else if(key.startsWith(SESSION_ATTR_PREFIX)) {
                loaded.setAttribute(key.substring(SESSION_ATTR_PREFIX.length()), entry.getValue());
            }
        }
        if(!allowExpired && loaded.isExpired()) {
            return null;
        }
        RedisSession result = new RedisSession(loaded);
        result.originalLastAccessTime = loaded.getLastAccessedTime() + TimeUnit.SECONDS.toMillis(loaded.getMaxInactiveInterval());
        result.setLastAccessedTime(System.currentTimeMillis());
        return result;
    }
View Full Code Here


        /**
         * Creates a new instance ensuring to mark all of the new attributes to be persisted in the next save operation.
         */
        RedisSession() {
            this(new MapSession());
            delta.put(CREATION_TIME_ATTR, getCreationTime());
            delta.put(MAX_INACTIVE_ATTR, getMaxInactiveInterval());
            delta.put(LAST_ACCESSED_ATTR, getLastAccessedTime());
        }
View Full Code Here

  private Session session;

  @Before
  public void setup() throws Exception {
    cookieName = "SESSION";
    session = new MapSession();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    strategy = new CookieHttpSessionStrategy();
  }
View Full Code Here

    private Session session;

    @Before
    public void setup() throws Exception {
        headerName = "x-auth-token";
        session = new MapSession();
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        strategy = new HeaderHttpSessionStrategy();
    }
View Full Code Here

    }

    @Test
    public void createSessionDefaultMaxInactiveInterval() throws Exception {
        ExpiringSession session = redisRepository.createSession();
        assertThat(session.getMaxInactiveInterval()).isEqualTo(new MapSession().getMaxInactiveInterval());
    }
View Full Code Here

        assertThat(delta.get(LAST_ACCESSED_ATTR)).isEqualTo(creationTime);
    }

    @Test
    public void saveLastAccessChanged() {
        RedisSession session = redisRepository.new RedisSession(new MapSession());
        session.setLastAccessedTime(12345678L);
        when(redisOperations.boundHashOps(getKey(session.getId()))).thenReturn(boundHashOperations);
        when(expirationRedisOperations.boundSetOps(anyString())).thenReturn(boundSetOperations);

        redisRepository.save(session);
View Full Code Here

    }

    @Test
    public void saveSetAttribute() {
        String attrName = "attrName";
        RedisSession session = redisRepository.new RedisSession(new MapSession());
        session.setAttribute(attrName, "attrValue");
        when(redisOperations.boundHashOps(getKey(session.getId()))).thenReturn(boundHashOperations);
        when(expirationRedisOperations.boundSetOps(anyString())).thenReturn(boundSetOperations);

        redisRepository.save(session);
View Full Code Here

    }

    @Test
    public void saveRemoveAttribute() {
        String attrName = "attrName";
        RedisSession session = redisRepository.new RedisSession(new MapSession());
        session.removeAttribute(attrName);
        when(redisOperations.boundHashOps(getKey(session.getId()))).thenReturn(boundHashOperations);
        when(expirationRedisOperations.boundSetOps(anyString())).thenReturn(boundSetOperations);

        redisRepository.save(session);
View Full Code Here

    }

    @Test
    public void redisSessionGetAttributes() {
        String attrName = "attrName";
        RedisSession session = redisRepository.new RedisSession(new MapSession());
        assertThat(session.getAttributeNames()).isEmpty();
        session.setAttribute(attrName, "attrValue");
        assertThat(session.getAttributeNames()).containsOnly(attrName);
        session.removeAttribute(attrName);
        assertThat(session.getAttributeNames()).isEmpty();
View Full Code Here

    }

    @Test
    public void delete() {
        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(
                getSessionAttrNameKey(attrName), expected.getAttribute(attrName),
                CREATION_TIME_ATTR, expected.getCreationTime(),
                MAX_INACTIVE_ATTR, expected.getMaxInactiveInterval(),
                LAST_ACCESSED_ATTR, expected.getLastAccessedTime());
        when(boundHashOperations.entries()).thenReturn(map);
        when(expirationRedisOperations.boundSetOps(anyString())).thenReturn(boundSetOperations);

        String id = expected.getId();
        redisRepository.delete(id);
        verify(redisOperations).delete(getKey(id));
    }
View Full Code Here

TOP

Related Classes of org.springframework.session.MapSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.