Skip to content

Commit fa35c5b

Browse files
franticticktickjzheaux
authored andcommitted
Make DefaultOneTimeToken Serializable
Closes gh-16617 Signed-off-by: Max Batischev <[email protected]>
1 parent 7df85a2 commit fa35c5b

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

Diff for: config/src/test/java/org/springframework/security/SpringSecurityCoreVersionSerializableTests.java

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Locale;
4444
import java.util.Map;
4545
import java.util.Set;
46+
import java.util.UUID;
4647
import java.util.stream.Stream;
4748

4849
import jakarta.servlet.http.Cookie;
@@ -98,6 +99,7 @@
9899
import org.springframework.security.authentication.jaas.JaasAuthenticationToken;
99100
import org.springframework.security.authentication.jaas.event.JaasAuthenticationFailedEvent;
100101
import org.springframework.security.authentication.jaas.event.JaasAuthenticationSuccessEvent;
102+
import org.springframework.security.authentication.ott.DefaultOneTimeToken;
101103
import org.springframework.security.authentication.ott.InvalidOneTimeTokenException;
102104
import org.springframework.security.authentication.ott.OneTimeTokenAuthenticationToken;
103105
import org.springframework.security.authentication.password.CompromisedPasswordException;
@@ -667,6 +669,11 @@ class SpringSecurityCoreVersionSerializableTests {
667669
return webAuthnAuthentication;
668670
});
669671
// @formatter:on
672+
673+
// One-Time Token
674+
DefaultOneTimeToken oneTimeToken = new DefaultOneTimeToken(UUID.randomUUID().toString(), "user",
675+
Instant.now().plusSeconds(300));
676+
generatorByClassName.put(DefaultOneTimeToken.class, (t) -> oneTimeToken);
670677
}
671678

672679
@ParameterizedTest

Diff for: core/src/main/java/org/springframework/security/authentication/ott/DefaultOneTimeToken.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.authentication.ott;
1818

19+
import java.io.Serial;
1920
import java.time.Instant;
2021

2122
import org.springframework.util.Assert;
@@ -28,6 +29,9 @@
2829
*/
2930
public class DefaultOneTimeToken implements OneTimeToken {
3031

32+
@Serial
33+
private static final long serialVersionUID = -1545822943352278549L;
34+
3135
private final String token;
3236

3337
private final String username;

Diff for: core/src/main/java/org/springframework/security/authentication/ott/OneTimeToken.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.authentication.ott;
1818

19+
import java.io.Serializable;
1920
import java.time.Instant;
2021

2122
/**
@@ -24,7 +25,7 @@
2425
* @author Marcus da Coregio
2526
* @since 6.4
2627
*/
27-
public interface OneTimeToken {
28+
public interface OneTimeToken extends Serializable {
2829

2930
/**
3031
* @return the one-time token value, never {@code null}

0 commit comments

Comments
 (0)