Skip to content

Commit 5dc161d

Browse files
Add Partitioned Cookie Support to DefaultCookieSerializer
Closes gh-2787
1 parent 60efefd commit 5dc161d

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2024 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.
@@ -86,6 +86,8 @@ public class DefaultCookieSerializer implements CookieSerializer {
8686

8787
private String sameSite = "Lax";
8888

89+
private boolean partitioned;
90+
8991
/*
9092
* @see
9193
* org.springframework.session.web.http.CookieSerializer#readCookieValues(jakarta.
@@ -153,6 +155,9 @@ public void writeCookieValue(CookieValue cookieValue) {
153155
if (this.sameSite != null) {
154156
sb.append("; SameSite=").append(this.sameSite);
155157
}
158+
if (this.partitioned) {
159+
sb.append("; Partitioned");
160+
}
156161
response.addHeader("Set-Cookie", sb.toString());
157162
}
158163

@@ -444,4 +449,12 @@ public String getRememberMeRequestAttribute() {
444449
return this.rememberMeRequestAttribute;
445450
}
446451

452+
/**
453+
* Allows defining whether the generated cookie carries the Partitioned attribute
454+
* @since 3.4
455+
*/
456+
public void setPartitioned(boolean partitioned) {
457+
this.partitioned = partitioned;
458+
}
459+
447460
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2024 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.
@@ -460,6 +460,13 @@ void writeCookieSetSameSiteNull() {
460460
assertThat(getCookie().getSameSite()).isNull();
461461
}
462462

463+
@Test
464+
void writeCookieWhenPartitionedTrueThenSetPartitionedAttribute() {
465+
this.serializer.setPartitioned(true);
466+
this.serializer.writeCookieValue(cookieValue(this.sessionId));
467+
assertThat(getCookie().isPartitioned()).isTrue();
468+
}
469+
463470
void setCookieName(String cookieName) {
464471
this.cookieName = cookieName;
465472
this.serializer.setCookieName(cookieName);
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
= What's New
1+
= What's New in 3.4
22

3-
- xref:configuration/common.adoc#changing-how-session-ids-are-generated[docs] - https://github.com/spring-projects/spring-session/issues/11[gh-11] - Introduce `SessionIdGenerator` to allow custom session id generation
4-
- xref:configuration/redis.adoc#configuring-redis-session-mapper[docs] - https://github.com/spring-projects/spring-session/issues/2021[gh-2021] - Allow safe deserialization of Redis sessions
3+
- https://github.com/spring-projects/spring-session/issues/2787[gh-2787] - Add Partitioned Cookie Support to `DefaultCookieSerializer`

0 commit comments

Comments
 (0)