Skip to content

Commit 6f379aa

Browse files
committed
Add Serializable to Csrf Components
Issue gh-16276
1 parent ca2c617 commit 6f379aa

14 files changed

+38
-5
lines changed

config/src/test/java/org/springframework/security/SpringSecurityCoreVersionSerializableTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@
134134
import org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException;
135135
import org.springframework.security.web.authentication.session.SessionAuthenticationException;
136136
import org.springframework.security.web.authentication.www.NonceExpiredException;
137+
import org.springframework.security.web.csrf.CsrfException;
138+
import org.springframework.security.web.csrf.DefaultCsrfToken;
139+
import org.springframework.security.web.csrf.InvalidCsrfTokenException;
140+
import org.springframework.security.web.csrf.MissingCsrfTokenException;
137141

138142
import static org.assertj.core.api.Assertions.assertThat;
139143
import static org.assertj.core.api.Assertions.fail;
@@ -344,6 +348,13 @@ class SpringSecurityCoreVersionSerializableTests {
344348
(r) -> new SessionAuthenticationException("message"));
345349
generatorByClassName.put(NonceExpiredException.class,
346350
(r) -> new NonceExpiredException("message", new IOException("fail")));
351+
generatorByClassName.put(CsrfException.class, (r) -> new CsrfException("message"));
352+
generatorByClassName.put(org.springframework.security.web.server.csrf.CsrfException.class, (r) -> new org.springframework.security.web.server.csrf.CsrfException("message"));
353+
generatorByClassName.put(InvalidCsrfTokenException.class, (r) -> new InvalidCsrfTokenException(new DefaultCsrfToken("header", "parameter", "token"), "token"));
354+
generatorByClassName.put(MissingCsrfTokenException.class, (r) -> new MissingCsrfTokenException("token"));
355+
generatorByClassName.put(DefaultCsrfToken.class, (r) -> new DefaultCsrfToken("header", "parameter", "token"));
356+
generatorByClassName.put(org.springframework.security.web.server.csrf.DefaultCsrfToken.class, (r) -> new org.springframework.security.web.server.csrf.DefaultCsrfToken("header", "parameter", "token"));
357+
347358
}
348359

349360
@ParameterizedTest
10.5 KB
Binary file not shown.
172 Bytes
Binary file not shown.
10.6 KB
Binary file not shown.
10.6 KB
Binary file not shown.
10.5 KB
Binary file not shown.
179 Bytes
Binary file not shown.

web/src/main/java/org/springframework/security/web/csrf/CsrfException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.security.web.csrf;
1818

19+
import java.io.Serial;
20+
1921
import org.springframework.security.access.AccessDeniedException;
2022

2123
/**
@@ -24,9 +26,11 @@
2426
* @author Rob Winch
2527
* @since 3.2
2628
*/
27-
@SuppressWarnings("serial")
2829
public class CsrfException extends AccessDeniedException {
2930

31+
@Serial
32+
private static final long serialVersionUID = 7802567627837252670L;
33+
3034
public CsrfException(String message) {
3135
super(message);
3236
}

web/src/main/java/org/springframework/security/web/csrf/CsrfTokenRequestAttributeHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response,
6262
request.setAttribute(csrfAttrName, csrfToken);
6363
}
6464

65+
@SuppressWarnings("serial")
6566
private static final class SupplierCsrfToken implements CsrfToken {
6667

6768
private final Supplier<CsrfToken> csrfTokenSupplier;

web/src/main/java/org/springframework/security/web/csrf/DefaultCsrfToken.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.security.web.csrf;
1818

19+
import java.io.Serial;
20+
1921
import org.springframework.util.Assert;
2022

2123
/**
@@ -24,9 +26,11 @@
2426
* @author Rob Winch
2527
* @since 3.2
2628
*/
27-
@SuppressWarnings("serial")
2829
public final class DefaultCsrfToken implements CsrfToken {
2930

31+
@Serial
32+
private static final long serialVersionUID = 6552658053267913685L;
33+
3034
private final String token;
3135

3236
private final String parameterName;

0 commit comments

Comments
 (0)