MapSessionRepository handles expried sessions
Fixes gh-31
This commit is contained in:
@@ -62,6 +62,10 @@ public class MapSessionRepository implements SessionRepository<ExpiringSession>
|
||||
if(saved == null) {
|
||||
return null;
|
||||
}
|
||||
if(saved.isExpired()) {
|
||||
delete(saved.getId());
|
||||
return null;
|
||||
}
|
||||
MapSession result = new MapSession(saved);
|
||||
result.setLastAccessedTime(System.currentTimeMillis());
|
||||
return result;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user