Move ExpiringSession API into Session

This commit is contained in:
Vedran Pavic
2017-05-04 19:50:50 +02:00
committed by Rob Winch
parent a848df1235
commit 4cf26d9c36
40 changed files with 217 additions and 269 deletions

View File

@@ -416,7 +416,7 @@ include::{docs-test-dir}docs/security/SecurityConfiguration.java[tags=class]
----
This assumes that you've also configured Spring Session to provide a `FindByIndexNameSessionRepository` that
returns `ExpiringSession` instances.
returns `Session` instances.
When using XML configuration, it would look something like this:
[source,xml,indent=0]
@@ -458,11 +458,7 @@ include::{indexdoc-tests}[tags=repository-demo]
<5> We retrieve the `Session` from the `SessionRepository`.
<6> We obtain the persisted `User` from our `Session` without the need for explicitly casting our attribute.
[[api-expiringsession]]
=== ExpiringSession
An `ExpiringSession` extends a `Session` by providing attributes related to the `Session` instance's expiration.
If there is no need to interact with the expiration information, prefer using the more simple `Session` API.
`Session` API also provides attributes related to the `Session` instance's expiration.
Typical usage might look like the following:
@@ -471,17 +467,17 @@ Typical usage might look like the following:
include::{indexdoc-tests}[tags=expire-repository-demo]
----
<1> We create a `SessionRepository` instance with a generic type, `S`, that extends `ExpiringSession`. The generic type is defined in our class.
<2> We create a new `ExpiringSession` using our `SessionRepository` and assign it to a variable of type `S`.
<3> We interact with the `ExpiringSession`.
In our example, we demonstrate updating the amount of time the `ExpiringSession` can be inactive before it expires.
<4> We now save the `ExpiringSession`.
<1> We create a `SessionRepository` instance with a generic type, `S`, that extends `Session`. The generic type is defined in our class.
<2> We create a new `Session` using our `SessionRepository` and assign it to a variable of type `S`.
<3> We interact with the `Session`.
In our example, we demonstrate updating the amount of time the `Session` can be inactive before it expires.
<4> We now save the `Session`.
This is why we needed the generic type `S`.
The `SessionRepository` only allows saving `ExpiringSession` instances that were created or retrieved using the same `SessionRepository`.
The `SessionRepository` only allows saving `Session` instances that were created or retrieved using the same `SessionRepository`.
This allows for the `SessionRepository` to make implementation specific optimizations (i.e. only writing attributes that have changed).
The last accessed time is automatically updated when the `ExpiringSession` is saved.
<5> We retrieve the `ExpiringSession` from the `SessionRepository`.
If the `ExpiringSession` were expired, the result would be null.
The last accessed time is automatically updated when the `Session` is saved.
<5> We retrieve the `Session` from the `SessionRepository`.
If the `Session` were expired, the result would be null.
[[api-sessionrepository]]
=== SessionRepository
@@ -640,7 +636,7 @@ HMSET spring:session:sessions:33fdd1b6-b496-4b33-9f7d-df96679d32fe sessionAttr:a
[[api-redisoperationssessionrepository-expiration]]
===== Session Expiration
An expiration is associated to each session using the EXPIRE command based upon the `ExpiringSession.getMaxInactiveInterval()`.
An expiration is associated to each session using the EXPIRE command based upon the `Session.getMaxInactiveInterval()`.
For example:
----
@@ -776,7 +772,7 @@ redis 127.0.0.1:6379> hget spring:session:sessions:4fc39ce3-63b3-4e17-b1c4-5e1ed
[[api-mapsessionrepository]]
=== MapSessionRepository
The `MapSessionRepository` allows for persisting `ExpiringSession` in a `Map` with the key being the `ExpiringSession` id and the value being the `ExpiringSession`.
The `MapSessionRepository` allows for persisting `Session` in a `Map` with the key being the `Session` id and the value being the `Session`.
The implementation can be used with a `ConcurrentHashMap` as a testing or convenience mechanism.
Alternatively, it can be used with distributed `Map` implementations. For example, it can be used with Hazelcast.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -21,7 +21,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -38,7 +38,7 @@ import static org.mockito.Mockito.mock;
@WebAppConfiguration
public class HttpSessionConfigurationNoOpConfigureRedisActionXmlTests {
@Autowired
SessionRepositoryFilter<? extends ExpiringSession> filter;
SessionRepositoryFilter<? extends Session> filter;
@Test
public void redisConnectionFactoryNotUsedSinceNoValidation() {

View File

@@ -26,7 +26,6 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactor
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.mock.web.MockServletContext;
import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSession;
import org.springframework.session.MapSessionRepository;
import org.springframework.session.Session;
@@ -49,7 +48,7 @@ public class IndexDocTests {
@Test
public void repositoryDemo() {
RepositoryDemo<ExpiringSession> demo = new RepositoryDemo<>();
RepositoryDemo<Session> demo = new RepositoryDemo<>();
demo.repository = new MapSessionRepository();
demo.demo();
@@ -81,14 +80,14 @@ public class IndexDocTests {
@Test
public void expireRepositoryDemo() {
ExpiringRepositoryDemo<ExpiringSession> demo = new ExpiringRepositoryDemo<>();
ExpiringRepositoryDemo<Session> demo = new ExpiringRepositoryDemo<>();
demo.repository = new MapSessionRepository();
demo.demo();
}
// tag::expire-repository-demo[]
public class ExpiringRepositoryDemo<S extends ExpiringSession> {
public class ExpiringRepositoryDemo<S extends Session> {
private SessionRepository<S> repository; // <1>
public void demo() {
@@ -111,7 +110,7 @@ public class IndexDocTests {
public void newRedisOperationsSessionRepository() {
// tag::new-redisoperationssessionrepository[]
LettuceConnectionFactory factory = new LettuceConnectionFactory();
SessionRepository<? extends ExpiringSession> repository = new RedisOperationsSessionRepository(
SessionRepository<? extends Session> repository = new RedisOperationsSessionRepository(
factory);
// end::new-redisoperationssessionrepository[]
}
@@ -120,7 +119,7 @@ public class IndexDocTests {
@SuppressWarnings("unused")
public void mapRepository() {
// tag::new-mapsessionrepository[]
SessionRepository<? extends ExpiringSession> repository = new MapSessionRepository();
SessionRepository<? extends Session> repository = new MapSessionRepository();
// end::new-mapsessionrepository[]
}
@@ -136,7 +135,7 @@ public class IndexDocTests {
// ... configure transactionManager ...
SessionRepository<? extends ExpiringSession> repository =
SessionRepository<? extends Session> repository =
new JdbcOperationsSessionRepository(jdbcTemplate, transactionManager);
// end::new-jdbcoperationssessionrepository[]
}

View File

@@ -26,7 +26,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.test.context.ContextConfiguration;
@@ -48,7 +48,7 @@ import static org.springframework.security.test.web.servlet.setup.SecurityMockMv
@ContextConfiguration(classes = RememberMeSecurityConfiguration.class)
@WebAppConfiguration
@SuppressWarnings("rawtypes")
public class RememberMeSecurityConfigurationTests<T extends ExpiringSession> {
public class RememberMeSecurityConfigurationTests<T extends Session> {
@Autowired
WebApplicationContext context;
@Autowired

View File

@@ -26,7 +26,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.test.context.ContextConfiguration;
@@ -48,7 +48,7 @@ import static org.springframework.security.test.web.servlet.setup.SecurityMockMv
@ContextConfiguration
@WebAppConfiguration
@SuppressWarnings("rawtypes")
public class RememberMeSecurityConfigurationXmlTests<T extends ExpiringSession> {
public class RememberMeSecurityConfigurationXmlTests<T extends Session> {
@Autowired
WebApplicationContext context;
@Autowired

View File

@@ -21,8 +21,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.security.SpringSessionBackedSessionRegistry;
/**
@@ -33,7 +33,7 @@ import org.springframework.session.security.SpringSessionBackedSessionRegistry;
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private FindByIndexNameSessionRepository<ExpiringSession> sessionRepository;
private FindByIndexNameSessionRepository<Session> sessionRepository;
@Override
protected void configure(HttpSecurity http) throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -21,8 +21,8 @@ import java.util.Collection;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
@@ -39,11 +39,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
public class IndexController {
// tag::findbyusername[]
@Autowired
FindByIndexNameSessionRepository<? extends ExpiringSession> sessions;
FindByIndexNameSessionRepository<? extends Session> sessions;
@RequestMapping("/")
public String index(Principal principal, Model model) {
Collection<? extends ExpiringSession> usersSessions = this.sessions
Collection<? extends Session> usersSessions = this.sessions
.findByIndexNameAndIndexValue(
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME,
principal.getName())

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -19,7 +19,7 @@ package sample.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.web.socket.config.annotation.AbstractSessionWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@@ -29,7 +29,7 @@ import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@EnableScheduling
@EnableWebSocketMessageBroker
public class WebSocketConfig
extends AbstractSessionWebSocketMessageBrokerConfigurer<ExpiringSession> { // <1>
extends AbstractSessionWebSocketMessageBrokerConfigurer<Session> { // <1>
protected void configureStompEndpoints(StompEndpointRegistry registry) { // <2>
registry.addEndpoint("/messages").withSockJS();

View File

@@ -23,7 +23,7 @@ import sample.websocket.WebSocketDisconnectHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
/**
* These handlers are separated from WebSocketConfig because they are specific to this
@@ -32,7 +32,7 @@ import org.springframework.session.ExpiringSession;
* @author Rob Winch
*/
@Configuration
public class WebSocketHandlersConfig<S extends ExpiringSession> {
public class WebSocketHandlersConfig<S extends Session> {
@Bean
public WebSocketConnectHandler<S> webSocketConnectHandler(

View File

@@ -26,7 +26,7 @@ import sample.mvc.MvcConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -50,7 +50,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
public class RestMockMvcTests {
@Autowired
SessionRepositoryFilter<? extends ExpiringSession> sessionRepositoryFilter;
SessionRepositoryFilter<? extends Session> sessionRepositoryFilter;
@Autowired
WebApplicationContext context;

View File

@@ -35,9 +35,9 @@ import com.hazelcast.config.SerializerConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSession;
import org.springframework.session.MapSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.web.http.SessionRepositoryFilter;
@@ -62,11 +62,10 @@ public class Initializer implements ServletContextListener {
cfg.addMapConfig(mc);
this.instance = Hazelcast.newHazelcastInstance(cfg);
Map<String, ExpiringSession> sessions = this.instance.getMap(sessionMapName);
Map<String, Session> sessions = this.instance.getMap(sessionMapName);
SessionRepository<ExpiringSession> sessionRepository = new MapSessionRepository(
sessions);
SessionRepositoryFilter<ExpiringSession> filter = new SessionRepositoryFilter<>(
SessionRepository<Session> sessionRepository = new MapSessionRepository(sessions);
SessionRepositoryFilter<Session> filter = new SessionRepositoryFilter<>(
sessionRepository);
Dynamic fr = sc.addFilter("springSessionFilter", filter);
fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -32,7 +32,7 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.events.SessionExpiredEvent;
import org.springframework.test.context.ContextConfiguration;
@@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@WebAppConfiguration
public class EnableRedisHttpSessionExpireSessionDestroyedTests<S extends ExpiringSession> {
public class EnableRedisHttpSessionExpireSessionDestroyedTests<S extends Session> {
@Autowired
private SessionRepository<S> repository;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -20,7 +20,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RedisHttpSessionConfig.class)
@WebAppConfiguration
public class RedisOperationsSessionRepositoryFlushImmediatelyITests<S extends ExpiringSession> {
public class RedisOperationsSessionRepositoryFlushImmediatelyITests<S extends Session> {
@Autowired
private SessionRepository<S> sessionRepository;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -29,7 +29,6 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
@@ -54,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@WebAppConfiguration
public class EnableHazelcastHttpSessionEventsTests<S extends ExpiringSession> {
public class EnableHazelcastHttpSessionEventsTests<S extends Session> {
private final static int MAX_INACTIVE_INTERVAL_IN_SECONDS = 1;
@@ -119,7 +118,7 @@ public class EnableHazelcastHttpSessionEventsTests<S extends ExpiringSession> {
assertThat(this.registry.<SessionExpiredEvent>getEvent(sessionToSave.getId()))
.isInstanceOf(SessionExpiredEvent.class);
assertThat(this.repository.<ExpiringSession>getSession(sessionToSave.getId())).isNull();
assertThat(this.repository.<Session>getSession(sessionToSave.getId())).isNull();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -27,7 +27,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -42,12 +42,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Tommy Ludwig
*/
public class HazelcastHttpSessionConfigurationXmlTests<S extends ExpiringSession> {
public class HazelcastHttpSessionConfigurationXmlTests<S extends Session> {
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@WebAppConfiguration
public static class CustomXmlMapNameTest<S extends ExpiringSession> {
public static class CustomXmlMapNameTest<S extends Session> {
@Autowired
private SessionRepository<S> repository;
@@ -84,7 +84,7 @@ public class HazelcastHttpSessionConfigurationXmlTests<S extends ExpiringSession
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@WebAppConfiguration
public static class CustomXmlMapNameAndIdleTest<S extends ExpiringSession> {
public static class CustomXmlMapNameAndIdleTest<S extends Session> {
@Autowired
private SessionRepository<S> repository;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -34,7 +34,6 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
@@ -156,7 +155,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests {
toSave.setLastAccessedTime(lastAccessedTime);
this.repository.save(toSave);
ExpiringSession session = this.repository.getSession(toSave.getId());
Session session = this.repository.getSession(toSave.getId());
assertThat(session).isNotNull();
assertThat(session.isExpired()).isFalse();

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2014-2016 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;
/**
* A {@link Session} that contains additional attributes that are useful for determining
* if a session is expired.
*
* @author Rob Winch
* @since 1.0
*/
public interface ExpiringSession extends Session {
/**
* Gets the time when this session was created in milliseconds since midnight of
* 1/1/1970 GMT.
*
* @return the time when this session was created in milliseconds since midnight of
* 1/1/1970 GMT.
*/
long getCreationTime();
/**
* Sets the last accessed time in milliseconds since midnight of 1/1/1970 GMT.
*
* @param lastAccessedTime the last accessed time in milliseconds since midnight of
* 1/1/1970 GMT
*/
void setLastAccessedTime(long lastAccessedTime);
/**
* Gets the last time this {@link Session} was accessed expressed in milliseconds
* since midnight of 1/1/1970 GMT.
*
* @return the last time the client sent a request associated with the session
* expressed in milliseconds since midnight of 1/1/1970 GMT
*/
long getLastAccessedTime();
/**
* Sets the maximum inactive interval in seconds between requests before this session
* will be invalidated. A negative time indicates that the session will never timeout.
*
* @param interval the number of seconds that the {@link Session} should be kept alive
* between client requests.
*/
void setMaxInactiveIntervalInSeconds(int interval);
/**
* Gets the maximum inactive interval in seconds between requests before this session
* will be invalidated. A negative time indicates that the session will never timeout.
*
* @return the maximum inactive interval in seconds between requests before this
* session will be invalidated. A negative time indicates that the session will never
* timeout.
*/
int getMaxInactiveIntervalInSeconds();
/**
* Returns true if the session is expired.
*
* @return true if the session is expired, else false.
*/
boolean isExpired();
}

View File

@@ -43,7 +43,7 @@ import java.util.concurrent.TimeUnit;
* @author Rob Winch
* @since 1.0
*/
public final class MapSession implements ExpiringSession, Serializable {
public final class MapSession implements Session, Serializable {
/**
* Default {@link #setMaxInactiveIntervalInSeconds(int)} (30 minutes).
*/
@@ -83,7 +83,7 @@ public final class MapSession implements ExpiringSession, Serializable {
* @param session the {@link Session} to initialize this {@link Session} with. Cannot
* be null.
*/
public MapSession(ExpiringSession session) {
public MapSession(Session session) {
if (session == null) {
throw new IllegalArgumentException("session cannot be null");
}

View File

@@ -36,14 +36,14 @@ import org.springframework.session.events.SessionExpiredEvent;
* @author Rob Winch
* @since 1.0
*/
public class MapSessionRepository implements SessionRepository<ExpiringSession> {
public class MapSessionRepository implements SessionRepository<Session> {
/**
* If non-null, this value is used to override
* {@link ExpiringSession#setMaxInactiveIntervalInSeconds(int)}.
* {@link Session#setMaxInactiveIntervalInSeconds(int)}.
*/
private Integer defaultMaxInactiveInterval;
private final Map<String, ExpiringSession> sessions;
private final Map<String, Session> sessions;
/**
* Creates an instance backed by a {@link java.util.concurrent.ConcurrentHashMap}.
@@ -58,7 +58,7 @@ public class MapSessionRepository implements SessionRepository<ExpiringSession>
*
* @param sessions the {@link java.util.Map} to use. Cannot be null.
*/
public MapSessionRepository(Map<String, ExpiringSession> sessions) {
public MapSessionRepository(Map<String, Session> sessions) {
if (sessions == null) {
throw new IllegalArgumentException("sessions cannot be null");
}
@@ -67,7 +67,7 @@ public class MapSessionRepository implements SessionRepository<ExpiringSession>
/**
* If non-null, this value is used to override
* {@link ExpiringSession#setMaxInactiveIntervalInSeconds(int)}.
* {@link Session#setMaxInactiveIntervalInSeconds(int)}.
* @param defaultMaxInactiveInterval the number of seconds that the {@link Session}
* should be kept alive between client requests.
*/
@@ -75,12 +75,12 @@ public class MapSessionRepository implements SessionRepository<ExpiringSession>
this.defaultMaxInactiveInterval = Integer.valueOf(defaultMaxInactiveInterval);
}
public void save(ExpiringSession session) {
public void save(Session session) {
this.sessions.put(session.getId(), new MapSession(session));
}
public ExpiringSession getSession(String id) {
ExpiringSession saved = this.sessions.get(id);
public Session getSession(String id) {
Session saved = this.sessions.get(id);
if (saved == null) {
return null;
}
@@ -95,8 +95,8 @@ public class MapSessionRepository implements SessionRepository<ExpiringSession>
this.sessions.remove(id);
}
public ExpiringSession createSession() {
ExpiringSession result = new MapSession();
public Session createSession() {
Session result = new MapSession();
if (this.defaultMaxInactiveInterval != null) {
result.setMaxInactiveIntervalInSeconds(this.defaultMaxInactiveInterval);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -71,4 +71,57 @@ public interface Session {
* @param attributeName the name of the attribute to remove
*/
void removeAttribute(String attributeName);
/**
* Gets the time when this session was created in milliseconds since midnight of
* 1/1/1970 GMT.
*
* @return the time when this session was created in milliseconds since midnight of
* 1/1/1970 GMT.
*/
long getCreationTime();
/**
* Sets the last accessed time in milliseconds since midnight of 1/1/1970 GMT.
*
* @param lastAccessedTime the last accessed time in milliseconds since midnight of
* 1/1/1970 GMT
*/
void setLastAccessedTime(long lastAccessedTime);
/**
* Gets the last time this {@link Session} was accessed expressed in milliseconds
* since midnight of 1/1/1970 GMT.
*
* @return the last time the client sent a request associated with the session
* expressed in milliseconds since midnight of 1/1/1970 GMT
*/
long getLastAccessedTime();
/**
* Sets the maximum inactive interval in seconds between requests before this session
* will be invalidated. A negative time indicates that the session will never timeout.
*
* @param interval the number of seconds that the {@link Session} should be kept alive
* between client requests.
*/
void setMaxInactiveIntervalInSeconds(int interval);
/**
* Gets the maximum inactive interval in seconds between requests before this session
* will be invalidated. A negative time indicates that the session will never timeout.
*
* @return the maximum inactive interval in seconds between requests before this
* session will be invalidated. A negative time indicates that the session will never
* timeout.
*/
int getMaxInactiveIntervalInSeconds();
/**
* Returns true if the session is expired.
*
* @return true if the session is expired, else false.
*/
boolean isExpired();
}

View File

@@ -33,7 +33,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.events.SessionCreatedEvent;
import org.springframework.session.events.SessionDestroyedEvent;
@@ -122,7 +122,7 @@ public class SpringHttpSessionConfiguration implements ApplicationContextAware {
}
@Bean
public <S extends ExpiringSession> SessionRepositoryFilter<? extends ExpiringSession> springSessionRepositoryFilter(
public <S extends Session> SessionRepositoryFilter<? extends Session> springSessionRepositoryFilter(
SessionRepository<S> sessionRepository) {
SessionRepositoryFilter<S> sessionRepositoryFilter = new SessionRepositoryFilter<>(
sessionRepository);

View File

@@ -39,7 +39,6 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
@@ -259,20 +258,20 @@ public class RedisOperationsSessionRepository implements
/**
* The key in the Hash representing
* {@link org.springframework.session.ExpiringSession#getCreationTime()}.
* {@link org.springframework.session.Session#getCreationTime()}.
*/
static final String CREATION_TIME_ATTR = "creationTime";
/**
* The key in the Hash representing
* {@link org.springframework.session.ExpiringSession#getMaxInactiveIntervalInSeconds()}
* {@link org.springframework.session.Session#getMaxInactiveIntervalInSeconds()}
* .
*/
static final String MAX_INACTIVE_ATTR = "maxInactiveInterval";
/**
* The key in the Hash representing
* {@link org.springframework.session.ExpiringSession#getLastAccessedTime()}.
* {@link org.springframework.session.Session#getLastAccessedTime()}.
*/
static final String LAST_ACCESSED_ATTR = "lastAccessedTime";
@@ -549,7 +548,7 @@ public class RedisOperationsSessionRepository implements
public void handleCreated(Map<Object, Object> loaded, String channel) {
String id = channel.substring(channel.lastIndexOf(":") + 1);
ExpiringSession session = loadSession(id, loaded);
Session session = loadSession(id, loaded);
publishEvent(new SessionCreatedEvent(this, session));
}
@@ -667,7 +666,7 @@ public class RedisOperationsSessionRepository implements
* @author Rob Winch
* @since 1.0
*/
final class RedisSession implements ExpiringSession {
final class RedisSession implements Session {
private final MapSession cached;
private Long originalLastAccessTime;
private Map<String, Object> delta = new HashMap<>();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -26,7 +26,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession;
/**
@@ -61,14 +61,13 @@ final class RedisSessionExpirationPolicy {
this.redisSession = redisSession;
}
public void onDelete(ExpiringSession session) {
public void onDelete(Session session) {
long toExpire = roundUpToNextMinute(expiresInMillis(session));
String expireKey = getExpirationKey(toExpire);
this.redis.boundSetOps(expireKey).remove(session.getId());
}
public void onExpirationUpdated(Long originalExpirationTimeInMilli,
ExpiringSession session) {
public void onExpirationUpdated(Long originalExpirationTimeInMilli, Session session) {
String keyToExpire = "expires:" + session.getId();
long toExpire = roundUpToNextMinute(expiresInMillis(session));
@@ -147,7 +146,7 @@ final class RedisSessionExpirationPolicy {
this.redis.hasKey(key);
}
static long expiresInMillis(ExpiringSession session) {
static long expiresInMillis(Session session) {
int maxInactiveInSeconds = session.getMaxInactiveIntervalInSeconds();
long lastAccessedTimeInMillis = session.getLastAccessedTime();
return lastAccessedTimeInMillis + TimeUnit.SECONDS.toMillis(maxInactiveInSeconds);

View File

@@ -37,7 +37,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
@@ -267,7 +266,7 @@ public class HazelcastSessionRepository implements
*
* @author Aleksandar Stojsavljevic
*/
final class HazelcastSession implements ExpiringSession {
final class HazelcastSession implements Session {
private final MapSession delegate;
private boolean changed;

View File

@@ -46,7 +46,6 @@ import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
@@ -185,8 +184,7 @@ public class JdbcOperationsSessionRepository implements
private final TransactionOperations transactionOperations;
private final ResultSetExtractor<List<ExpiringSession>> extractor =
new ExpiringSessionResultSetExtractor();
private final ResultSetExtractor<List<Session>> extractor = new SessionResultSetExtractor();
/**
* The name of database table used by Spring Session to store sessions.
@@ -460,8 +458,8 @@ public class JdbcOperationsSessionRepository implements
}
public JdbcSession getSession(final String id) {
final ExpiringSession session = this.transactionOperations.execute(status -> {
List<ExpiringSession> sessions = JdbcOperationsSessionRepository.this.jdbcOperations.query(
final Session session = this.transactionOperations.execute(status -> {
List<Session> sessions = JdbcOperationsSessionRepository.this.jdbcOperations.query(
JdbcOperationsSessionRepository.this.getSessionQuery,
ps -> ps.setString(1, id),
JdbcOperationsSessionRepository.this.extractor
@@ -500,7 +498,7 @@ public class JdbcOperationsSessionRepository implements
return Collections.emptyMap();
}
List<ExpiringSession> sessions = this.transactionOperations.execute(status ->
List<Session> sessions = this.transactionOperations.execute(status ->
JdbcOperationsSessionRepository.this.jdbcOperations.query(
JdbcOperationsSessionRepository.this.listSessionsByPrincipalNameQuery,
ps -> ps.setString(1, indexValue),
@@ -509,7 +507,7 @@ public class JdbcOperationsSessionRepository implements
Map<String, JdbcSession> sessionMap = new HashMap<>(
sessions.size());
for (ExpiringSession session : sessions) {
for (Session session : sessions) {
sessionMap.put(session.getId(), new JdbcSession(session));
}
@@ -588,13 +586,13 @@ public class JdbcOperationsSessionRepository implements
}
/**
* The {@link ExpiringSession} to use for {@link JdbcOperationsSessionRepository}.
* The {@link Session} to use for {@link JdbcOperationsSessionRepository}.
*
* @author Vedran Pavic
*/
final class JdbcSession implements ExpiringSession {
final class JdbcSession implements Session {
private final ExpiringSession delegate;
private final Session delegate;
private boolean isNew;
@@ -607,8 +605,8 @@ public class JdbcOperationsSessionRepository implements
this.isNew = true;
}
JdbcSession(ExpiringSession delegate) {
Assert.notNull(delegate, "ExpiringSession cannot be null");
JdbcSession(Session delegate) {
Assert.notNull(delegate, "Session cannot be null");
this.delegate = delegate;
}
@@ -713,11 +711,10 @@ public class JdbcOperationsSessionRepository implements
}
private class ExpiringSessionResultSetExtractor
implements ResultSetExtractor<List<ExpiringSession>> {
private class SessionResultSetExtractor implements ResultSetExtractor<List<Session>> {
public List<ExpiringSession> extractData(ResultSet rs) throws SQLException, DataAccessException {
List<ExpiringSession> sessions = new ArrayList<>();
public List<Session> extractData(ResultSet rs) throws SQLException, DataAccessException {
List<Session> sessions = new ArrayList<>();
while (rs.next()) {
String id = rs.getString("SESSION_ID");
MapSession session;
@@ -739,7 +736,7 @@ public class JdbcOperationsSessionRepository implements
return sessions;
}
private ExpiringSession getLast(List<ExpiringSession> sessions) {
private Session getLast(List<Session> sessions) {
return sessions.get(sessions.size() - 1);
}

View File

@@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.session.SessionInformation;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
@@ -32,12 +31,12 @@ import org.springframework.session.SessionRepository;
* Ensures that calling {@link #expireNow()} propagates to Spring Session, since this
* session information contains only derived data and is not the authoritative source.
*
* @param <S> the {@link ExpiringSession} type.
* @param <S> the {@link Session} type.
* @author Joris Kuipers
* @author Vedran Pavic
* @since 1.3
*/
class SpringSessionBackedSessionInformation<S extends ExpiringSession>
class SpringSessionBackedSessionInformation<S extends Session>
extends SessionInformation {
static final String EXPIRED_ATTR = SpringSessionBackedSessionInformation.class

View File

@@ -24,8 +24,8 @@ import java.util.List;
import org.springframework.security.core.session.SessionInformation;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
import org.springframework.util.Assert;
/**
@@ -39,12 +39,12 @@ import org.springframework.util.Assert;
* <p>
* Does not support {@link #getAllPrincipals()}, since that information is not available.
*
* @param <S> the {@link ExpiringSession} type.
* @param <S> the {@link Session} type.
* @author Joris Kuipers
* @author Vedran Pavic
* @since 1.3
*/
public class SpringSessionBackedSessionRegistry<S extends ExpiringSession>
public class SpringSessionBackedSessionRegistry<S extends Session>
implements SessionRegistry {
private final FindByIndexNameSessionRepository<S> sessionRepository;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -25,23 +25,23 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
/**
* Adapts Spring Session's {@link ExpiringSession} to an {@link HttpSession}.
* Adapts Spring Session's {@link Session} to an {@link HttpSession}.
*
* @param <S> the {@link ExpiringSession} type
* @param <S> the {@link Session} type
* @author Rob Winch
* @since 1.1
*/
@SuppressWarnings("deprecation")
class ExpiringSessionHttpSession<S extends ExpiringSession> implements HttpSession {
class HttpSessionAdapter<S extends Session> implements HttpSession {
private S session;
private final ServletContext servletContext;
private boolean invalidated;
private boolean old;
ExpiringSessionHttpSession(S session, ServletContext servletContext) {
HttpSessionAdapter(S session, ServletContext servletContext) {
this.session = session;
this.servletContext = servletContext;
}

View File

@@ -24,7 +24,7 @@ import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.springframework.context.ApplicationListener;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.events.AbstractSessionEvent;
import org.springframework.session.events.SessionCreatedEvent;
import org.springframework.session.events.SessionDestroyedEvent;
@@ -73,8 +73,8 @@ public class SessionEventHttpSessionListenerAdapter
}
private HttpSessionEvent createHttpSessionEvent(AbstractSessionEvent event) {
ExpiringSession session = event.getSession();
HttpSession httpSession = new ExpiringSessionHttpSession<>(session,
Session session = event.getSession();
HttpSession httpSession = new HttpSessionAdapter<>(session,
this.context);
HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession);
return httpSessionEvent;

View File

@@ -33,7 +33,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.annotation.Order;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
@@ -56,7 +55,7 @@ import org.springframework.session.SessionRepository;
* <li>The session id is looked up using
* {@link HttpSessionStrategy#getRequestedSessionId(javax.servlet.http.HttpServletRequest)}
* . The default is to look in a cookie named SESSION.</li>
* <li>The session id of newly created {@link org.springframework.session.ExpiringSession}
* <li>The session id of newly created {@link org.springframework.session.Session}
* is sent to the client using
* <li>The client is notified that the session id is no longer valid with
* {@link HttpSessionStrategy#onInvalidateSession(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}
@@ -69,12 +68,12 @@ import org.springframework.session.SessionRepository;
* persisted properly.
* </p>
*
* @param <S> the {@link ExpiringSession} type.
* @param <S> the {@link Session} type.
* @since 1.0
* @author Rob Winch
*/
@Order(SessionRepositoryFilter.DEFAULT_ORDER)
public class SessionRepositoryFilter<S extends ExpiringSession>
public class SessionRepositoryFilter<S extends Session>
extends OncePerRequestFilter {
private static final String SESSION_LOGGER_NAME = SessionRepositoryFilter.class
.getName().concat(".SESSION_LOGGER");
@@ -402,7 +401,7 @@ public class SessionRepositoryFilter<S extends ExpiringSession>
* @author Rob Winch
* @since 1.0
*/
private final class HttpSessionWrapper extends ExpiringSessionHttpSession<S> {
private final class HttpSessionWrapper extends HttpSessionAdapter<S> {
HttpSessionWrapper(S session, ServletContext servletContext) {
super(session, servletContext);

View File

@@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.web.socket.handler.WebSocketConnectHandlerDecoratorFactory;
@@ -55,7 +54,7 @@ import org.springframework.web.util.UrlPathHelper;
* {@literal @Configuration}
* {@literal @EnableScheduling}
* {@literal @EnableWebSocketMessageBroker}
* {@literal public class WebSocketConfig<S extends ExpiringSession> extends AbstractSessionWebSocketMessageBrokerConfigurer<S>} {
* {@literal public class WebSocketConfig<S extends Session> extends AbstractSessionWebSocketMessageBrokerConfigurer<S>} {
*
* {@literal @Override}
* protected void configureStompEndpoints(StompEndpointRegistry registry) {
@@ -71,11 +70,11 @@ import org.springframework.web.util.UrlPathHelper;
* }
* </code>
*
* @param <S> the type of ExpiringSession
* @param <S> the type of Session
* @author Rob Winch
* @since 1.0
*/
public abstract class AbstractSessionWebSocketMessageBrokerConfigurer<S extends ExpiringSession>
public abstract class AbstractSessionWebSocketMessageBrokerConfigurer<S extends Session>
extends AbstractWebSocketMessageBrokerConfigurer {
@Autowired

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -31,7 +31,6 @@ import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.messaging.support.ChannelInterceptorAdapter;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.util.Assert;
@@ -41,12 +40,12 @@ import org.springframework.web.socket.server.HandshakeInterceptor;
/**
* <p>
* Acts as a {@link ChannelInterceptor} and a {@link HandshakeInterceptor} to ensure the
* {@link ExpiringSession#getLastAccessedTime()} is up to date.
* {@link Session#getLastAccessedTime()} is up to date.
* </p>
* <ul>
* <li>Associates the {@link Session#getId()} with the WebSocket Session attributes when
* the handshake is performed. This is later used when intercepting messages to ensure the
* {@link ExpiringSession#getLastAccessedTime()} is updated.</li>
* {@link Session#getLastAccessedTime()} is updated.</li>
* <li>Intercepts {@link Message}'s that are have {@link SimpMessageType} that corresponds
* to {@link #setMatchingMessageTypes(Set)} and updates the last accessed time of the
* {@link Session}. If the {@link Session} is expired, the {@link Message} is prevented
@@ -58,11 +57,11 @@ import org.springframework.web.socket.server.HandshakeInterceptor;
* {@link ChannelInterceptor} and a {@link HandshakeInterceptor} .
* </p>
*
* @param <S> the {@link ExpiringSession} type
* @param <S> the {@link Session} type
* @author Rob Winch
* @since 1.0
*/
public final class SessionRepositoryMessageInterceptor<S extends ExpiringSession>
public final class SessionRepositoryMessageInterceptor<S extends Session>
extends ChannelInterceptorAdapter implements HandshakeInterceptor {
private static final String SPRING_SESSION_ID_ATTR_NAME = "SPRING.SESSION.ID";
@@ -88,7 +87,7 @@ public final class SessionRepositoryMessageInterceptor<S extends ExpiringSession
* <p>
* Sets the {@link SimpMessageType} to match on. If the {@link Message} matches, then
* {@link #preSend(Message, MessageChannel)} ensures the {@link Session} is not
* expired and updates the {@link ExpiringSession#getLastAccessedTime()}
* expired and updates the {@link Session#getLastAccessedTime()}
* </p>
*
* <p>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -46,7 +46,7 @@ public class MapSessionRepositoryTests {
@Test
public void createSessionDefaultExpiration() {
ExpiringSession session = this.repository.createSession();
Session session = this.repository.createSession();
assertThat(session).isInstanceOf(MapSession.class);
assertThat(session.getMaxInactiveIntervalInSeconds())
@@ -59,7 +59,7 @@ public class MapSessionRepositoryTests {
+ 10;
this.repository.setDefaultMaxInactiveInterval(expectedMaxInterval);
ExpiringSession session = this.repository.createSession();
Session session = this.repository.createSession();
assertThat(session.getMaxInactiveIntervalInSeconds())
.isEqualTo(expectedMaxInterval);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
@@ -35,7 +35,7 @@ public class MapSessionTests {
@Test(expected = IllegalArgumentException.class)
public void constructorNullSession() {
new MapSession((ExpiringSession) null);
new MapSession((Session) null);
}
/**
@@ -85,7 +85,7 @@ public class MapSessionTests {
assertThat(this.session.isExpired(now)).isTrue();
}
static class CustomSession implements ExpiringSession {
static class CustomSession implements Session {
public long getCreationTime() {
return 0;

View File

@@ -34,8 +34,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockFilterChain;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.CookieSerializer.CookieValue;
import org.springframework.session.web.http.SessionRepositoryFilter;
@@ -65,7 +65,7 @@ public class EnableSpringHttpSessionCustomCookieSerializerTests {
MockFilterChain chain;
@Autowired
SessionRepositoryFilter<? extends ExpiringSession> sessionRepositoryFilter;
SessionRepositoryFilter<? extends Session> sessionRepositoryFilter;
@Autowired
CookieSerializer cookieSerializer;

View File

@@ -29,8 +29,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockFilterChain;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.web.http.MultiHttpSessionStrategy;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.test.context.ContextConfiguration;
@@ -58,7 +58,7 @@ public class EnableSpringHttpSessionCustomMultiHttpSessionStrategyTests {
MockFilterChain chain;
@Autowired
SessionRepositoryFilter<? extends ExpiringSession> sessionRepositoryFilter;
SessionRepositoryFilter<? extends Session> sessionRepositoryFilter;
@Autowired
MultiHttpSessionStrategy strategy;

View File

@@ -47,9 +47,9 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
import org.springframework.session.data.redis.RedisOperationsSessionRepository.PrincipalNameResolver;
import org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession;
import org.springframework.session.events.AbstractSessionEvent;
@@ -130,7 +130,7 @@ public class RedisOperationsSessionRepositoryTests {
@Test
public void createSessionDefaultMaxInactiveInterval() throws Exception {
ExpiringSession session = this.redisRepository.createSession();
Session session = this.redisRepository.createSession();
assertThat(session.getMaxInactiveIntervalInSeconds())
.isEqualTo(new MapSession().getMaxInactiveIntervalInSeconds());
}
@@ -139,7 +139,7 @@ public class RedisOperationsSessionRepositoryTests {
public void createSessionCustomMaxInactiveInterval() throws Exception {
int interval = 1;
this.redisRepository.setDefaultMaxInactiveInterval(interval);
ExpiringSession session = this.redisRepository.createSession();
Session session = this.redisRepository.createSession();
assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(interval);
}

View File

@@ -30,13 +30,12 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.security.core.session.SessionInformation;
import org.springframework.security.core.userdetails.User;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.mock;
@@ -56,19 +55,19 @@ public class SpringSessionBackedSessionRegistryTest {
private static final String USER_NAME = "userName";
private static final User PRINCIPAL = new User(USER_NAME, "password",
Collections.<GrantedAuthority>emptyList());
Collections.emptyList());
private static final Date NOW = new Date();
@Mock
private FindByIndexNameSessionRepository<ExpiringSession> sessionRepository;
private FindByIndexNameSessionRepository<Session> sessionRepository;
@InjectMocks
private SpringSessionBackedSessionRegistry<ExpiringSession> sessionRegistry;
private SpringSessionBackedSessionRegistry<Session> sessionRegistry;
@Test
public void sessionInformationForExistingSession() {
ExpiringSession session = createSession(SESSION_ID, USER_NAME, NOW.getTime());
Session session = createSession(SESSION_ID, USER_NAME, NOW.getTime());
when(this.sessionRepository.getSession(SESSION_ID)).thenReturn(session);
SessionInformation sessionInfo = this.sessionRegistry
@@ -82,7 +81,7 @@ public class SpringSessionBackedSessionRegistryTest {
@Test
public void sessionInformationForExpiredSession() {
ExpiringSession session = createSession(SESSION_ID, USER_NAME, NOW.getTime());
Session session = createSession(SESSION_ID, USER_NAME, NOW.getTime());
session.setAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR,
Boolean.TRUE);
when(this.sessionRepository.getSession(SESSION_ID)).thenReturn(session);
@@ -126,7 +125,7 @@ public class SpringSessionBackedSessionRegistryTest {
@Test
public void expireNow() {
ExpiringSession session = createSession(SESSION_ID, USER_NAME, NOW.getTime());
Session session = createSession(SESSION_ID, USER_NAME, NOW.getTime());
when(this.sessionRepository.getSession(SESSION_ID)).thenReturn(session);
SessionInformation sessionInfo = this.sessionRegistry
@@ -136,16 +135,14 @@ public class SpringSessionBackedSessionRegistryTest {
sessionInfo.expireNow();
assertThat(sessionInfo.isExpired()).isTrue();
ArgumentCaptor<ExpiringSession> captor = ArgumentCaptor
.forClass(ExpiringSession.class);
ArgumentCaptor<Session> captor = ArgumentCaptor.forClass(Session.class);
verify(this.sessionRepository).save(captor.capture());
assertThat(captor.getValue().<Boolean>getAttribute(
SpringSessionBackedSessionInformation.EXPIRED_ATTR))
.isEqualTo(Boolean.TRUE);
}
private ExpiringSession createSession(String sessionId, String userName,
Long lastAccessed) {
private Session createSession(String sessionId, String userName, Long lastAccessed) {
MapSession session = new MapSession(sessionId);
session.setLastAccessedTime(lastAccessed);
Authentication authentication = mock(Authentication.class);
@@ -157,11 +154,11 @@ public class SpringSessionBackedSessionRegistryTest {
}
private void setUpSessions() {
ExpiringSession session1 = createSession(SESSION_ID, USER_NAME, NOW.getTime());
Session session1 = createSession(SESSION_ID, USER_NAME, NOW.getTime());
session1.setAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR,
Boolean.TRUE);
ExpiringSession session2 = createSession(SESSION_ID2, USER_NAME, NOW.getTime());
Map<String, ExpiringSession> sessions = new LinkedHashMap<>();
Session session2 = createSession(SESSION_ID2, USER_NAME, NOW.getTime());
Map<String, Session> sessions = new LinkedHashMap<>();
sessions.put(session1.getId(), session1);
sessions.put(session2.getId(), session2);
when(this.sessionRepository.findByIndexNameAndIndexValue(

View File

@@ -49,7 +49,6 @@ import org.springframework.mock.web.MockFilterChain;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSession;
import org.springframework.session.MapSessionRepository;
import org.springframework.session.Session;
@@ -74,11 +73,11 @@ public class SessionRepositoryFilterTests {
@Mock
private HttpSessionStrategy strategy;
private Map<String, ExpiringSession> sessions;
private Map<String, Session> sessions;
private SessionRepository<ExpiringSession> sessionRepository;
private SessionRepository<Session> sessionRepository;
private SessionRepositoryFilter<ExpiringSession> filter;
private SessionRepositoryFilter<Session> filter;
private MockHttpServletRequest request;
@@ -422,7 +421,7 @@ public class SessionRepositoryFilterTests {
public void doFilterSetsCookieIfChanged() throws Exception {
this.sessionRepository = new MapSessionRepository() {
@Override
public ExpiringSession getSession(String id) {
public Session getSession(String id) {
return createSession();
}
};
@@ -1256,8 +1255,7 @@ public class SessionRepositoryFilterTests {
@SuppressWarnings("unchecked")
public void doFilterRequestSessionNoRequestSessionNoSessionRepositoryInteractions()
throws Exception {
SessionRepository<ExpiringSession> sessionRepository = spy(
new MapSessionRepository());
SessionRepository<Session> sessionRepository = spy(new MapSessionRepository());
this.filter = new SessionRepositoryFilter<>(sessionRepository);
@@ -1284,8 +1282,7 @@ public class SessionRepositoryFilterTests {
@Test
public void doFilterLazySessionCreation() throws Exception {
SessionRepository<ExpiringSession> sessionRepository = spy(
new MapSessionRepository());
SessionRepository<Session> sessionRepository = spy(new MapSessionRepository());
this.filter = new SessionRepositoryFilter<>(sessionRepository);
@@ -1301,10 +1298,9 @@ public class SessionRepositoryFilterTests {
@Test
public void doFilterLazySessionUpdates() throws Exception {
ExpiringSession session = this.sessionRepository.createSession();
Session session = this.sessionRepository.createSession();
this.sessionRepository.save(session);
SessionRepository<ExpiringSession> sessionRepository = spy(
this.sessionRepository);
SessionRepository<Session> sessionRepository = spy(this.sessionRepository);
setSessionCookie(session.getId());
this.filter = new SessionRepositoryFilter<>(sessionRepository);

View File

@@ -38,7 +38,7 @@ import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.session.ExpiringSession;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import static org.assertj.core.api.Assertions.assertThat;
@@ -53,17 +53,17 @@ import static org.mockito.Mockito.verifyZeroInteractions;
@RunWith(MockitoJUnitRunner.class)
public class SessionRepositoryMessageInterceptorTests {
@Mock
SessionRepository<ExpiringSession> sessionRepository;
SessionRepository<Session> sessionRepository;
@Mock
MessageChannel channel;
@Mock
ExpiringSession session;
Session session;
Message<?> createMessage;
SimpMessageHeaderAccessor headers;
SessionRepositoryMessageInterceptor<ExpiringSession> interceptor;
SessionRepositoryMessageInterceptor<Session> interceptor;
@Before
public void setup() {
@@ -202,7 +202,7 @@ public class SessionRepositoryMessageInterceptorTests {
this.interceptor.preSend(createMessage(), this.channel);
verify(this.sessionRepository, times(0)).save(any(ExpiringSession.class));
verify(this.sessionRepository, times(0)).save(any(Session.class));
}
@Test