Search in sources :

Example 46 with RedisSession

use of org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryITests method findByChangedPrincipalNameReload.

@Test
public void findByChangedPrincipalNameReload() throws Exception {
    String principalName = "findByChangedPrincipalName" + UUID.randomUUID();
    String principalNameChanged = "findByChangedPrincipalName" + UUID.randomUUID();
    RedisSession toSave = this.repository.createSession();
    toSave.setAttribute(INDEX_NAME, principalName);
    this.repository.save(toSave);
    RedisSession getSession = this.repository.findById(toSave.getId());
    getSession.setAttribute(INDEX_NAME, principalNameChanged);
    this.repository.save(getSession);
    Map<String, RedisSession> findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, principalName);
    assertThat(findByPrincipalName).isEmpty();
    findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, principalNameChanged);
    assertThat(findByPrincipalName).hasSize(1);
    assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId());
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) Test(org.junit.Test)

Example 47 with RedisSession

use of org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryITests method findByPrincipalNameNoPrincipalNameChange.

@Test
public void findByPrincipalNameNoPrincipalNameChange() throws Exception {
    String principalName = "findByPrincipalNameNoPrincipalNameChange" + UUID.randomUUID();
    RedisSession toSave = this.repository.createSession();
    toSave.setAttribute(INDEX_NAME, principalName);
    this.repository.save(toSave);
    toSave.setAttribute("other", "value");
    this.repository.save(toSave);
    Map<String, RedisSession> findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, principalName);
    assertThat(findByPrincipalName).hasSize(1);
    assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId());
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)47 RedisSession (org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession)47 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 MapSession (org.springframework.session.MapSession)6 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DefaultMessage (org.springframework.data.redis.connection.DefaultMessage)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 Authentication (org.springframework.security.core.Authentication)2 SecurityContext (org.springframework.security.core.context.SecurityContext)2 Session (org.springframework.session.Session)2 PrincipalNameResolver (org.springframework.session.data.redis.RedisOperationsSessionRepository.PrincipalNameResolver)2 EnableRedisHttpSession (org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 TimeUnit (java.util.concurrent.TimeUnit)1 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)1 SessionCreatedEvent (org.springframework.session.events.SessionCreatedEvent)1 SessionDestroyedEvent (org.springframework.session.events.SessionDestroyedEvent)1