JDBC session with negative timeout should never expire

Closes gh-1847
This commit is contained in:
Eleftheria Stein
2021-05-10 15:13:26 +02:00
parent 0e5dd1863f
commit 4bb2bd6fda
2 changed files with 17 additions and 1 deletions

View File

@@ -586,6 +586,18 @@ abstract class AbstractJdbcIndexedSessionRepositoryITests {
assertThat(this.repository.findById(session.getId())).isNull();
}
@Test
void cleanupExpiredSessionsWhenMaxInactiveIntervalNegativeThenSessionNotDeleted() {
JdbcSession session = this.repository.createSession();
session.setMaxInactiveInterval(Duration.ofSeconds(-1));
session.setLastAccessedTime(Instant.now().minusSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS + 1));
this.repository.save(session);
this.repository.cleanUpExpiredSessions();
assertThat(this.repository.findById(session.getId())).isNotNull();
}
@Test
void changeSessionIdWhenOnlyChangeId() {
String attrName = "changeSessionId";

View File

@@ -185,7 +185,8 @@ public class JdbcIndexedSessionRepository
// @formatter:off
private static final String DELETE_SESSION_QUERY = ""
+ "DELETE FROM %TABLE_NAME% "
+ "WHERE SESSION_ID = ?";
+ "WHERE SESSION_ID = ? "
+ "AND MAX_INACTIVE_INTERVAL >= 0";
// @formatter:on
// @formatter:off
@@ -701,6 +702,9 @@ public class JdbcIndexedSessionRepository
}
Instant getExpiryTime() {
if (getMaxInactiveInterval().isNegative()) {
return Instant.ofEpochMilli(Long.MAX_VALUE);
}
return getLastAccessedTime().plus(getMaxInactiveInterval());
}