use of org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryTests method changeRedisNamespace.
@Test
public void changeRedisNamespace() {
String namespace = "foo:bar";
this.redisRepository.setRedisKeyNamespace(namespace);
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(namespace + ":sessions:expires:" + id);
verify(this.redisOperations, never()).boundValueOps(namespace + ":sessions:expires:" + id);
}
use of org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryTests method saveRemoveAttribute.
@Test
public void saveRemoveAttribute() {
String attrName = "attrName";
RedisSession session = this.redisRepository.new RedisSession(new MapSession());
session.removeAttribute(attrName);
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.getSessionAttrNameKey(attrName), null));
}
use of org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryTests method resolveIndexOnSecurityContext.
@Test
public void resolveIndexOnSecurityContext() {
String principal = "resolveIndexOnSecurityContext";
Authentication authentication = new UsernamePasswordAuthenticationToken(principal, "notused", AuthorityUtils.createAuthorityList("ROLE_USER"));
SecurityContext context = new SecurityContextImpl();
context.setAuthentication(authentication);
PrincipalNameResolver resolver = RedisOperationsSessionRepository.PRINCIPAL_NAME_RESOLVER;
RedisSession session = this.redisRepository.createSession();
session.setAttribute(SPRING_SECURITY_CONTEXT_KEY, context);
assertThat(resolver.resolvePrincipal(session)).isEqualTo(principal);
}
use of org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryTests method flushModeOnSaveRemoveAttribute.
@Test
public void flushModeOnSaveRemoveAttribute() {
RedisSession session = this.redisRepository.createSession();
session.removeAttribute("remove");
verifyZeroInteractions(this.boundHashOperations);
}
use of org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryITests method findByDeletedSecurityPrincipalName.
@Test
public void findByDeletedSecurityPrincipalName() throws Exception {
RedisSession toSave = this.repository.createSession();
toSave.setAttribute(SPRING_SECURITY_CONTEXT, this.context);
this.repository.save(toSave);
toSave.setAttribute(SPRING_SECURITY_CONTEXT, null);
this.repository.save(toSave);
Map<String, RedisSession> findByPrincipalName = this.repository.findByIndexNameAndIndexValue(INDEX_NAME, getSecurityName());
assertThat(findByPrincipalName).isEmpty();
}
Aggregations