Make AuthenticatorAttestation Serializable

Issue gh-16481
This commit is contained in:
Josh Cummings 2025-02-14 12:59:59 -07:00
parent b5a4218a0b
commit 946812691e
No known key found for this signature in database
GPG Key ID: 869B37A20E876129
7 changed files with 23 additions and 3 deletions

View File

@ -46,6 +46,7 @@ import jakarta.servlet.http.Cookie;
import org.apereo.cas.client.validation.AssertionImpl; import org.apereo.cas.client.validation.AssertionImpl;
import org.instancio.Instancio; import org.instancio.Instancio;
import org.instancio.InstancioApi; import org.instancio.InstancioApi;
import org.instancio.InstancioOfClassApi;
import org.instancio.Select; import org.instancio.Select;
import org.instancio.generator.Generator; import org.instancio.generator.Generator;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
@ -55,6 +56,7 @@ import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.ResolvableType;
import org.springframework.core.type.filter.AssignableTypeFilter; import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockHttpSession;
@ -214,6 +216,7 @@ import org.springframework.security.web.session.HttpSessionCreatedEvent;
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs; import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientOutputs; import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientOutputs;
import org.springframework.security.web.webauthn.api.AuthenticatorAssertionResponse; import org.springframework.security.web.webauthn.api.AuthenticatorAssertionResponse;
import org.springframework.security.web.webauthn.api.AuthenticatorAttachment;
import org.springframework.security.web.webauthn.api.AuthenticatorTransport; import org.springframework.security.web.webauthn.api.AuthenticatorTransport;
import org.springframework.security.web.webauthn.api.Bytes; import org.springframework.security.web.webauthn.api.Bytes;
import org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput; import org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput;
@ -658,6 +661,7 @@ class SpringSecurityCoreVersionSerializableTests {
generatorByClassName.put(RelyingPartyAuthenticationRequest.class, (r) -> authRequest); generatorByClassName.put(RelyingPartyAuthenticationRequest.class, (r) -> authRequest);
generatorByClassName.put(PublicKeyCredential.class, (r) -> credential); generatorByClassName.put(PublicKeyCredential.class, (r) -> credential);
generatorByClassName.put(WebAuthnAuthenticationRequestToken.class, (r) -> requestToken); generatorByClassName.put(WebAuthnAuthenticationRequestToken.class, (r) -> requestToken);
generatorByClassName.put(AuthenticatorAttachment.class, (r) -> AuthenticatorAttachment.PLATFORM);
// @formatter:on // @formatter:on
} }
@ -768,7 +772,11 @@ class SpringSecurityCoreVersionSerializableTests {
} }
private static InstancioApi<?> instancioWithDefaults(Class<?> clazz) { private static InstancioApi<?> instancioWithDefaults(Class<?> clazz) {
InstancioApi<?> instancio = Instancio.of(clazz); InstancioOfClassApi<?> instancio = Instancio.of(clazz);
ResolvableType[] generics = ResolvableType.forClass(clazz).getGenerics();
for (ResolvableType type : generics) {
instancio.withTypeParameters(type.resolve());
}
if (generatorByClassName.containsKey(clazz)) { if (generatorByClassName.containsKey(clazz)) {
instancio.supply(Select.all(clazz), generatorByClassName.get(clazz)); instancio.supply(Select.all(clazz), generatorByClassName.get(clazz));
} }

View File

@ -16,6 +16,10 @@
package org.springframework.security.web.webauthn.api; package org.springframework.security.web.webauthn.api;
import java.io.ObjectStreamException;
import java.io.Serial;
import java.io.Serializable;
/** /**
* The <a href= * The <a href=
* "https://www.w3.org/TR/webauthn-3/#enumdef-authenticatorattachment">AuthenticatorAttachment</a>. * "https://www.w3.org/TR/webauthn-3/#enumdef-authenticatorattachment">AuthenticatorAttachment</a>.
@ -23,7 +27,10 @@ package org.springframework.security.web.webauthn.api;
* @author Rob Winch * @author Rob Winch
* @since 6.4 * @since 6.4
*/ */
public final class AuthenticatorAttachment { public final class AuthenticatorAttachment implements Serializable {
@Serial
private static final long serialVersionUID = 8446133215195918090L;
/** /**
* Indicates <a href= * Indicates <a href=
@ -85,4 +92,9 @@ public final class AuthenticatorAttachment {
return new AuthenticatorAttachment[] { CROSS_PLATFORM, PLATFORM }; return new AuthenticatorAttachment[] { CROSS_PLATFORM, PLATFORM };
} }
@Serial
private Object readResolve() throws ObjectStreamException {
return valueOf(this.value);
}
} }

View File

@ -40,7 +40,7 @@ public final class PublicKeyCredential<R extends AuthenticatorResponse> implemen
private final R response; private final R response;
private final transient AuthenticatorAttachment authenticatorAttachment; private final AuthenticatorAttachment authenticatorAttachment;
private final AuthenticationExtensionsClientOutputs clientExtensionResults; private final AuthenticationExtensionsClientOutputs clientExtensionResults;