Skip to content

Make DefaultOneTimeToken Serializable #16618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;

import jakarta.servlet.http.Cookie;
Expand Down Expand Up @@ -98,6 +99,7 @@
import org.springframework.security.authentication.jaas.JaasAuthenticationToken;
import org.springframework.security.authentication.jaas.event.JaasAuthenticationFailedEvent;
import org.springframework.security.authentication.jaas.event.JaasAuthenticationSuccessEvent;
import org.springframework.security.authentication.ott.DefaultOneTimeToken;
import org.springframework.security.authentication.ott.InvalidOneTimeTokenException;
import org.springframework.security.authentication.ott.OneTimeTokenAuthenticationToken;
import org.springframework.security.authentication.password.CompromisedPasswordException;
Expand Down Expand Up @@ -667,6 +669,11 @@ class SpringSecurityCoreVersionSerializableTests {
return webAuthnAuthentication;
});
// @formatter:on

// One-Time Token
DefaultOneTimeToken oneTimeToken = new DefaultOneTimeToken(UUID.randomUUID().toString(), "user",
Instant.now().plusSeconds(300));
generatorByClassName.put(DefaultOneTimeToken.class, (t) -> oneTimeToken);
}

@ParameterizedTest
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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 All @@ -16,6 +16,7 @@

package org.springframework.security.authentication.ott;

import java.io.Serial;
import java.time.Instant;

import org.springframework.util.Assert;
Expand All @@ -28,6 +29,9 @@
*/
public class DefaultOneTimeToken implements OneTimeToken {

@Serial
private static final long serialVersionUID = -1545822943352278549L;

private final String token;

private final String username;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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 All @@ -16,6 +16,7 @@

package org.springframework.security.authentication.ott;

import java.io.Serializable;
import java.time.Instant;

/**
Expand All @@ -24,7 +25,7 @@
* @author Marcus da Coregio
* @since 6.4
*/
public interface OneTimeToken {
public interface OneTimeToken extends Serializable {

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