Skip to content

Commit f1b2d03

Browse files
Make WebAuthnAuthenticationRequestToken Serializable
Closes gh-16481 Signed-off-by: Max Batischev <[email protected]>
1 parent 9e1a573 commit f1b2d03

18 files changed

+151
-19
lines changed

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

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,30 @@
212212
import org.springframework.security.web.server.firewall.ServerExchangeRejectedException;
213213
import org.springframework.security.web.session.HttpSessionCreatedEvent;
214214
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
215+
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientOutputs;
216+
import org.springframework.security.web.webauthn.api.AuthenticatorAssertionResponse;
215217
import org.springframework.security.web.webauthn.api.AuthenticatorTransport;
216218
import org.springframework.security.web.webauthn.api.Bytes;
217219
import org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput;
220+
import org.springframework.security.web.webauthn.api.CredentialPropertiesOutput;
218221
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInput;
219222
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInputs;
223+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientOutputs;
220224
import org.springframework.security.web.webauthn.api.ImmutablePublicKeyCredentialUserEntity;
225+
import org.springframework.security.web.webauthn.api.PublicKeyCredential;
221226
import org.springframework.security.web.webauthn.api.PublicKeyCredentialDescriptor;
222227
import org.springframework.security.web.webauthn.api.PublicKeyCredentialRequestOptions;
223228
import org.springframework.security.web.webauthn.api.PublicKeyCredentialType;
224229
import org.springframework.security.web.webauthn.api.PublicKeyCredentialUserEntity;
230+
import org.springframework.security.web.webauthn.api.TestAuthenticationAssertionResponses;
225231
import org.springframework.security.web.webauthn.api.TestBytes;
232+
import org.springframework.security.web.webauthn.api.TestPublicKeyCredential;
226233
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialRequestOptions;
227234
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialUserEntity;
228235
import org.springframework.security.web.webauthn.api.UserVerificationRequirement;
229236
import org.springframework.security.web.webauthn.authentication.WebAuthnAuthentication;
237+
import org.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationRequestToken;
238+
import org.springframework.security.web.webauthn.management.RelyingPartyAuthenticationRequest;
230239
import org.springframework.util.ReflectionUtils;
231240

232241
import static org.assertj.core.api.Assertions.assertThat;
@@ -629,6 +638,26 @@ class SpringSecurityCoreVersionSerializableTests {
629638
.allowCredentials(List.of(descriptor))
630639
.build()
631640
);
641+
642+
CredentialPropertiesOutput credentialOutput = new CredentialPropertiesOutput(false);
643+
AuthenticationExtensionsClientOutputs outputs = new ImmutableAuthenticationExtensionsClientOutputs(credentialOutput);
644+
AuthenticatorAssertionResponse response = TestAuthenticationAssertionResponses.createAuthenticatorAssertionResponse()
645+
.build();
646+
PublicKeyCredential<AuthenticatorAssertionResponse> credential = TestPublicKeyCredential.createPublicKeyCredential(
647+
response, outputs)
648+
.build();
649+
RelyingPartyAuthenticationRequest authRequest = new RelyingPartyAuthenticationRequest(
650+
TestPublicKeyCredentialRequestOptions.create().build(),
651+
credential
652+
);
653+
WebAuthnAuthenticationRequestToken requestToken = new WebAuthnAuthenticationRequestToken(authRequest);
654+
requestToken.setDetails(details);
655+
generatorByClassName.put(CredentialPropertiesOutput.class, (o) -> credentialOutput);
656+
generatorByClassName.put(ImmutableAuthenticationExtensionsClientOutputs.class, (o) -> outputs);
657+
generatorByClassName.put(AuthenticatorAssertionResponse.class, (r) -> response);
658+
generatorByClassName.put(RelyingPartyAuthenticationRequest.class, (r) -> authRequest);
659+
generatorByClassName.put(PublicKeyCredential.class, (r) -> credential);
660+
generatorByClassName.put(WebAuthnAuthenticationRequestToken.class, (r) -> requestToken);
632661
// @formatter:on
633662
}
634663

@@ -643,8 +672,15 @@ void serializeCurrentVersionClasses(Class<?> clazz) throws Exception {
643672
return;
644673
}
645674
Files.createFile(filePath);
646-
Object instance = instancioWithDefaults(clazz).create();
647-
assertThat(instance).isInstanceOf(clazz);
675+
Object instance;
676+
if (clazz.equals(PublicKeyCredential.class)) {
677+
instance = instancioWithParameter((Class<PublicKeyCredential>) clazz).create();
678+
}
679+
else {
680+
instance = instancioWithDefaults(clazz).create();
681+
}
682+
// Object instance = instancioWithDefaults(clazz).create();
683+
// assertThat(instance).isInstanceOf(clazz);
648684
try (FileOutputStream fileOutputStream = new FileOutputStream(file);
649685
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream)) {
650686
objectOutputStream.writeObject(instance);
@@ -656,6 +692,14 @@ void serializeCurrentVersionClasses(Class<?> clazz) throws Exception {
656692
}
657693
}
658694

695+
private static InstancioApi<?> instancioWithParameter(Class<PublicKeyCredential> clazz) {
696+
InstancioApi<?> instancio = Instancio.of(clazz).withTypeParameters(AuthenticatorAssertionResponse.class);
697+
if (generatorByClassName.containsKey(clazz)) {
698+
instancio.supply(Select.all(clazz), generatorByClassName.get(clazz));
699+
}
700+
return instancio;
701+
}
702+
659703
@ParameterizedTest
660704
@MethodSource("getFilesToDeserialize")
661705
void shouldBeAbleToDeserializeClassFromPreviousVersion(Path filePath) {
782 Bytes
Binary file not shown.
306 Bytes
Binary file not shown.
619 Bytes
Binary file not shown.
2.03 KB
Binary file not shown.
3.8 KB
Binary file not shown.
3.12 KB
Binary file not shown.

web/src/main/java/org/springframework/security/web/webauthn/api/AuthenticationExtensionsClientOutput.java

Lines changed: 4 additions & 2 deletions
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,8 @@
1616

1717
package org.springframework.security.web.webauthn.api;
1818

19+
import java.io.Serializable;
20+
1921
/**
2022
* A <a href="https://www.w3.org/TR/webauthn-3/#client-extension-output">client extension
2123
* output</a> entry in {@link AuthenticationExtensionsClientOutputs}.
@@ -24,7 +26,7 @@
2426
* @see AuthenticationExtensionsClientOutputs#getOutputs()
2527
* @see CredentialPropertiesOutput
2628
*/
27-
public interface AuthenticationExtensionsClientOutput<T> {
29+
public interface AuthenticationExtensionsClientOutput<T> extends Serializable {
2830

2931
/**
3032
* Gets the <a href="https://www.w3.org/TR/webauthn-3/#extension-identifier">extension

web/src/main/java/org/springframework/security/web/webauthn/api/AuthenticationExtensionsClientOutputs.java

Lines changed: 3 additions & 2 deletions
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.web.webauthn.api;
1818

19+
import java.io.Serializable;
1920
import java.util.List;
2021

2122
/**
@@ -31,7 +32,7 @@
3132
* @since 6.4
3233
* @see PublicKeyCredential#getClientExtensionResults()
3334
*/
34-
public interface AuthenticationExtensionsClientOutputs {
35+
public interface AuthenticationExtensionsClientOutputs extends Serializable {
3536

3637
/**
3738
* Gets all of the {@link AuthenticationExtensionsClientOutput}.

web/src/main/java/org/springframework/security/web/webauthn/api/AuthenticatorAssertionResponse.java

Lines changed: 6 additions & 1 deletion
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,8 @@
1616

1717
package org.springframework.security.web.webauthn.api;
1818

19+
import java.io.Serial;
20+
1921
/**
2022
* The <a href=
2123
* "https://www.w3.org/TR/webauthn-3/#authenticatorassertionresponse">AuthenticatorAssertionResponse</a>
@@ -38,6 +40,9 @@
3840
*/
3941
public final class AuthenticatorAssertionResponse extends AuthenticatorResponse {
4042

43+
@Serial
44+
private static final long serialVersionUID = 324976481675434298L;
45+
4146
private final Bytes authenticatorData;
4247

4348
private final Bytes signature;

0 commit comments

Comments
 (0)