From 04fcc393fd85bf25bdb22f754f55799e7389cbd2 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Wed, 12 Nov 2014 09:28:24 -0600 Subject: [PATCH] MapSessionRepository handles expried sessions Fixes gh-31 --- .../session/MapSessionRepository.java | 4 ++ .../session/MapSessionRepositoryTests.java | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 spring-session/src/test/java/org/springframework/session/MapSessionRepositoryTests.java diff --git a/spring-session/src/main/java/org/springframework/session/MapSessionRepository.java b/spring-session/src/main/java/org/springframework/session/MapSessionRepository.java index 19bde00c..72bc94d4 100644 --- a/spring-session/src/main/java/org/springframework/session/MapSessionRepository.java +++ b/spring-session/src/main/java/org/springframework/session/MapSessionRepository.java @@ -62,6 +62,10 @@ public class MapSessionRepository implements SessionRepository if(saved == null) { return null; } + if(saved.isExpired()) { + delete(saved.getId()); + return null; + } MapSession result = new MapSession(saved); result.setLastAccessedTime(System.currentTimeMillis()); return result; diff --git a/spring-session/src/test/java/org/springframework/session/MapSessionRepositoryTests.java b/spring-session/src/test/java/org/springframework/session/MapSessionRepositoryTests.java new file mode 100644 index 00000000..4fe8f45a --- /dev/null +++ b/spring-session/src/test/java/org/springframework/session/MapSessionRepositoryTests.java @@ -0,0 +1,45 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.session; + +import static org.fest.assertions.Assertions.assertThat; + +import java.util.concurrent.TimeUnit; + +import org.junit.Before; +import org.junit.Test; + +public class MapSessionRepositoryTests { + MapSessionRepository repository; + + MapSession session; + + @Before + public void setup() { + repository = new MapSessionRepository(); + session = new MapSession(); + } + + @Test + public void getSessionExpired() { + session.setMaxInactiveInterval(1); + session.setLastAccessedTime(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5)); + repository.save(session); + + assertThat(repository.getSession(session.getId())).isNull(); + } + +}