diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java b/spring-session-core/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java index 7b350ac38..d357993bf 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2024 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. @@ -86,6 +86,8 @@ public class DefaultCookieSerializer implements CookieSerializer { private String sameSite = "Lax"; + private boolean partitioned; + /* * @see * org.springframework.session.web.http.CookieSerializer#readCookieValues(jakarta. @@ -153,6 +155,9 @@ public void writeCookieValue(CookieValue cookieValue) { if (this.sameSite != null) { sb.append("; SameSite=").append(this.sameSite); } + if (this.partitioned) { + sb.append("; Partitioned"); + } response.addHeader("Set-Cookie", sb.toString()); } @@ -444,4 +449,12 @@ public String getRememberMeRequestAttribute() { return this.rememberMeRequestAttribute; } + /** + * Allows defining whether the generated cookie carries the Partitioned attribute + * @since 3.4 + */ + public void setPartitioned(boolean partitioned) { + this.partitioned = partitioned; + } + } diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/DefaultCookieSerializerTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/DefaultCookieSerializerTests.java index 358b884c1..890fe53f8 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/http/DefaultCookieSerializerTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/http/DefaultCookieSerializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2024 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. @@ -460,6 +460,13 @@ void writeCookieSetSameSiteNull() { assertThat(getCookie().getSameSite()).isNull(); } + @Test + void writeCookieWhenPartitionedTrueThenSetPartitionedAttribute() { + this.serializer.setPartitioned(true); + this.serializer.writeCookieValue(cookieValue(this.sessionId)); + assertThat(getCookie().isPartitioned()).isTrue(); + } + void setCookieName(String cookieName) { this.cookieName = cookieName; this.serializer.setCookieName(cookieName); diff --git a/spring-session-docs/modules/ROOT/pages/whats-new.adoc b/spring-session-docs/modules/ROOT/pages/whats-new.adoc index ea07f330e..5fd76654f 100644 --- a/spring-session-docs/modules/ROOT/pages/whats-new.adoc +++ b/spring-session-docs/modules/ROOT/pages/whats-new.adoc @@ -1,4 +1,3 @@ -= What's New += What's New in 3.4 -- 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 -- 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 +- https://github.com/spring-projects/spring-session/issues/2787[gh-2787] - Add Partitioned Cookie Support to `DefaultCookieSerializer`