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

0 commit comments

Comments
 (0)