Skip to content

Commit 13c3c57

Browse files
committed
SPR-5835 - CookieGenerator default max age value leads to expiration date back in 1977
1 parent 42590de commit 13c3c57

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

org.springframework.web/src/main/java/org/springframework/web/util/CookieGenerator.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2009 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.
@@ -44,11 +44,6 @@ public class CookieGenerator {
4444
*/
4545
public static final String DEFAULT_COOKIE_PATH = "/";
4646

47-
/**
48-
* Default maximum age of cookies: maximum integer value, i.e. forever.
49-
*/
50-
public static final int DEFAULT_COOKIE_MAX_AGE = Integer.MAX_VALUE;
51-
5247

5348
protected final Log logger = LogFactory.getLog(getClass());
5449

@@ -58,7 +53,7 @@ public class CookieGenerator {
5853

5954
private String cookiePath = DEFAULT_COOKIE_PATH;
6055

61-
private int cookieMaxAge = DEFAULT_COOKIE_MAX_AGE;
56+
private Integer cookieMaxAge = null;
6257

6358
private boolean cookieSecure = false;
6459

@@ -118,7 +113,7 @@ public void setCookieMaxAge(int cookieMaxAge) {
118113
/**
119114
* Return the maximum age for cookies created by this generator.
120115
*/
121-
public int getCookieMaxAge() {
116+
public Integer getCookieMaxAge() {
122117
return cookieMaxAge;
123118
}
124119

@@ -154,7 +149,10 @@ public boolean isCookieSecure() {
154149
*/
155150
public void addCookie(HttpServletResponse response, String cookieValue) {
156151
Cookie cookie = createCookie(cookieValue);
157-
cookie.setMaxAge(getCookieMaxAge());
152+
Integer maxAge = getCookieMaxAge();
153+
if (maxAge != null) {
154+
cookie.setMaxAge(maxAge);
155+
}
158156
if (isCookieSecure()) {
159157
cookie.setSecure(true);
160158
}

0 commit comments

Comments
 (0)