Skip to content

Commit 1b421da

Browse files
Make PublicKeyCredentialRequestOptions Serializable
Closes spring-projectsgh-16432 Signed-off-by: Max Batischev <[email protected]>
1 parent 09b6e4c commit 1b421da

File tree

22 files changed

+119
-20
lines changed

22 files changed

+119
-20
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@
196196
import org.springframework.security.web.firewall.RequestRejectedException;
197197
import org.springframework.security.web.server.firewall.ServerExchangeRejectedException;
198198
import org.springframework.security.web.session.HttpSessionCreatedEvent;
199+
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
200+
import org.springframework.security.web.webauthn.api.AuthenticatorTransport;
201+
import org.springframework.security.web.webauthn.api.Bytes;
202+
import org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput;
203+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInput;
204+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInputs;
205+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialDescriptor;
206+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialRequestOptions;
207+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialType;
208+
import org.springframework.security.web.webauthn.api.TestBytes;
209+
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialRequestOptions;
210+
import org.springframework.security.web.webauthn.api.UserVerificationRequirement;
199211
import org.springframework.util.ReflectionUtils;
200212

201213
import static org.assertj.core.api.Assertions.assertThat;
@@ -515,6 +527,39 @@ class SpringSecurityCoreVersionSerializableTests {
515527
(r) -> new AuthenticationSwitchUserEvent(authentication, user));
516528
generatorByClassName.put(HttpSessionCreatedEvent.class,
517529
(r) -> new HttpSessionCreatedEvent(new MockHttpSession()));
530+
531+
// webauthn
532+
CredProtectAuthenticationExtensionsClientInput.CredProtect credProtect = new CredProtectAuthenticationExtensionsClientInput.CredProtect(
533+
CredProtectAuthenticationExtensionsClientInput.CredProtect.ProtectionPolicy.USER_VERIFICATION_OPTIONAL,
534+
true);
535+
Bytes id = TestBytes.get();
536+
AuthenticationExtensionsClientInputs inputs = new ImmutableAuthenticationExtensionsClientInputs(
537+
ImmutableAuthenticationExtensionsClientInput.credProps);
538+
// @formatter:off
539+
PublicKeyCredentialDescriptor descriptor = PublicKeyCredentialDescriptor.builder()
540+
.id(id)
541+
.type(PublicKeyCredentialType.PUBLIC_KEY)
542+
.transports(Set.of(AuthenticatorTransport.USB))
543+
.build();
544+
// @formatter:on
545+
generatorByClassName.put(AuthenticatorTransport.class, (a) -> AuthenticatorTransport.USB);
546+
generatorByClassName.put(PublicKeyCredentialType.class, (k) -> PublicKeyCredentialType.PUBLIC_KEY);
547+
generatorByClassName.put(UserVerificationRequirement.class, (r) -> UserVerificationRequirement.REQUIRED);
548+
generatorByClassName.put(CredProtectAuthenticationExtensionsClientInput.CredProtect.class, (c) -> credProtect);
549+
generatorByClassName.put(CredProtectAuthenticationExtensionsClientInput.class,
550+
(c) -> new CredProtectAuthenticationExtensionsClientInput(credProtect));
551+
generatorByClassName.put(ImmutableAuthenticationExtensionsClientInputs.class, (i) -> inputs);
552+
generatorByClassName.put(ImmutableAuthenticationExtensionsClientInput.class,
553+
(i) -> ImmutableAuthenticationExtensionsClientInput.credProps);
554+
generatorByClassName.put(Bytes.class, (b) -> id);
555+
generatorByClassName.put(PublicKeyCredentialDescriptor.class, (d) -> descriptor);
556+
// @formatter:off
557+
generatorByClassName.put(PublicKeyCredentialRequestOptions.class, (o) -> TestPublicKeyCredentialRequestOptions.create()
558+
.extensions(inputs)
559+
.allowCredentials(List.of(descriptor))
560+
.build()
561+
);
562+
// @formatter:on
518563
}
519564

520565
@ParameterizedTest

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

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 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

Lines changed: 8 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,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/Bytes.java

Lines changed: 7 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.Serial;
20+
import java.io.Serializable;
1921
import java.security.SecureRandom;
2022
import java.util.Arrays;
2123
import java.util.Base64;
@@ -28,7 +30,10 @@
2830
* @author Rob Winch
2931
* @since 6.4
3032
*/
31-
public final class Bytes {
33+
public final class Bytes implements Serializable {
34+
35+
@Serial
36+
private static final long serialVersionUID = -7420539646106189663L;
3237

3338
private static final SecureRandom RANDOM = new SecureRandom();
3439

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

Lines changed: 11 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,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

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
* 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

Lines changed: 5 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,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

Lines changed: 7 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.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

Lines changed: 7 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.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

Lines changed: 8 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,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

Lines changed: 8 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,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)