Add Partitioned Cookie Support to DefaultCookieSerializer

Closes gh-2787
This commit is contained in:
Marcus Hert Da Coregio
2024-06-13 16:29:03 -03:00
parent 60efefd948
commit 5dc161d75d
3 changed files with 24 additions and 5 deletions

View File

@@ -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 class DefaultCookieSerializer implements CookieSerializer {
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 class DefaultCookieSerializer implements CookieSerializer {
return this.rememberMeRequestAttribute;
}
/**
* Allows defining whether the generated cookie carries the Partitioned attribute
* @since 3.4
*/
public void setPartitioned(boolean partitioned) {
this.partitioned = partitioned;
}
}

View File

@@ -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 @@ class DefaultCookieSerializerTests {
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);

View File

@@ -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`