Search in sources :

Example 6 with Session

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

the class SessionEventHttpSessionListenerAdapterTests method setup.

@Before
public void setup() {
    this.listener = new SessionEventHttpSessionListenerAdapter(Arrays.asList(this.listener1, this.listener2));
    this.listener.setServletContext(new MockServletContext());
    Session session = new MapSession();
    this.destroyed = new SessionDestroyedEvent(this, session);
    this.created = new SessionCreatedEvent(this, session);
}
Also used : SessionCreatedEvent(org.springframework.session.events.SessionCreatedEvent) MapSession(org.springframework.session.MapSession) SessionDestroyedEvent(org.springframework.session.events.SessionDestroyedEvent) MockServletContext(org.springframework.mock.web.MockServletContext) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) Before(org.junit.Before)

Example 7 with Session

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

the class ReactiveRedisOperationsSessionRepositoryITests method putAllOnSingleAttrDoesNotRemoveOld.

@Test
public void putAllOnSingleAttrDoesNotRemoveOld() {
    ReactiveRedisOperationsSessionRepository.RedisSession toSave = this.repository.createSession().block();
    toSave.setAttribute("a", "b");
    this.repository.save(toSave).block();
    toSave = this.repository.findById(toSave.getId()).block();
    toSave.setAttribute("1", "2");
    this.repository.save(toSave).block();
    toSave = this.repository.findById(toSave.getId()).block();
    Session session = this.repository.findById(toSave.getId()).block();
    assertThat(session.getAttributeNames().size()).isEqualTo(2);
    assertThat(session.<String>getAttribute("a")).isEqualTo("b");
    assertThat(session.<String>getAttribute("1")).isEqualTo("2");
    this.repository.deleteById(toSave.getId()).block();
}
Also used : EnableRedisWebSession(org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession) Session(org.springframework.session.Session) Test(org.junit.Test)

Example 8 with Session

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

the class ReactiveRedisOperationsSessionRepositoryITests method saves.

@Test
public void saves() throws InterruptedException {
    ReactiveRedisOperationsSessionRepository.RedisSession toSave = this.repository.createSession().block();
    String expectedAttributeName = "a";
    String expectedAttributeValue = "b";
    toSave.setAttribute(expectedAttributeName, expectedAttributeValue);
    this.repository.save(toSave).block();
    Session session = this.repository.findById(toSave.getId()).block();
    assertThat(session.getId()).isEqualTo(toSave.getId());
    assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
    assertThat(session.<String>getAttribute(expectedAttributeName)).isEqualTo(toSave.getAttribute(expectedAttributeName));
    this.repository.deleteById(toSave.getId()).block();
    assertThat(this.repository.findById(toSave.getId()).block()).isNull();
}
Also used : EnableRedisWebSession(org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession) Session(org.springframework.session.Session) Test(org.junit.Test)

Example 9 with Session

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

the class AbstractJdbcOperationsSessionRepositoryITests method putAllOnSingleAttrDoesNotRemoveOld.

@Test
public void putAllOnSingleAttrDoesNotRemoveOld() {
    JdbcOperationsSessionRepository.JdbcSession toSave = this.repository.createSession();
    toSave.setAttribute("a", "b");
    this.repository.save(toSave);
    toSave = this.repository.findById(toSave.getId());
    toSave.setAttribute("1", "2");
    this.repository.save(toSave);
    toSave = this.repository.findById(toSave.getId());
    Session session = this.repository.findById(toSave.getId());
    assertThat(session.getAttributeNames().size()).isEqualTo(2);
    assertThat(session.<String>getAttribute("a")).isEqualTo("b");
    assertThat(session.<String>getAttribute("1")).isEqualTo("2");
    this.repository.deleteById(toSave.getId());
}
Also used : Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) EnableJdbcHttpSession(org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession) Test(org.junit.Test)

Example 10 with Session

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

the class AbstractJdbcOperationsSessionRepositoryITests method updateLastAccessedTime.

@Test
public void updateLastAccessedTime() {
    JdbcOperationsSessionRepository.JdbcSession toSave = this.repository.createSession();
    toSave.setLastAccessedTime(Instant.now().minusSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS + 1));
    this.repository.save(toSave);
    Instant lastAccessedTime = Instant.now();
    toSave.setLastAccessedTime(lastAccessedTime);
    this.repository.save(toSave);
    Session session = this.repository.findById(toSave.getId());
    assertThat(session).isNotNull();
    assertThat(session.isExpired()).isFalse();
    assertThat(session.getLastAccessedTime()).isEqualTo(lastAccessedTime);
}
Also used : Instant(java.time.Instant) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) EnableJdbcHttpSession(org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession) Test(org.junit.Test)

Aggregations

Session (org.springframework.session.Session)27 Test (org.junit.Test)19 MapSession (org.springframework.session.MapSession)19 HttpSession (javax.servlet.http.HttpSession)4 BatchPreparedStatementSetter (org.springframework.jdbc.core.BatchPreparedStatementSetter)4 ResultSetExtractor (org.springframework.jdbc.core.ResultSetExtractor)4 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)4 Authentication (org.springframework.security.core.Authentication)4 RedisSession (org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession)4 SessionCreatedEvent (org.springframework.session.events.SessionCreatedEvent)4 PreparedStatementSetter (org.springframework.jdbc.core.PreparedStatementSetter)3 EnableJdbcHttpSession (org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession)3 RequestContext (com.netflix.zuul.context.RequestContext)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 SecurityContext (org.springframework.security.core.context.SecurityContext)2 SessionInformation (org.springframework.security.core.session.SessionInformation)2 EnableRedisHttpSession (org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession)2 EnableRedisWebSession (org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession)2 IOException (java.io.IOException)1