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

The following examples show how to use org.springframework.session.MapSession#setMaxInactiveInterval() . 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: SessionUpdateEntryProcessor.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Override
public Object process(Map.Entry<String, MapSession> entry) {
	MapSession value = entry.getValue();
	if (value == null) {
		return Boolean.FALSE;
	}
	if (this.lastAccessedTime != null) {
		value.setLastAccessedTime(this.lastAccessedTime);
	}
	if (this.maxInactiveInterval != null) {
		value.setMaxInactiveInterval(this.maxInactiveInterval);
	}
	if (this.delta != null) {
		for (final Map.Entry<String, Object> attribute : this.delta.entrySet()) {
			if (attribute.getValue() != null) {
				value.setAttribute(attribute.getKey(), attribute.getValue());
			}
			else {
				value.removeAttribute(attribute.getKey());
			}
		}
	}
	entry.setValue(value);
	return Boolean.TRUE;
}
 
Example 3
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 4
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 5
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 6
Source File: HazelcastIndexedSessionRepository.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public HazelcastSession createSession() {
	MapSession cached = new MapSession();
	if (this.defaultMaxInactiveInterval != null) {
		cached.setMaxInactiveInterval(Duration.ofSeconds(this.defaultMaxInactiveInterval));
	}
	HazelcastSession session = new HazelcastSession(cached, true);
	session.flushImmediateIfNecessary();
	return session;
}
 
Example 7
Source File: JdbcIndexedSessionRepository.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public JdbcSession createSession() {
	MapSession delegate = new MapSession();
	if (this.defaultMaxInactiveInterval != null) {
		delegate.setMaxInactiveInterval(Duration.ofSeconds(this.defaultMaxInactiveInterval));
	}
	JdbcSession session = new JdbcSession(delegate, UUID.randomUUID().toString(), true);
	session.flushIfRequired();
	return session;
}
 
Example 8
Source File: RedisSessionRepository.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public RedisSession createSession() {
	MapSession cached = new MapSession();
	cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
	RedisSession session = new RedisSession(cached, true);
	session.flushIfRequired();
	return session;
}
 
Example 9
Source File: RedisIndexedSessionRepository.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public RedisSession createSession() {
	MapSession cached = new MapSession();
	if (this.defaultMaxInactiveInterval != null) {
		cached.setMaxInactiveInterval(Duration.ofSeconds(this.defaultMaxInactiveInterval));
	}
	RedisSession session = new RedisSession(cached, true);
	session.flushImmediateIfNecessary();
	return session;
}