Search in sources :

Example 21 with MapSession

use of org.springframework.session.MapSession in project spring-session by spring-projects.

the class CookieHttpSessionIdResolverTests method onNewSessionTwiceNewId.

@Test
public void onNewSessionTwiceNewId() throws Exception {
    Session newSession = new MapSession();
    this.strategy.setSessionId(this.request, this.response, this.session.getId());
    this.strategy.setSessionId(this.request, this.response, newSession.getId());
    Cookie[] cookies = this.response.getCookies();
    assertThat(cookies).hasSize(2);
    assertThat(base64Decode(cookies[0].getValue())).isEqualTo(this.session.getId());
    assertThat(base64Decode(cookies[1].getValue())).isEqualTo(newSession.getId());
}
Also used : Cookie(javax.servlet.http.Cookie) MapSession(org.springframework.session.MapSession) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Example 22 with MapSession

use of org.springframework.session.MapSession in project metasfresh-webui-api by metasfresh.

the class FixedMapSessionRepository method createSession.

@Override
public ExpiringSession createSession() {
    final ExpiringSession result = new MapSession();
    if (defaultMaxInactiveInterval != null) {
        result.setMaxInactiveIntervalInSeconds(defaultMaxInactiveInterval);
    }
    // Fire event
    applicationEventPublisher.publishEvent(new SessionCreatedEvent(this, result.getId()));
    return result;
}
Also used : ExpiringSession(org.springframework.session.ExpiringSession) SessionCreatedEvent(org.springframework.session.events.SessionCreatedEvent) MapSession(org.springframework.session.MapSession)

Example 23 with MapSession

use of org.springframework.session.MapSession in project metasfresh-webui-api by metasfresh.

the class FixedMapSessionRepository method getSession.

@Override
public ExpiringSession getSession(final String id) {
    final ExpiringSession saved = sessions.get(id);
    if (saved == null) {
        return null;
    }
    if (saved.isExpired()) {
        final boolean expired = true;
        deleteAndFireEvent(saved.getId(), expired);
        return null;
    }
    return new MapSession(saved);
}
Also used : ExpiringSession(org.springframework.session.ExpiringSession) MapSession(org.springframework.session.MapSession)

Example 24 with MapSession

use of org.springframework.session.MapSession in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryTests method getSessionFound.

@Test
public void getSessionFound() {
    String attrName = "attrName";
    MapSession expected = new MapSession();
    expected.setLastAccessedTime(Instant.now().minusSeconds(60));
    expected.setAttribute(attrName, "attrValue");
    given(this.redisOperations.boundHashOps(getKey(expected.getId()))).willReturn(this.boundHashOperations);
    Map map = map(RedisOperationsSessionRepository.getSessionAttrNameKey(attrName), expected.getAttribute(attrName), RedisOperationsSessionRepository.CREATION_TIME_ATTR, expected.getCreationTime().toEpochMilli(), RedisOperationsSessionRepository.MAX_INACTIVE_ATTR, (int) expected.getMaxInactiveInterval().getSeconds(), RedisOperationsSessionRepository.LAST_ACCESSED_ATTR, expected.getLastAccessedTime().toEpochMilli());
    given(this.boundHashOperations.entries()).willReturn(map);
    RedisSession session = this.redisRepository.findById(expected.getId());
    assertThat(session.getId()).isEqualTo(expected.getId());
    assertThat(session.getAttributeNames()).isEqualTo(expected.getAttributeNames());
    assertThat(session.<String>getAttribute(attrName)).isEqualTo(expected.getAttribute(attrName));
    assertThat(session.getCreationTime()).isEqualTo(expected.getCreationTime());
    assertThat(session.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval());
    assertThat(session.getLastAccessedTime()).isEqualTo(expected.getLastAccessedTime());
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MapSession(org.springframework.session.MapSession) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 25 with MapSession

use of org.springframework.session.MapSession in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryTests method saveSetAttribute.

@Test
public void saveSetAttribute() {
    String attrName = "attrName";
    RedisSession session = this.redisRepository.new RedisSession(new MapSession());
    session.setAttribute(attrName, "attrValue");
    given(this.redisOperations.boundHashOps(anyString())).willReturn(this.boundHashOperations);
    given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations);
    given(this.redisOperations.boundValueOps(anyString())).willReturn(this.boundValueOperations);
    this.redisRepository.save(session);
    assertThat(getDelta()).isEqualTo(map(RedisOperationsSessionRepository.getSessionAttrNameKey(attrName), session.getAttribute(attrName)));
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Aggregations

MapSession (org.springframework.session.MapSession)47 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 DefaultMessage (org.springframework.data.redis.connection.DefaultMessage)2