Skip to content

Commit 2cbf02a

Browse files
Make DefaultOneTimeToken Serializable
Closes gh-16617 Signed-off-by: Max Batischev <[email protected]>
1 parent d2f825b commit 2cbf02a

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
@@ -39,6 +39,7 @@
3939
import java.util.Locale;
4040
import java.util.Map;
4141
import java.util.Set;
42+
import java.util.UUID;
4243
import java.util.stream.Collectors;
4344
import java.util.stream.Stream;
4445

@@ -94,6 +95,7 @@
9495
import org.springframework.security.authentication.jaas.JaasAuthenticationToken;
9596
import org.springframework.security.authentication.jaas.event.JaasAuthenticationFailedEvent;
9697
import org.springframework.security.authentication.jaas.event.JaasAuthenticationSuccessEvent;
98+
import org.springframework.security.authentication.ott.DefaultOneTimeToken;
9799
import org.springframework.security.authentication.ott.InvalidOneTimeTokenException;
98100
import org.springframework.security.authentication.ott.OneTimeTokenAuthenticationToken;
99101
import org.springframework.security.authentication.password.CompromisedPasswordException;
@@ -663,6 +665,11 @@ class SpringSecurityCoreVersionSerializableTests {
663665
generatorByClassName.put(WebAuthnAuthenticationRequestToken.class, (r) -> requestToken);
664666
generatorByClassName.put(AuthenticatorAttachment.class, (r) -> AuthenticatorAttachment.PLATFORM);
665667
// @formatter:on
668+
669+
// One-Time Token
670+
DefaultOneTimeToken oneTimeToken = new DefaultOneTimeToken(UUID.randomUUID().toString(), "user",
671+
Instant.now().plusSeconds(300));
672+
generatorByClassName.put(DefaultOneTimeToken.class, (t) -> oneTimeToken);
666673
}
667674

668675
@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)