Skip to content

Commit

Permalink
Add Partitioned Cookie Support to DefaultCookieSerializer
Browse files Browse the repository at this point in the history
Closes gh-2787
  • Loading branch information
marcusdacoregio committed Jun 13, 2024
1 parent 60efefd commit 5dc161d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions spring-session-docs/modules/ROOT/pages/whats-new.adoc
Original file line number Diff line number Diff line change
@@ -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`

0 comments on commit 5dc161d

Please sign in to comment.