Skip to content

Commit 5bc443a

Browse files
committed
Make PublicKeyCredentialRequestOptions Serializable
Closes gh-16438
2 parents e1a42db + a841737 commit 5bc443a

File tree

21 files changed

+110
-19
lines changed

21 files changed

+110
-19
lines changed

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

+43-1
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,21 @@
206206
import org.springframework.security.web.savedrequest.SimpleSavedRequest;
207207
import org.springframework.security.web.server.firewall.ServerExchangeRejectedException;
208208
import org.springframework.security.web.session.HttpSessionCreatedEvent;
209+
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
210+
import org.springframework.security.web.webauthn.api.AuthenticatorTransport;
209211
import org.springframework.security.web.webauthn.api.Bytes;
212+
import org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput;
213+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInput;
214+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInputs;
210215
import org.springframework.security.web.webauthn.api.ImmutablePublicKeyCredentialUserEntity;
216+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialDescriptor;
217+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialRequestOptions;
218+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialType;
211219
import org.springframework.security.web.webauthn.api.PublicKeyCredentialUserEntity;
212220
import org.springframework.security.web.webauthn.api.TestBytes;
221+
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialRequestOptions;
213222
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialUserEntity;
223+
import org.springframework.security.web.webauthn.api.UserVerificationRequirement;
214224
import org.springframework.security.web.webauthn.authentication.WebAuthnAuthentication;
215225
import org.springframework.util.ReflectionUtils;
216226

@@ -554,7 +564,39 @@ class SpringSecurityCoreVersionSerializableTests {
554564
});
555565

556566
// webauthn
557-
generatorByClassName.put(Bytes.class, (r) -> TestBytes.get());
567+
CredProtectAuthenticationExtensionsClientInput.CredProtect credProtect = new CredProtectAuthenticationExtensionsClientInput.CredProtect(
568+
CredProtectAuthenticationExtensionsClientInput.CredProtect.ProtectionPolicy.USER_VERIFICATION_OPTIONAL,
569+
true);
570+
Bytes id = TestBytes.get();
571+
AuthenticationExtensionsClientInputs inputs = new ImmutableAuthenticationExtensionsClientInputs(
572+
ImmutableAuthenticationExtensionsClientInput.credProps);
573+
// @formatter:off
574+
PublicKeyCredentialDescriptor descriptor = PublicKeyCredentialDescriptor.builder()
575+
.id(id)
576+
.type(PublicKeyCredentialType.PUBLIC_KEY)
577+
.transports(Set.of(AuthenticatorTransport.USB))
578+
.build();
579+
// @formatter:on
580+
generatorByClassName.put(AuthenticatorTransport.class, (a) -> AuthenticatorTransport.USB);
581+
generatorByClassName.put(PublicKeyCredentialType.class, (k) -> PublicKeyCredentialType.PUBLIC_KEY);
582+
generatorByClassName.put(UserVerificationRequirement.class, (r) -> UserVerificationRequirement.REQUIRED);
583+
generatorByClassName.put(CredProtectAuthenticationExtensionsClientInput.CredProtect.class, (c) -> credProtect);
584+
generatorByClassName.put(CredProtectAuthenticationExtensionsClientInput.class,
585+
(c) -> new CredProtectAuthenticationExtensionsClientInput(credProtect));
586+
generatorByClassName.put(ImmutableAuthenticationExtensionsClientInputs.class, (i) -> inputs);
587+
Field credPropsField = ReflectionUtils.findField(ImmutableAuthenticationExtensionsClientInput.class,
588+
"credProps");
589+
generatorByClassName.put(credPropsField.getType(),
590+
(i) -> ImmutableAuthenticationExtensionsClientInput.credProps);
591+
generatorByClassName.put(Bytes.class, (b) -> id);
592+
generatorByClassName.put(PublicKeyCredentialDescriptor.class, (d) -> descriptor);
593+
// @formatter:off
594+
generatorByClassName.put(PublicKeyCredentialRequestOptions.class, (o) -> TestPublicKeyCredentialRequestOptions.create()
595+
.extensions(inputs)
596+
.allowCredentials(List.of(descriptor))
597+
.build()
598+
);
599+
// @formatter:on
558600
generatorByClassName.put(ImmutablePublicKeyCredentialUserEntity.class,
559601
(r) -> TestPublicKeyCredentialUserEntity.userEntity().id(TestBytes.get()).build());
560602
generatorByClassName.put(WebAuthnAuthentication.class, (r) -> {

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

+4-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,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-input">client extension
2123
* input</a> entry in the {@link AuthenticationExtensionsClientInputs}.
@@ -25,7 +27,7 @@
2527
* @since 6.4
2628
* @see ImmutableAuthenticationExtensionsClientInput
2729
*/
28-
public interface AuthenticationExtensionsClientInput<T> {
30+
public interface AuthenticationExtensionsClientInput<T> extends Serializable {
2931

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

web/src/main/java/org/springframework/security/web/webauthn/api/AuthenticationExtensionsClientInputs.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.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 PublicKeyCredentialCreationOptions#getExtensions()
3334
*/
34-
public interface AuthenticationExtensionsClientInputs {
35+
public interface AuthenticationExtensionsClientInputs extends Serializable {
3536

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

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

+8-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,9 @@
1616

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

19+
import java.io.Serial;
20+
import java.io.Serializable;
21+
1922
/**
2023
* <a href=
2124
* "https://www.w3.org/TR/webauthn-3/#enumdef-authenticatortransport">AuthenticatorTransport</a>
@@ -25,7 +28,10 @@
2528
* @author Rob Winch
2629
* @since 6.4
2730
*/
28-
public final class AuthenticatorTransport {
31+
public final class AuthenticatorTransport implements Serializable {
32+
33+
@Serial
34+
private static final long serialVersionUID = -5617945441117386982L;
2935

3036
/**
3137
* <a href="https://www.w3.org/TR/webauthn-3/#dom-authenticatortransport-usb">usbc</a>

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

+11-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,9 @@
1616

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

19+
import java.io.Serial;
20+
import java.io.Serializable;
21+
1922
/**
2023
* Implements <a href=
2124
* "https://fidoalliance.org/specs/fido-v2.2-rd-20230321/fido-client-to-authenticator-protocol-v2.2-rd-20230321.html#sctn-credProtect-extension">
@@ -27,6 +30,9 @@
2730
public class CredProtectAuthenticationExtensionsClientInput
2831
implements AuthenticationExtensionsClientInput<CredProtectAuthenticationExtensionsClientInput.CredProtect> {
2932

33+
@Serial
34+
private static final long serialVersionUID = -6418175591005843455L;
35+
3036
private final CredProtect input;
3137

3238
public CredProtectAuthenticationExtensionsClientInput(CredProtect input) {
@@ -43,7 +49,10 @@ public CredProtect getInput() {
4349
return this.input;
4450
}
4551

46-
public static class CredProtect {
52+
public static class CredProtect implements Serializable {
53+
54+
@Serial
55+
private static final long serialVersionUID = 109597301115842688L;
4756

4857
private final ProtectionPolicy credProtectionPolicy;
4958

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

+6-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,8 @@
1616

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

19+
import java.io.Serial;
20+
1921
/**
2022
* An immutable {@link AuthenticationExtensionsClientInput}.
2123
*
@@ -26,6 +28,9 @@
2628
*/
2729
public class ImmutableAuthenticationExtensionsClientInput<T> implements AuthenticationExtensionsClientInput<T> {
2830

31+
@Serial
32+
private static final long serialVersionUID = -1738152485672656808L;
33+
2934
/**
3035
* https://www.w3.org/TR/webauthn-3/#sctn-authenticator-credential-properties-extension
3136
*/

web/src/main/java/org/springframework/security/web/webauthn/api/ImmutableAuthenticationExtensionsClientInputs.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.web.webauthn.api;
1818

19+
import java.io.Serial;
1920
import java.util.Arrays;
2021
import java.util.List;
2122

@@ -27,6 +28,9 @@
2728
*/
2829
public class ImmutableAuthenticationExtensionsClientInputs implements AuthenticationExtensionsClientInputs {
2930

31+
@Serial
32+
private static final long serialVersionUID = 4277817521578485720L;
33+
3034
private final List<AuthenticationExtensionsClientInput> inputs;
3135

3236
public ImmutableAuthenticationExtensionsClientInputs(List<AuthenticationExtensionsClientInput> inputs) {

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

+7-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,8 @@
1616

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

19+
import java.io.Serial;
20+
import java.io.Serializable;
1921
import java.util.Set;
2022

2123
/**
@@ -29,7 +31,10 @@
2931
* @author Rob Winch
3032
* @since 6.4
3133
*/
32-
public final class PublicKeyCredentialDescriptor {
34+
public final class PublicKeyCredentialDescriptor implements Serializable {
35+
36+
@Serial
37+
private static final long serialVersionUID = 8793385059692676240L;
3338

3439
private final PublicKeyCredentialType type;
3540

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

+7-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,8 @@
1616

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

19+
import java.io.Serial;
20+
import java.io.Serializable;
1921
import java.time.Duration;
2022
import java.util.ArrayList;
2123
import java.util.Collections;
@@ -32,7 +34,10 @@
3234
* @author Rob Winch
3335
* @since 6.4
3436
*/
35-
public final class PublicKeyCredentialRequestOptions {
37+
public final class PublicKeyCredentialRequestOptions implements Serializable {
38+
39+
@Serial
40+
private static final long serialVersionUID = -2970057592835694354L;
3641

3742
private final Bytes challenge;
3843

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

+8-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,9 @@
1616

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

19+
import java.io.Serial;
20+
import java.io.Serializable;
21+
1922
/**
2023
* The <a href=
2124
* "https://www.w3.org/TR/webauthn-3/#enum-credentialType">PublicKeyCredentialType</a>
@@ -24,7 +27,10 @@
2427
* @author Rob Winch
2528
* @since 6.4
2629
*/
27-
public final class PublicKeyCredentialType {
30+
public final class PublicKeyCredentialType implements Serializable {
31+
32+
@Serial
33+
private static final long serialVersionUID = 7025333122210061679L;
2834

2935
/**
3036
* The only credential type that currently exists.

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

+8-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,9 @@
1616

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

19+
import java.io.Serial;
20+
import java.io.Serializable;
21+
1922
/**
2023
* <a href=
2124
* "https://www.w3.org/TR/webauthn-3/#enumdef-userverificationrequirement">UserVerificationRequirement</a>
@@ -24,7 +27,10 @@
2427
* @author Rob Winch
2528
* @since 6.4
2629
*/
27-
public final class UserVerificationRequirement {
30+
public final class UserVerificationRequirement implements Serializable {
31+
32+
@Serial
33+
private static final long serialVersionUID = -2801001231345540040L;
2834

2935
/**
3036
* The <a href=

0 commit comments

Comments
 (0)