Search in sources :

Example 21 with RedisSession

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

the class RedisOperationsSessionRepositoryITests method findByPrincipalNameNoPrincipalNameChangeReload.

@Test
public void findByPrincipalNameNoPrincipalNameChangeReload() throws Exception {
    String principalName = "findByPrincipalNameNoPrincipalNameChangeReload" + UUID.randomUUID();
    RedisSession toSave = this.repository.createSession();
    toSave.setAttribute(INDEX_NAME, principalName);
    this.repository.save(toSave);
    toSave = this.repository.findById(toSave.getId());
    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)

Example 22 with RedisSession

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

the class RedisOperationsSessionRepositoryITests method findByChangedSecurityPrincipalName.

@Test
public void findByChangedSecurityPrincipalName() throws Exception {
    RedisSession toSave = this.repository.createSession();
    toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.context);
    this.repository.save(toSave);
    toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.changedContext);
    this.repository.save(toSave);
    Map<String, RedisSession> findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getSecurityName());
    assertThat(findByPrincipalName).isEmpty();
    findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getChangedSecurityName());
    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 23 with RedisSession

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

the class RedisOperationsSessionRepositoryITests method findByDeletedSecurityPrincipalNameReload.

@Test
public void findByDeletedSecurityPrincipalNameReload() throws Exception {
    RedisSession toSave = this.repository.createSession();
    toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.context);
    this.repository.save(toSave);
    RedisSession getSession = this.repository.findById(toSave.getId());
    getSession.setAttribute(INDEX_NAME, null);
    this.repository.save(getSession);
    Map<String, RedisSession> findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getChangedSecurityName());
    assertThat(findByPrincipalName).isEmpty();
}
Also used : RedisSession(org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession) Test(org.junit.Test)

Example 24 with RedisSession

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

the class RedisOperationsSessionRepositoryITests method findByChangedSecurityPrincipalNameReload.

@Test
public void findByChangedSecurityPrincipalNameReload() throws Exception {
    RedisSession toSave = this.repository.createSession();
    toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.context);
    this.repository.save(toSave);
    RedisSession getSession = this.repository.findById(toSave.getId());
    getSession.setAttribute(SPRING_SECURITY_CONTEXT, this.changedContext);
    this.repository.save(getSession);
    Map<String, RedisSession> findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getSecurityName());
    assertThat(findByPrincipalName).isEmpty();
    findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getChangedSecurityName());
    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 25 with RedisSession

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

the class RedisOperationsSessionRepositoryITests method findBySecurityPrincipalName.

@Test
public void findBySecurityPrincipalName() throws Exception {
    RedisSession toSave = this.repository.createSession();
    toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.context);
    this.repository.save(toSave);
    Map<String, RedisSession> findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getSecurityName());
    assertThat(findByPrincipalName).hasSize(1);
    assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId());
    this.repository.deleteById(toSave.getId());
    assertThat(this.registry.receivedEvent(toSave.getId())).isTrue();
    findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getSecurityName());
    assertThat(findByPrincipalName).hasSize(0);
    assertThat(findByPrincipalName.keySet()).doesNotContain(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