@@ -39,7 +39,7 @@ public interface SessionRepository<S extends Session> {
|
|||||||
* @param id the {@link org.springframework.session.Session#getId()} to lookup
|
* @param id the {@link org.springframework.session.Session#getId()} to lookup
|
||||||
* @return the {@link Session} by the {@link Session#getId()} or null if no {@link Session} is found.
|
* @return the {@link Session} by the {@link Session#getId()} or null if no {@link Session} is found.
|
||||||
*/
|
*/
|
||||||
Session getSession(String id);
|
S getSession(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the {@link Session} with the given {@link Session#getId()} or does nothing if the {@link Session} is not found.
|
* Deletes the {@link Session} with the given {@link Session#getId()} or does nothing if the {@link Session} is not found.
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class RedisOperationsSessionRepository implements SessionRepository<Redis
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Session getSession(String id) {
|
public RedisSession getSession(String id) {
|
||||||
Map<Object, Object> entries = getOperations(id).entries();
|
Map<Object, Object> entries = getOperations(id).entries();
|
||||||
if(entries.isEmpty()) {
|
if(entries.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -53,12 +53,12 @@ import java.util.Set;
|
|||||||
*
|
*
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
*/
|
*/
|
||||||
public class SessionRepositoryFilter extends OncePerRequestFilter {
|
public class SessionRepositoryFilter<S extends Session> extends OncePerRequestFilter {
|
||||||
private final SessionRepository<Session> sessionRepository;
|
private final SessionRepository<S> sessionRepository;
|
||||||
|
|
||||||
private HttpSessionStrategy httpSessionStrategy = new CookieHttpSessionStrategy();
|
private HttpSessionStrategy httpSessionStrategy = new CookieHttpSessionStrategy();
|
||||||
|
|
||||||
public SessionRepositoryFilter(SessionRepository sessionRepository) {
|
public SessionRepositoryFilter(SessionRepository<S> sessionRepository) {
|
||||||
this.sessionRepository = sessionRepository;
|
this.sessionRepository = sessionRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ public class SessionRepositoryFilter extends OncePerRequestFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class SessionRepositoryResponseWrapper extends OnCommittedResponseWrapper {
|
private final class SessionRepositoryResponseWrapper extends OnCommittedResponseWrapper {
|
||||||
|
|
||||||
private final SessionRepositoryRequestWrapper request;
|
private final SessionRepositoryRequestWrapper request;
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ public class SessionRepositoryFilter extends OncePerRequestFilter {
|
|||||||
httpSessionStrategy.onInvalidateSession(this, response);
|
httpSessionStrategy.onInvalidateSession(this, response);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Session session = wrappedSession.session;
|
S session = wrappedSession.session;
|
||||||
sessionRepository.save(session);
|
sessionRepository.save(session);
|
||||||
httpSessionStrategy.onNewSession(session, this, response);
|
httpSessionStrategy.onNewSession(session, this, response);
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ public class SessionRepositoryFilter extends OncePerRequestFilter {
|
|||||||
}
|
}
|
||||||
String requestedSessionId = getRequestedSessionId();
|
String requestedSessionId = getRequestedSessionId();
|
||||||
if(requestedSessionId != null) {
|
if(requestedSessionId != null) {
|
||||||
Session session = sessionRepository.getSession(requestedSessionId);
|
S session = sessionRepository.getSession(requestedSessionId);
|
||||||
if(session != null) {
|
if(session != null) {
|
||||||
this.requestedValidSession = true;
|
this.requestedValidSession = true;
|
||||||
session.setLastAccessedTime(System.currentTimeMillis());
|
session.setLastAccessedTime(System.currentTimeMillis());
|
||||||
@@ -153,7 +153,7 @@ public class SessionRepositoryFilter extends OncePerRequestFilter {
|
|||||||
if(!create) {
|
if(!create) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Session session = sessionRepository.createSession();
|
S session = sessionRepository.createSession();
|
||||||
currentSession = new HttpSessionWrapper(session, getServletContext());
|
currentSession = new HttpSessionWrapper(session, getServletContext());
|
||||||
return currentSession;
|
return currentSession;
|
||||||
}
|
}
|
||||||
@@ -169,12 +169,12 @@ public class SessionRepositoryFilter extends OncePerRequestFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class HttpSessionWrapper implements HttpSession {
|
private final class HttpSessionWrapper implements HttpSession {
|
||||||
final Session session;
|
final S session;
|
||||||
private final ServletContext servletContext;
|
private final ServletContext servletContext;
|
||||||
private boolean invalidated;
|
private boolean invalidated;
|
||||||
private boolean old;
|
private boolean old;
|
||||||
|
|
||||||
public HttpSessionWrapper(Session session, ServletContext servletContext) {
|
public HttpSessionWrapper(S session, ServletContext servletContext) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.servletContext = servletContext;
|
this.servletContext = servletContext;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user