Skip to content

Commit 9468126

Browse files
committed
Make AuthenticatorAttestation Serializable
Issue gh-16481
1 parent b5a4218 commit 9468126

7 files changed

+23
-3
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apereo.cas.client.validation.AssertionImpl;
4747
import org.instancio.Instancio;
4848
import org.instancio.InstancioApi;
49+
import org.instancio.InstancioOfClassApi;
4950
import org.instancio.Select;
5051
import org.instancio.generator.Generator;
5152
import org.junit.jupiter.api.Disabled;
@@ -55,6 +56,7 @@
5556

5657
import org.springframework.beans.factory.config.BeanDefinition;
5758
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
59+
import org.springframework.core.ResolvableType;
5860
import org.springframework.core.type.filter.AssignableTypeFilter;
5961
import org.springframework.mock.web.MockHttpServletRequest;
6062
import org.springframework.mock.web.MockHttpSession;
@@ -214,6 +216,7 @@
214216
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs;
215217
import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientOutputs;
216218
import org.springframework.security.web.webauthn.api.AuthenticatorAssertionResponse;
219+
import org.springframework.security.web.webauthn.api.AuthenticatorAttachment;
217220
import org.springframework.security.web.webauthn.api.AuthenticatorTransport;
218221
import org.springframework.security.web.webauthn.api.Bytes;
219222
import org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput;
@@ -658,6 +661,7 @@ class SpringSecurityCoreVersionSerializableTests {
658661
generatorByClassName.put(RelyingPartyAuthenticationRequest.class, (r) -> authRequest);
659662
generatorByClassName.put(PublicKeyCredential.class, (r) -> credential);
660663
generatorByClassName.put(WebAuthnAuthenticationRequestToken.class, (r) -> requestToken);
664+
generatorByClassName.put(AuthenticatorAttachment.class, (r) -> AuthenticatorAttachment.PLATFORM);
661665
// @formatter:on
662666
}
663667

@@ -768,7 +772,11 @@ static Stream<Class<?>> getClassesToSerialize() throws Exception {
768772
}
769773

770774
private static InstancioApi<?> instancioWithDefaults(Class<?> clazz) {
771-
InstancioApi<?> instancio = Instancio.of(clazz);
775+
InstancioOfClassApi<?> instancio = Instancio.of(clazz);
776+
ResolvableType[] generics = ResolvableType.forClass(clazz).getGenerics();
777+
for (ResolvableType type : generics) {
778+
instancio.withTypeParameters(type.resolve());
779+
}
772780
if (generatorByClassName.containsKey(clazz)) {
773781
instancio.supply(Select.all(clazz), generatorByClassName.get(clazz));
774782
}

web/src/main/java/org/springframework/security/web/webauthn/api/AuthenticatorAttachment.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616

1717
package org.springframework.security.web.webauthn.api;
1818

19+
import java.io.ObjectStreamException;
20+
import java.io.Serial;
21+
import java.io.Serializable;
22+
1923
/**
2024
* The <a href=
2125
* "https://www.w3.org/TR/webauthn-3/#enumdef-authenticatorattachment">AuthenticatorAttachment</a>.
2226
*
2327
* @author Rob Winch
2428
* @since 6.4
2529
*/
26-
public final class AuthenticatorAttachment {
30+
public final class AuthenticatorAttachment implements Serializable {
31+
32+
@Serial
33+
private static final long serialVersionUID = 8446133215195918090L;
2734

2835
/**
2936
* Indicates <a href=
@@ -85,4 +92,9 @@ public static AuthenticatorAttachment[] values() {
8592
return new AuthenticatorAttachment[] { CROSS_PLATFORM, PLATFORM };
8693
}
8794

95+
@Serial
96+
private Object readResolve() throws ObjectStreamException {
97+
return valueOf(this.value);
98+
}
99+
88100
}

web/src/main/java/org/springframework/security/web/webauthn/api/PublicKeyCredential.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class PublicKeyCredential<R extends AuthenticatorResponse> implemen
4040

4141
private final R response;
4242

43-
private final transient AuthenticatorAttachment authenticatorAttachment;
43+
private final AuthenticatorAttachment authenticatorAttachment;
4444

4545
private final AuthenticationExtensionsClientOutputs clientExtensionResults;
4646

0 commit comments

Comments
 (0)