Skip to content

Commit 879b44f

Browse files
franticticktickjzheaux
authored andcommitted
Make PublicKeyCredentialRequestOptions Serializable
Closes gh-16432 Signed-off-by: Max Batischev <mblancer@mail.ru>
1 parent 17ca1de commit 879b44f

File tree

20 files changed

+113
-18
lines changed

20 files changed

+113
-18
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,23 @@
211211
import org.springframework.security.web.savedrequest.SimpleSavedRequest;
212212
import org.springframework.security.web.server.firewall.ServerExchangeRejectedException;
213213
import org.springframework.security.web.session.HttpSessionCreatedEvent;
214+
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
215+
import org.springframework.security.web.webauthn.api.AuthenticatorTransport;
214216
import org.springframework.security.web.webauthn.api.Bytes;
217+
import org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput;
218+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInput;
219+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInputs;
215220
import org.springframework.security.web.webauthn.api.ImmutablePublicKeyCredentialUserEntity;
221+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialDescriptor;
222+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialRequestOptions;
223+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialType;
216224
import org.springframework.security.web.webauthn.api.PublicKeyCredentialUserEntity;
217225
import org.springframework.security.web.webauthn.api.TestBytes;
226+
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialRequestOptions;
218227
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialUserEntity;
228+
import org.springframework.security.web.webauthn.api.UserVerificationRequirement;
219229
import org.springframework.security.web.webauthn.authentication.WebAuthnAuthentication;
230+
import org.springframework.util.ReflectionUtils;
220231

221232
import static org.assertj.core.api.Assertions.assertThat;
222233
import static org.assertj.core.api.Assertions.fail;
@@ -584,6 +595,41 @@ class SpringSecurityCoreVersionSerializableTests {
584595
webAuthnAuthentication.setDetails(details);
585596
return webAuthnAuthentication;
586597
});
598+
599+
// webauthn
600+
CredProtectAuthenticationExtensionsClientInput.CredProtect credProtect = new CredProtectAuthenticationExtensionsClientInput.CredProtect(
601+
CredProtectAuthenticationExtensionsClientInput.CredProtect.ProtectionPolicy.USER_VERIFICATION_OPTIONAL,
602+
true);
603+
Bytes id = TestBytes.get();
604+
AuthenticationExtensionsClientInputs inputs = new ImmutableAuthenticationExtensionsClientInputs(
605+
ImmutableAuthenticationExtensionsClientInput.credProps);
606+
// @formatter:off
607+
PublicKeyCredentialDescriptor descriptor = PublicKeyCredentialDescriptor.builder()
608+
.id(id)
609+
.type(PublicKeyCredentialType.PUBLIC_KEY)
610+
.transports(Set.of(AuthenticatorTransport.USB))
611+
.build();
612+
// @formatter:on
613+
generatorByClassName.put(AuthenticatorTransport.class, (a) -> AuthenticatorTransport.USB);
614+
generatorByClassName.put(PublicKeyCredentialType.class, (k) -> PublicKeyCredentialType.PUBLIC_KEY);
615+
generatorByClassName.put(UserVerificationRequirement.class, (r) -> UserVerificationRequirement.REQUIRED);
616+
generatorByClassName.put(CredProtectAuthenticationExtensionsClientInput.CredProtect.class, (c) -> credProtect);
617+
generatorByClassName.put(CredProtectAuthenticationExtensionsClientInput.class,
618+
(c) -> new CredProtectAuthenticationExtensionsClientInput(credProtect));
619+
generatorByClassName.put(ImmutableAuthenticationExtensionsClientInputs.class, (i) -> inputs);
620+
Field credPropsField = ReflectionUtils.findField(ImmutableAuthenticationExtensionsClientInput.class,
621+
"credProps");
622+
generatorByClassName.put(credPropsField.getType(),
623+
(i) -> ImmutableAuthenticationExtensionsClientInput.credProps);
624+
generatorByClassName.put(Bytes.class, (b) -> id);
625+
generatorByClassName.put(PublicKeyCredentialDescriptor.class, (d) -> descriptor);
626+
// @formatter:off
627+
generatorByClassName.put(PublicKeyCredentialRequestOptions.class, (o) -> TestPublicKeyCredentialRequestOptions.create()
628+
.extensions(inputs)
629+
.allowCredentials(List.of(descriptor))
630+
.build()
631+
);
632+
// @formatter:on
587633
}
588634

589635
@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/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)