Skip to content

Commit e68c63c

Browse files
committed
Refac: gh-16889 - Remove deprecated cookie comment and verison methods
Signed-off-by: M-Faheem-Khan <[email protected]>
1 parent 226e81d commit e68c63c

File tree

11 files changed

+10
-81
lines changed

11 files changed

+10
-81
lines changed

web/src/main/java/org/springframework/security/web/authentication/rememberme/AbstractRememberMeServices.java

-3
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,6 @@ protected void setCookie(String[] tokens, int maxAge, HttpServletRequest request
372372
if (this.cookieDomain != null) {
373373
cookie.setDomain(this.cookieDomain);
374374
}
375-
if (maxAge < 1) {
376-
cookie.setVersion(1);
377-
}
378375
cookie.setSecure((this.useSecureCookie != null) ? this.useSecureCookie : request.isSecure());
379376
cookie.setHttpOnly(true);
380377

web/src/main/java/org/springframework/security/web/firewall/FirewalledResponse.java

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public void addCookie(Cookie cookie) {
6767
validateCrlf(SET_COOKIE_HEADER, cookie.getValue());
6868
validateCrlf(SET_COOKIE_HEADER, cookie.getPath());
6969
validateCrlf(SET_COOKIE_HEADER, cookie.getDomain());
70-
validateCrlf(SET_COOKIE_HEADER, cookie.getComment());
7170
}
7271
super.addCookie(cookie);
7372
}

web/src/main/java/org/springframework/security/web/jackson2/CookieDeserializer.java

-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ public Cookie deserialize(JsonParser jp, DeserializationContext ctxt) throws IOE
4545
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
4646
JsonNode jsonNode = mapper.readTree(jp);
4747
Cookie cookie = new Cookie(readJsonNode(jsonNode, "name").asText(), readJsonNode(jsonNode, "value").asText());
48-
cookie.setComment(readJsonNode(jsonNode, "comment").asText());
4948
cookie.setDomain(readJsonNode(jsonNode, "domain").asText());
5049
cookie.setMaxAge(readJsonNode(jsonNode, "maxAge").asInt(-1));
5150
cookie.setSecure(readJsonNode(jsonNode, "secure").asBoolean());
52-
cookie.setVersion(readJsonNode(jsonNode, "version").asInt());
5351
cookie.setPath(readJsonNode(jsonNode, "path").asText());
5452
JsonNode attributes = readJsonNode(jsonNode, "attributes");
5553
cookie.setHttpOnly(readJsonNode(attributes, "HttpOnly").asBoolean());

web/src/main/java/org/springframework/security/web/jackson2/SavedCookieMixin.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ abstract class SavedCookieMixin {
4444

4545
@JsonCreator
4646
SavedCookieMixin(@JsonProperty("name") String name, @JsonProperty("value") String value,
47-
@JsonProperty("comment") String comment, @JsonProperty("domain") String domain,
48-
@JsonProperty("maxAge") int maxAge, @JsonProperty("path") String path,
49-
@JsonProperty("secure") boolean secure, @JsonProperty("version") int version) {
50-
47+
@JsonProperty("domain") String domain, @JsonProperty("maxAge") int maxAge,
48+
@JsonProperty("path") String path, @JsonProperty("secure") boolean secure) {
5149
}
5250

5351
}

web/src/main/java/org/springframework/security/web/savedrequest/SavedCookie.java

+1-32
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public class SavedCookie implements Serializable {
3535

3636
private final String value;
3737

38-
private final String comment;
39-
4038
private final String domain;
4139

4240
private final int maxAge;
@@ -45,28 +43,13 @@ public class SavedCookie implements Serializable {
4543

4644
private final boolean secure;
4745

48-
private final int version;
49-
50-
/**
51-
* @deprecated use
52-
* {@link org.springframework.security.web.savedrequest.SavedCookie#SavedCookie(String, String, String, int, String, boolean)}
53-
* instead
54-
*/
55-
@Deprecated(forRemoval = true, since = "6.1")
56-
public SavedCookie(String name, String value, String comment, String domain, int maxAge, String path,
57-
boolean secure, int version) {
46+
public SavedCookie(String name, String value, String domain, int maxAge, String path, boolean secure) {
5847
this.name = name;
5948
this.value = value;
60-
this.comment = comment;
6149
this.domain = domain;
6250
this.maxAge = maxAge;
6351
this.path = path;
6452
this.secure = secure;
65-
this.version = version;
66-
}
67-
68-
public SavedCookie(String name, String value, String domain, int maxAge, String path, boolean secure) {
69-
this(name, value, null, domain, maxAge, path, secure, 0);
7053
}
7154

7255
public SavedCookie(Cookie cookie) {
@@ -82,11 +65,6 @@ public String getValue() {
8265
return this.value;
8366
}
8467

85-
@Deprecated(forRemoval = true, since = "6.1")
86-
public String getComment() {
87-
return this.comment;
88-
}
89-
9068
public String getDomain() {
9169
return this.domain;
9270
}
@@ -103,23 +81,14 @@ public boolean isSecure() {
10381
return this.secure;
10482
}
10583

106-
@Deprecated(forRemoval = true, since = "6.1")
107-
public int getVersion() {
108-
return this.version;
109-
}
110-
11184
public Cookie getCookie() {
11285
Cookie cookie = new Cookie(getName(), getValue());
113-
if (getComment() != null) {
114-
cookie.setComment(getComment());
115-
}
11686
if (getDomain() != null) {
11787
cookie.setDomain(getDomain());
11888
}
11989
if (getPath() != null) {
12090
cookie.setPath(getPath());
12191
}
122-
cookie.setVersion(getVersion());
12392
cookie.setMaxAge(getMaxAge());
12493
cookie.setSecure(isSecure());
12594
return cookie;

web/src/test/java/org/springframework/security/web/authentication/rememberme/AbstractRememberMeServicesTests.java

-11
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,6 @@ public void setCookieSetsIsHttpOnlyFlagByDefault() {
362362
assertThat(cookie.isHttpOnly()).isTrue();
363363
}
364364

365-
// SEC-2791
366-
@Test
367-
public void setCookieMaxAge1VersionSet() {
368-
MockRememberMeServices services = new MockRememberMeServices();
369-
MockHttpServletRequest request = new MockHttpServletRequest();
370-
MockHttpServletResponse response = new MockHttpServletResponse();
371-
services.setCookie(new String[] { "value" }, 1, request, response);
372-
Cookie cookie = response.getCookie(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
373-
assertThat(cookie.getVersion()).isZero();
374-
}
375-
376365
@Test
377366
public void setCookieDomainValue() {
378367
MockRememberMeServices services = new MockRememberMeServices();

web/src/test/java/org/springframework/security/web/firewall/FirewalledResponseTests.java

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public void addCookieWhenValidThenDelegateInvoked() {
9393
Cookie cookie = new Cookie("foo", "bar");
9494
cookie.setPath("/foobar");
9595
cookie.setDomain("foobar");
96-
cookie.setComment("foobar");
9796
this.fwResponse.addCookie(cookie);
9897
verify(this.response).addCookie(cookie);
9998
}

web/src/test/java/org/springframework/security/web/jackson2/CookieMixinTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public class CookieMixinTests extends AbstractMixinTests {
3838
" \"name\": \"demo\"," +
3939
" \"value\": \"cookie1\"," +
4040
" \"attributes\":{\"@class\":\"java.util.Collections$EmptyMap\"}," +
41-
" \"comment\": null," +
41+
" \"comment\": null," +
4242
" \"maxAge\": -1," +
4343
" \"path\": null," +
4444
" \"secure\": false," +
45-
" \"version\": 0," +
45+
" \"version\": 0," +
4646
" \"domain\": null" +
4747
"}";
4848
// @formatter:on
@@ -53,11 +53,11 @@ public class CookieMixinTests extends AbstractMixinTests {
5353
" \"name\": \"demo\"," +
5454
" \"value\": \"cookie1\"," +
5555
" \"attributes\":{\"@class\":\"java.util.Collections$UnmodifiableMap\", \"HttpOnly\": \"true\"}," +
56-
" \"comment\": null," +
56+
" \"comment\": null," +
5757
" \"maxAge\": -1," +
5858
" \"path\": null," +
5959
" \"secure\": false," +
60-
" \"version\": 0," +
60+
" \"version\": 0," +
6161
" \"domain\": null" +
6262
"}";
6363
// @formatter:on

web/src/test/java/org/springframework/security/web/jackson2/DefaultSavedRequestMixinTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ public class DefaultSavedRequestMixinTests extends AbstractMixinTests {
4545
+ "\"@class\": \"org.springframework.security.web.savedrequest.SavedCookie\", "
4646
+ "\"name\": \"SESSION\", "
4747
+ "\"value\": \"123456789\", "
48-
+ "\"comment\": null, "
4948
+ "\"maxAge\": -1, "
5049
+ "\"path\": null, "
5150
+ "\"secure\":false, "
52-
+ "\"version\": 0, "
5351
+ "\"domain\": null"
5452
+ "}]]";
5553
// @formatter:on

web/src/test/java/org/springframework/security/web/jackson2/SavedCookieMixinTests.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ public class SavedCookieMixinTests extends AbstractMixinTests {
4242
+ "\"@class\": \"org.springframework.security.web.savedrequest.SavedCookie\", "
4343
+ "\"name\": \"SESSION\", "
4444
+ "\"value\": \"123456789\", "
45-
+ "\"comment\": null, "
45+
+ "\"domain\": null, "
4646
+ "\"maxAge\": -1, "
4747
+ "\"path\": null, "
48-
+ "\"secure\":false, "
49-
+ "\"version\": 0, "
50-
+ "\"domain\": null"
48+
+ "\"secure\":false "
5149
+ "}";
5250
// @formatter:on
5351
// @formatter:off
@@ -90,13 +88,11 @@ public void deserializeSavedCookieWithList() throws IOException {
9088

9189
@Test
9290
public void deserializeSavedCookieJsonTest() throws IOException {
93-
SavedCookie savedCookie = (SavedCookie) this.mapper.readValue(COOKIE_JSON, Object.class);
91+
SavedCookie savedCookie = this.mapper.readValue(COOKIE_JSON, SavedCookie.class);
9492
assertThat(savedCookie).isNotNull();
9593
assertThat(savedCookie.getName()).isEqualTo("SESSION");
9694
assertThat(savedCookie.getValue()).isEqualTo("123456789");
9795
assertThat(savedCookie.isSecure()).isEqualTo(false);
98-
assertThat(savedCookie.getVersion()).isZero();
99-
assertThat(savedCookie.getComment()).isNull();
10096
}
10197

10298
}

web/src/test/java/org/springframework/security/web/savedrequest/SavedCookieTests.java

-14
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ public class SavedCookieTests {
3333
@BeforeEach
3434
public void setUp() {
3535
this.cookie = new Cookie("name", "value");
36-
this.cookie.setComment("comment");
3736
this.cookie.setDomain("domain");
3837
this.cookie.setMaxAge(100);
3938
this.cookie.setPath("path");
4039
this.cookie.setSecure(true);
41-
this.cookie.setVersion(11);
4240
this.savedCookie = new SavedCookie(this.cookie);
4341
}
4442

@@ -52,11 +50,6 @@ public void testGetValue() {
5250
assertThat(this.savedCookie.getValue()).isEqualTo(this.cookie.getValue());
5351
}
5452

55-
@Test
56-
public void testGetComment() {
57-
assertThat(this.savedCookie.getComment()).isEqualTo(this.cookie.getComment());
58-
}
59-
6053
@Test
6154
public void testGetDomain() {
6255
assertThat(this.savedCookie.getDomain()).isEqualTo(this.cookie.getDomain());
@@ -72,22 +65,15 @@ public void testGetPath() {
7265
assertThat(this.savedCookie.getPath()).isEqualTo(this.cookie.getPath());
7366
}
7467

75-
@Test
76-
public void testGetVersion() {
77-
assertThat(this.savedCookie.getVersion()).isEqualTo(this.cookie.getVersion());
78-
}
79-
8068
@Test
8169
public void testGetCookie() {
8270
Cookie other = this.savedCookie.getCookie();
83-
assertThat(other.getComment()).isEqualTo(this.cookie.getComment());
8471
assertThat(other.getDomain()).isEqualTo(this.cookie.getDomain());
8572
assertThat(other.getMaxAge()).isEqualTo(this.cookie.getMaxAge());
8673
assertThat(other.getName()).isEqualTo(this.cookie.getName());
8774
assertThat(other.getPath()).isEqualTo(this.cookie.getPath());
8875
assertThat(other.getSecure()).isEqualTo(this.cookie.getSecure());
8976
assertThat(other.getValue()).isEqualTo(this.cookie.getValue());
90-
assertThat(other.getVersion()).isEqualTo(this.cookie.getVersion());
9177
}
9278

9379
@Test

0 commit comments

Comments
 (0)