Skip to content

Commit e557c72

Browse files
ngocnhan-tran1996rwinch
authored andcommitted
Implement Serializable for WebAuthnAuthentication
Closes gh-16273 Closes gh-16285 Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
1 parent 751b558 commit e557c72

8 files changed

+42
-6
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@
191191
import org.springframework.security.web.firewall.RequestRejectedException;
192192
import org.springframework.security.web.server.firewall.ServerExchangeRejectedException;
193193
import org.springframework.security.web.session.HttpSessionCreatedEvent;
194+
import org.springframework.security.web.webauthn.api.Bytes;
195+
import org.springframework.security.web.webauthn.api.ImmutablePublicKeyCredentialUserEntity;
196+
import org.springframework.security.web.webauthn.api.PublicKeyCredentialUserEntity;
197+
import org.springframework.security.web.webauthn.api.TestBytes;
198+
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialUserEntity;
199+
import org.springframework.security.web.webauthn.authentication.WebAuthnAuthentication;
194200

195201
import static org.assertj.core.api.Assertions.assertThat;
196202
import static org.assertj.core.api.Assertions.fail;
@@ -508,6 +514,20 @@ class SpringSecurityCoreVersionSerializableTests {
508514
(r) -> new AuthenticationSwitchUserEvent(authentication, user));
509515
generatorByClassName.put(HttpSessionCreatedEvent.class,
510516
(r) -> new HttpSessionCreatedEvent(new MockHttpSession()));
517+
518+
// webauthn
519+
generatorByClassName.put(Bytes.class, (r) -> TestBytes.get());
520+
generatorByClassName.put(ImmutablePublicKeyCredentialUserEntity.class,
521+
(r) -> TestPublicKeyCredentialUserEntity.userEntity().id(TestBytes.get()).build());
522+
generatorByClassName.put(WebAuthnAuthentication.class, (r) -> {
523+
PublicKeyCredentialUserEntity userEntity = TestPublicKeyCredentialUserEntity.userEntity()
524+
.id(TestBytes.get())
525+
.build();
526+
List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER");
527+
WebAuthnAuthentication webAuthnAuthentication = new WebAuthnAuthentication(userEntity, authorities);
528+
webAuthnAuthentication.setDetails(details);
529+
return webAuthnAuthentication;
530+
});
511531
}
512532

513533
@ParameterizedTest

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

+7-2
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.
@@ -16,6 +16,8 @@
1616

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

19+
import java.io.Serial;
20+
import java.io.Serializable;
1921
import java.security.SecureRandom;
2022
import java.util.Arrays;
2123
import java.util.Base64;
@@ -28,7 +30,10 @@
2830
* @author Rob Winch
2931
* @since 6.4
3032
*/
31-
public final class Bytes {
33+
public final class Bytes implements Serializable {
34+
35+
@Serial
36+
private static final long serialVersionUID = -3278138671365709777L;
3237

3338
private static final SecureRandom RANDOM = new SecureRandom();
3439

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

+6-1
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.
@@ -16,6 +16,8 @@
1616

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

19+
import java.io.Serial;
20+
1921
/**
2022
* <a href=
2123
* "https://www.w3.org/TR/webauthn-3/#dictdef-publickeycredentialuserentity">PublicKeyCredentialUserEntity</a>
@@ -28,6 +30,9 @@
2830
*/
2931
public final class ImmutablePublicKeyCredentialUserEntity implements PublicKeyCredentialUserEntity {
3032

33+
@Serial
34+
private static final long serialVersionUID = -3438693960347279759L;
35+
3136
/**
3237
* When inherited by PublicKeyCredentialUserEntity, it is a human-palatable identifier
3338
* for a user account. It is intended only for display, i.e., aiding the user in

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

+4-2
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.
@@ -16,6 +16,8 @@
1616

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

19+
import java.io.Serializable;
20+
1921
/**
2022
* <a href=
2123
* "https://www.w3.org/TR/webauthn-3/#dictdef-publickeycredentialuserentity">PublicKeyCredentialUserEntity</a>
@@ -27,7 +29,7 @@
2729
* @since 6.4
2830
* @see org.springframework.security.web.webauthn.management.WebAuthnRelyingPartyOperations#authenticate(org.springframework.security.web.webauthn.management.RelyingPartyAuthenticationRequest)
2931
*/
30-
public interface PublicKeyCredentialUserEntity {
32+
public interface PublicKeyCredentialUserEntity extends Serializable {
3133

3234
/**
3335
* The <a href=

web/src/main/java/org/springframework/security/web/webauthn/authentication/WebAuthnAuthentication.java

+5-1
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.
@@ -16,6 +16,7 @@
1616

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

19+
import java.io.Serial;
1920
import java.util.Collection;
2021

2122
import org.springframework.security.authentication.AbstractAuthenticationToken;
@@ -33,6 +34,9 @@
3334
*/
3435
public class WebAuthnAuthentication extends AbstractAuthenticationToken {
3536

37+
@Serial
38+
private static final long serialVersionUID = -4879907158750659197L;
39+
3640
private final PublicKeyCredentialUserEntity principal;
3741

3842
public WebAuthnAuthentication(PublicKeyCredentialUserEntity principal,

0 commit comments

Comments
 (0)