Search in sources :

Example 1 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 2 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 3 with MapSession

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

the class AbstractHttpSessionListenerTests method springSessionDestroyedTranslatedToSpringSecurityDestroyed.

@Test
public void springSessionDestroyedTranslatedToSpringSecurityDestroyed() {
    Session session = new MapSession();
    this.publisher.publishEvent(new org.springframework.session.events.SessionDestroyedEvent(this, session));
    assertThat(this.listener.getEvent().getId()).isEqualTo(session.getId());
}
Also used : MapSession(org.springframework.session.MapSession) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

Example 4 with MapSession

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

the class RedisOperationsSessionRepositoryTests method saveExpired.

@Test
public void saveExpired() {
    RedisSession session = this.redisRepository.new RedisSession(new MapSession());
    session.setMaxInactiveInterval(Duration.ZERO);
    given(this.redisOperations.boundHashOps(anyString())).willReturn(this.boundHashOperations);
    given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations);
    this.redisRepository.save(session);
    String id = session.getId();
    verify(this.redisOperations, atLeastOnce()).delete(getKey("expires:" + id));
    verify(this.redisOperations, never()).boundValueOps(getKey("expires:" + id));
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) MapSession(org.springframework.session.MapSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 5 with MapSession

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

the class RedisOperationsSessionRepositoryTests method saveLastAccessChanged.

@Test
public void saveLastAccessChanged() {
    RedisSession session = this.redisRepository.new RedisSession(new MapSession(this.cached));
    session.setLastAccessedTime(Instant.ofEpochMilli(12345678L));
    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.LAST_ACCESSED_ATTR, session.getLastAccessedTime().toEpochMilli()));
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) MapSession(org.springframework.session.MapSession) Test(org.junit.Test)

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