Invoke HttpSessionStrategy.onNewSession if session id changed

Fixes gh-154
This commit is contained in:
Dave Syer
2015-02-19 16:07:57 -06:00
committed by Rob Winch
parent ae03fac468
commit 29ad238307
2 changed files with 33 additions and 1 deletions

View File

@@ -170,7 +170,7 @@ public class SessionRepositoryFilter<S extends ExpiringSession> extends OncePerR
} else {
S session = wrappedSession.session;
sessionRepository.save(session);
if(!requestedValidSession) {
if(!requestedValidSession || !session.getId().equals(getRequestedSessionId())) {
httpSessionStrategy.onNewSession(session, this, response);
}
}

View File

@@ -323,6 +323,38 @@ public class SessionRepositoryFilterTests<S extends ExpiringSession> {
assertThat(wrappedRequest.getSession().isNew()).isFalse();
}
});
assertThat(response.getCookie("SESSION")).isNull();
}
@Test
public void doFilterSetsCookieIfChanged() throws Exception {
sessionRepository = new MapSessionRepository() {
@Override
public ExpiringSession getSession(String id) {
return createSession();
}
};
filter = new SessionRepositoryFilter<ExpiringSession>(sessionRepository);
doFilter(new DoInFilter() {
@Override
public void doFilter(HttpServletRequest wrappedRequest) {
wrappedRequest.getSession();
}
});
assertThat(response.getCookie("SESSION")).isNotNull();
setupSession();
response.reset();
doFilter(new DoInFilter() {
@Override
public void doFilter(HttpServletRequest wrappedRequest) {
assertThat(wrappedRequest.getSession().isNew()).isFalse();
}
});
assertThat(response.getCookie("SESSION")).isNotNull();
}
@Test