Java Code Examples for org.springframework.session.MapSession#setCreationTime()

The following examples show how to use org.springframework.session.MapSession#setCreationTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonSessionRepository.java    From redisson with Apache License 2.0 6 votes vote down vote up
private MapSession loadSession(String sessionId) {
    RMap<String, Object> map = redisson.getMap(keyPrefix + sessionId, new CompositeCodec(StringCodec.INSTANCE, redisson.getConfig().getCodec()));
    Set<Entry<String, Object>> entrySet = map.readAllEntrySet();
    if (entrySet.isEmpty()) {
        return null;
    }
    
    MapSession delegate = new MapSession(sessionId);
    for (Entry<String, Object> entry : entrySet) {
        if ("session:creationTime".equals(entry.getKey())) {
            delegate.setCreationTime(Instant.ofEpochMilli((Long) entry.getValue()));
        } else if ("session:lastAccessedTime".equals(entry.getKey())) {
            delegate.setLastAccessedTime(Instant.ofEpochMilli((Long) entry.getValue()));
        } else if ("session:maxInactiveInterval".equals(entry.getKey())) {
            delegate.setMaxInactiveInterval(Duration.ofSeconds((Long) entry.getValue()));
        } else if (entry.getKey().startsWith(SESSION_ATTR_PREFIX)) {
            delegate.setAttribute(entry.getKey().substring(SESSION_ATTR_PREFIX.length()), entry.getValue());
        }
    }
    return delegate;
}
 
Example 2
Source File: JdbcIndexedSessionRepository.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Override
public List<JdbcSession> extractData(ResultSet rs) throws SQLException, DataAccessException {
	List<JdbcSession> sessions = new ArrayList<>();
	while (rs.next()) {
		String id = rs.getString("SESSION_ID");
		JdbcSession session;
		if (sessions.size() > 0 && getLast(sessions).getId().equals(id)) {
			session = getLast(sessions);
		}
		else {
			MapSession delegate = new MapSession(id);
			String primaryKey = rs.getString("PRIMARY_ID");
			delegate.setCreationTime(Instant.ofEpochMilli(rs.getLong("CREATION_TIME")));
			delegate.setLastAccessedTime(Instant.ofEpochMilli(rs.getLong("LAST_ACCESS_TIME")));
			delegate.setMaxInactiveInterval(Duration.ofSeconds(rs.getInt("MAX_INACTIVE_INTERVAL")));
			session = new JdbcSession(delegate, primaryKey, false);
		}
		String attributeName = rs.getString("ATTRIBUTE_NAME");
		if (attributeName != null) {
			byte[] bytes = getLobHandler().getBlobAsBytes(rs, "ATTRIBUTE_BYTES");
			session.delegate.setAttribute(attributeName, lazily(() -> deserialize(bytes)));
		}
		sessions.add(session);
	}
	return sessions;
}
 
Example 3
Source File: RedisSessionMapper.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Override
public MapSession apply(Map<String, Object> map) {
	Assert.notEmpty(map, "map must not be empty");
	MapSession session = new MapSession(this.sessionId);
	Long creationTime = (Long) map.get(CREATION_TIME_KEY);
	if (creationTime == null) {
		handleMissingKey(CREATION_TIME_KEY);
	}
	session.setCreationTime(Instant.ofEpochMilli(creationTime));
	Long lastAccessedTime = (Long) map.get(LAST_ACCESSED_TIME_KEY);
	if (lastAccessedTime == null) {
		handleMissingKey(LAST_ACCESSED_TIME_KEY);
	}
	session.setLastAccessedTime(Instant.ofEpochMilli(lastAccessedTime));
	Integer maxInactiveInterval = (Integer) map.get(MAX_INACTIVE_INTERVAL_KEY);
	if (maxInactiveInterval == null) {
		handleMissingKey(MAX_INACTIVE_INTERVAL_KEY);
	}
	session.setMaxInactiveInterval(Duration.ofSeconds(maxInactiveInterval));
	map.forEach((name, value) -> {
		if (name.startsWith(ATTRIBUTE_PREFIX)) {
			session.setAttribute(name.substring(ATTRIBUTE_PREFIX.length()), value);
		}
	});
	return session;
}
 
Example 4
Source File: RedisIndexedSessionRepository.java    From spring-session with Apache License 2.0 6 votes vote down vote up
private MapSession loadSession(String id, Map<Object, Object> entries) {
	MapSession loaded = new MapSession(id);
	for (Map.Entry<Object, Object> entry : entries.entrySet()) {
		String key = (String) entry.getKey();
		if (RedisSessionMapper.CREATION_TIME_KEY.equals(key)) {
			loaded.setCreationTime(Instant.ofEpochMilli((long) entry.getValue()));
		}
		else if (RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY.equals(key)) {
			loaded.setMaxInactiveInterval(Duration.ofSeconds((int) entry.getValue()));
		}
		else if (RedisSessionMapper.LAST_ACCESSED_TIME_KEY.equals(key)) {
			loaded.setLastAccessedTime(Instant.ofEpochMilli((long) entry.getValue()));
		}
		else if (key.startsWith(RedisSessionMapper.ATTRIBUTE_PREFIX)) {
			loaded.setAttribute(key.substring(RedisSessionMapper.ATTRIBUTE_PREFIX.length()), entry.getValue());
		}
	}
	return loaded;
}
 
Example 5
Source File: RedisSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
private RedisSession createTestSession(Map<String, Object> attributes) {
	MapSession cached = new MapSession(TEST_SESSION_ID);
	cached.setCreationTime(Instant.EPOCH);
	cached.setLastAccessedTime(Instant.EPOCH);
	attributes.forEach(cached::setAttribute);
	return this.sessionRepository.new RedisSession(cached, false);
}