Skip to content

Commit 24a3e46

Browse files
Make PublicKeyCredentialRequestOptions Serializable
Closes gh-16432 Signed-off-by: Max Batischev <[email protected]>
1 parent 6f3e2ac commit 24a3e46

19 files changed

+75
-26
lines changed

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

Lines changed: 46 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.
@@ -30,6 +30,7 @@
3030
import java.nio.file.Files;
3131
import java.nio.file.Path;
3232
import java.nio.file.Paths;
33+
import java.time.Duration;
3334
import java.time.Instant;
3435
import java.util.ArrayList;
3536
import java.util.Collection;
@@ -170,9 +171,21 @@
170171
import org.springframework.security.web.csrf.MissingCsrfTokenException;
171172
import org.springframework.security.web.firewall.RequestRejectedException;
172173
import org.springframework.security.web.server.firewall.ServerExchangeRejectedException;
174+
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
175+
import org.springframework.security.web.webauthn.api.AuthenticatorTransport;
176+
import org.springframework.security.web.webauthn.api.Bytes;
177+
import org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput;
178+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInput;
179+
import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInputs;
180+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialDescriptor;
181+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialRequestOptions;
182+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialType;
183+
import org.springframework.security.web.webauthn.api.UserVerificationRequirement;
173184

174185
import static org.assertj.core.api.Assertions.assertThat;
175186
import static org.assertj.core.api.Assertions.fail;
187+
import static org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput.*;
188+
import static org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput.CredProtect.ProtectionPolicy.*;
176189

177190
/**
178191
* Tests that Spring Security classes that implements {@link Serializable} and have the
@@ -322,6 +335,38 @@ class SpringSecurityCoreVersionSerializableTests {
322335
generatorByClassName.put(OAuth2IntrospectionException.class,
323336
(r) -> new OAuth2IntrospectionException("message", new RuntimeException()));
324337

338+
//webauthn
339+
CredProtect credProtect = new CredProtect(USER_VERIFICATION_OPTIONAL, true);
340+
Bytes id = new Bytes(("test").getBytes());
341+
AuthenticationExtensionsClientInputs inputs = new ImmutableAuthenticationExtensionsClientInputs(ImmutableAuthenticationExtensionsClientInput.credProps);
342+
// @formatter:off
343+
PublicKeyCredentialDescriptor descriptor = PublicKeyCredentialDescriptor.builder()
344+
.id(id)
345+
.type(PublicKeyCredentialType.PUBLIC_KEY)
346+
.transports(Set.of(AuthenticatorTransport.USB))
347+
.build();
348+
// @formatter:on
349+
generatorByClassName.put(AuthenticatorTransport.class, (a) -> AuthenticatorTransport.USB);
350+
generatorByClassName.put(PublicKeyCredentialType.class, (k) -> PublicKeyCredentialType.PUBLIC_KEY);
351+
generatorByClassName.put(UserVerificationRequirement.class, (r) -> UserVerificationRequirement.REQUIRED);
352+
generatorByClassName.put(CredProtect.class, (c) -> credProtect);
353+
generatorByClassName.put(CredProtectAuthenticationExtensionsClientInput.class, (c) -> new CredProtectAuthenticationExtensionsClientInput(credProtect));
354+
generatorByClassName.put(ImmutableAuthenticationExtensionsClientInputs.class, (i) -> inputs);
355+
generatorByClassName.put(ImmutableAuthenticationExtensionsClientInput.class, (i) -> ImmutableAuthenticationExtensionsClientInput.credProps);
356+
generatorByClassName.put(Bytes.class, (b) -> id);
357+
generatorByClassName.put(PublicKeyCredentialDescriptor.class, (d) -> descriptor);
358+
// @formatter:off
359+
generatorByClassName.put(PublicKeyCredentialRequestOptions.class, (o) -> PublicKeyCredentialRequestOptions.builder()
360+
.allowCredentials(List.of(descriptor))
361+
.rpId("example.localhost")
362+
.challenge(Bytes.fromBase64("I69THX904Q8ONhCgUgOu2PCQCcEjTDiNmokdbgsAsYU"))
363+
.userVerification(UserVerificationRequirement.REQUIRED)
364+
.extensions(inputs)
365+
.timeout(Duration.ofMinutes(5))
366+
.build()
367+
);
368+
// @formatter:on
369+
325370
// core
326371
generatorByClassName.put(RunAsUserToken.class, (r) -> {
327372
RunAsUserToken token = new RunAsUserToken("key", user, "creds", user.getAuthorities(),

0 commit comments

Comments
 (0)