Search in sources :

Example 26 with Session

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

the class SpringSessionBackedSessionRegistryTest method setUpSessions.

private void setUpSessions() {
    Session session1 = createSession(SESSION_ID, USER_NAME, NOW);
    session1.setAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR, Boolean.TRUE);
    Session session2 = createSession(SESSION_ID2, USER_NAME, NOW);
    Map<String, Session> sessions = new LinkedHashMap<>();
    sessions.put(session1.getId(), session1);
    sessions.put(session2.getId(), session2);
    when(this.sessionRepository.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, USER_NAME)).thenReturn(sessions);
}
Also used : Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) LinkedHashMap(java.util.LinkedHashMap)

Example 27 with Session

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

the class SpringSessionBackedSessionRegistryTest method sessionInformationForExistingSession.

@Test
public void sessionInformationForExistingSession() {
    Session session = createSession(SESSION_ID, USER_NAME, NOW);
    when(this.sessionRepository.findById(SESSION_ID)).thenReturn(session);
    SessionInformation sessionInfo = this.sessionRegistry.getSessionInformation(SESSION_ID);
    assertThat(sessionInfo.getSessionId()).isEqualTo(SESSION_ID);
    assertThat(sessionInfo.getLastRequest().toInstant()).isEqualTo(NOW);
    assertThat(sessionInfo.getPrincipal()).isEqualTo(USER_NAME);
    assertThat(sessionInfo.isExpired()).isFalse();
}
Also used : SessionInformation(org.springframework.security.core.session.SessionInformation) Session(org.springframework.session.Session) MapSession(org.springframework.session.MapSession) 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