Skip to content

Commit 2d3001a

Browse files
committed
Fix SessionRepositoryFilter not retaining original maxInactiveInterval
Closes gh-951
1 parent f2d1bad commit 2d3001a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

spring-session/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -289,9 +289,10 @@ public String changeSessionId() {
289289
setCurrentSession(null);
290290

291291
HttpSessionWrapper newSession = getSession();
292+
int originalMaxInactiveInterval = session.getMaxInactiveInterval();
292293
original.setSession(newSession.getSession());
293294

294-
newSession.setMaxInactiveInterval(session.getMaxInactiveInterval());
295+
newSession.setMaxInactiveInterval(originalMaxInactiveInterval);
295296
for (Map.Entry<String, Object> attr : attrs.entrySet()) {
296297
String attrName = attr.getKey();
297298
Object attrValue = attr.getValue();

spring-session/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -568,6 +568,27 @@ public void doFilter(HttpServletRequest wrappedRequest) {
568568
});
569569
}
570570

571+
// gh-951
572+
@Test
573+
public void doFilterChangeSessionIdCopyAttributes() throws Exception {
574+
// change the session id
575+
doFilter(new DoInFilter() {
576+
@Override
577+
public void doFilter(HttpServletRequest wrappedRequest) {
578+
HttpSession session = wrappedRequest.getSession();
579+
session.setMaxInactiveInterval(300);
580+
String originalSessionId = session.getId();
581+
int originalMaxInactiveInterval = session.getMaxInactiveInterval();
582+
583+
String changeSessionId = ReflectionTestUtils.invokeMethod(wrappedRequest,
584+
"changeSessionId");
585+
assertThat(changeSessionId).isNotEqualTo(originalSessionId);
586+
assertThat(session.getMaxInactiveInterval())
587+
.isEqualTo(originalMaxInactiveInterval);
588+
}
589+
});
590+
}
591+
571592
// gh-142, gh-153
572593
@Test
573594
public void doFilterIsRequestedValidSessionFalseInvalidId() throws Exception {

0 commit comments

Comments
 (0)