From 2d3001a24ef2c1970f7c085520d5487bdb68040f Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Mon, 29 Jan 2018 16:45:46 +0100 Subject: [PATCH] Fix `SessionRepositoryFilter` not retaining original `maxInactiveInterval` Closes gh-951 --- .../web/http/SessionRepositoryFilter.java | 5 ++-- .../http/SessionRepositoryFilterTests.java | 23 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/spring-session/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java b/spring-session/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java index 180a9283..eb685b04 100644 --- a/spring-session/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java +++ b/spring-session/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -289,9 +289,10 @@ public class SessionRepositoryFilter setCurrentSession(null); HttpSessionWrapper newSession = getSession(); + int originalMaxInactiveInterval = session.getMaxInactiveInterval(); original.setSession(newSession.getSession()); - newSession.setMaxInactiveInterval(session.getMaxInactiveInterval()); + newSession.setMaxInactiveInterval(originalMaxInactiveInterval); for (Map.Entry attr : attrs.entrySet()) { String attrName = attr.getKey(); Object attrValue = attr.getValue(); diff --git a/spring-session/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java b/spring-session/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java index d105cbf9..ffd9818a 100644 --- a/spring-session/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java +++ b/spring-session/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -568,6 +568,27 @@ public class SessionRepositoryFilterTests { }); } + // gh-951 + @Test + public void doFilterChangeSessionIdCopyAttributes() throws Exception { + // change the session id + doFilter(new DoInFilter() { + @Override + public void doFilter(HttpServletRequest wrappedRequest) { + HttpSession session = wrappedRequest.getSession(); + session.setMaxInactiveInterval(300); + String originalSessionId = session.getId(); + int originalMaxInactiveInterval = session.getMaxInactiveInterval(); + + String changeSessionId = ReflectionTestUtils.invokeMethod(wrappedRequest, + "changeSessionId"); + assertThat(changeSessionId).isNotEqualTo(originalSessionId); + assertThat(session.getMaxInactiveInterval()) + .isEqualTo(originalMaxInactiveInterval); + } + }); + } + // gh-142, gh-153 @Test public void doFilterIsRequestedValidSessionFalseInvalidId() throws Exception {