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

Lines changed: 43 additions & 1 deletion
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) -> {

0 commit comments

Comments
 (0)