use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class ReactiveRedisOperationsSessionRepositoryTests method saveLastAccessChanged.
@Test
public void saveLastAccessChanged() {
given(this.redisOperations.opsForHash()).willReturn(this.hashOperations);
given(this.hashOperations.putAll(anyString(), this.delta.capture())).willReturn(Mono.just(true));
given(this.redisOperations.expire(anyString(), any())).willReturn(Mono.just(true));
ReactiveRedisOperationsSessionRepository.RedisSession session = this.repository.new RedisSession(new MapSession());
session.setLastAccessedTime(Instant.ofEpochMilli(12345678L));
Mono<Void> result = this.repository.save(session);
StepVerifier.create(result).expectNextMatches(predicate -> {
assertThat(this.delta.getAllValues().get(0)).isEqualTo(map(RedisOperationsSessionRepository.LAST_ACCESSED_ATTR, session.getLastAccessedTime().toEpochMilli()));
return true;
});
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class ReactiveRedisOperationsSessionRepositoryTests method saveRemoveAttribute.
@Test
public void saveRemoveAttribute() {
given(this.redisOperations.opsForHash()).willReturn(this.hashOperations);
given(this.hashOperations.putAll(anyString(), this.delta.capture())).willReturn(Mono.just(true));
given(this.redisOperations.expire(anyString(), any())).willReturn(Mono.just(true));
String attrName = "attrName";
ReactiveRedisOperationsSessionRepository.RedisSession session = this.repository.new RedisSession(new MapSession());
session.removeAttribute(attrName);
Mono<Void> result = this.repository.save(session);
StepVerifier.create(result).expectNextMatches(predicate -> {
assertThat(this.delta.getAllValues().get(0)).isEqualTo(map(RedisOperationsSessionRepository.getSessionAttrNameKey(attrName), null));
return true;
});
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class HazelcastSessionRepositoryTests method createSessionDefaultMaxInactiveInterval.
@Test
public void createSessionDefaultMaxInactiveInterval() throws Exception {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
HazelcastSession session = this.repository.createSession();
assertThat(session.getMaxInactiveInterval()).isEqualTo(new MapSession().getMaxInactiveInterval());
verifyZeroInteractions(this.sessions);
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class HazelcastSessionRepositoryTests method findByIndexNameAndIndexValuePrincipalIndexNameFound.
@Test
public void findByIndexNameAndIndexValuePrincipalIndexNameFound() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean());
String principal = "username";
Authentication authentication = new UsernamePasswordAuthenticationToken(principal, "notused", AuthorityUtils.createAuthorityList("ROLE_USER"));
List<MapSession> saved = new ArrayList<>(2);
MapSession saved1 = new MapSession();
saved1.setAttribute(SPRING_SECURITY_CONTEXT, authentication);
saved.add(saved1);
MapSession saved2 = new MapSession();
saved2.setAttribute(SPRING_SECURITY_CONTEXT, authentication);
saved.add(saved2);
given(this.sessions.values(isA(EqualPredicate.class))).willReturn(saved);
Map<String, HazelcastSession> sessions = this.repository.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
assertThat(sessions).hasSize(2);
verify(this.sessions, times(1)).values(isA(EqualPredicate.class));
verifyZeroInteractions(this.sessions);
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class HazelcastSessionRepository method findByIndexNameAndIndexValue.
@Override
public Map<String, HazelcastSession> findByIndexNameAndIndexValue(String indexName, String indexValue) {
if (!PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) {
return Collections.emptyMap();
}
Collection<MapSession> sessions = this.sessions.values(Predicates.equal(PRINCIPAL_NAME_ATTRIBUTE, indexValue));
Map<String, HazelcastSession> sessionMap = new HashMap<>(sessions.size());
for (MapSession session : sessions) {
sessionMap.put(session.getId(), new HazelcastSession(session));
}
return sessionMap;
}
Aggregations