use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class CookieHttpSessionIdResolverTests method onNewSessionTwiceNewId.
@Test
public void onNewSessionTwiceNewId() throws Exception {
Session newSession = new MapSession();
this.strategy.setSessionId(this.request, this.response, this.session.getId());
this.strategy.setSessionId(this.request, this.response, newSession.getId());
Cookie[] cookies = this.response.getCookies();
assertThat(cookies).hasSize(2);
assertThat(base64Decode(cookies[0].getValue())).isEqualTo(this.session.getId());
assertThat(base64Decode(cookies[1].getValue())).isEqualTo(newSession.getId());
}
use of org.springframework.session.MapSession in project metasfresh-webui-api by metasfresh.
the class FixedMapSessionRepository method createSession.
@Override
public ExpiringSession createSession() {
final ExpiringSession result = new MapSession();
if (defaultMaxInactiveInterval != null) {
result.setMaxInactiveIntervalInSeconds(defaultMaxInactiveInterval);
}
// Fire event
applicationEventPublisher.publishEvent(new SessionCreatedEvent(this, result.getId()));
return result;
}
use of org.springframework.session.MapSession in project metasfresh-webui-api by metasfresh.
the class FixedMapSessionRepository method getSession.
@Override
public ExpiringSession getSession(final String id) {
final ExpiringSession saved = sessions.get(id);
if (saved == null) {
return null;
}
if (saved.isExpired()) {
final boolean expired = true;
deleteAndFireEvent(saved.getId(), expired);
return null;
}
return new MapSession(saved);
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryTests method getSessionFound.
@Test
public void getSessionFound() {
String attrName = "attrName";
MapSession expected = new MapSession();
expected.setLastAccessedTime(Instant.now().minusSeconds(60));
expected.setAttribute(attrName, "attrValue");
given(this.redisOperations.boundHashOps(getKey(expected.getId()))).willReturn(this.boundHashOperations);
Map map = map(RedisOperationsSessionRepository.getSessionAttrNameKey(attrName), expected.getAttribute(attrName), RedisOperationsSessionRepository.CREATION_TIME_ATTR, expected.getCreationTime().toEpochMilli(), RedisOperationsSessionRepository.MAX_INACTIVE_ATTR, (int) expected.getMaxInactiveInterval().getSeconds(), RedisOperationsSessionRepository.LAST_ACCESSED_ATTR, expected.getLastAccessedTime().toEpochMilli());
given(this.boundHashOperations.entries()).willReturn(map);
RedisSession session = this.redisRepository.findById(expected.getId());
assertThat(session.getId()).isEqualTo(expected.getId());
assertThat(session.getAttributeNames()).isEqualTo(expected.getAttributeNames());
assertThat(session.<String>getAttribute(attrName)).isEqualTo(expected.getAttribute(attrName));
assertThat(session.getCreationTime()).isEqualTo(expected.getCreationTime());
assertThat(session.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval());
assertThat(session.getLastAccessedTime()).isEqualTo(expected.getLastAccessedTime());
}
use of org.springframework.session.MapSession in project spring-session by spring-projects.
the class RedisOperationsSessionRepositoryTests method saveSetAttribute.
@Test
public void saveSetAttribute() {
String attrName = "attrName";
RedisSession session = this.redisRepository.new RedisSession(new MapSession());
session.setAttribute(attrName, "attrValue");
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), session.getAttribute(attrName)));
}
Aggregations