|
1 | 1 | /* |
2 | | - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
30 | 30 | import java.nio.file.Files; |
31 | 31 | import java.nio.file.Path; |
32 | 32 | import java.nio.file.Paths; |
| 33 | +import java.time.Duration; |
33 | 34 | import java.time.Instant; |
34 | 35 | import java.util.ArrayList; |
35 | 36 | import java.util.Collection; |
|
170 | 171 | import org.springframework.security.web.csrf.MissingCsrfTokenException; |
171 | 172 | import org.springframework.security.web.firewall.RequestRejectedException; |
172 | 173 | import org.springframework.security.web.server.firewall.ServerExchangeRejectedException; |
| 174 | +import org.springframework.security.web.webauthn.api.AuthenticationExtensionsClientInputs; |
| 175 | +import org.springframework.security.web.webauthn.api.AuthenticatorTransport; |
| 176 | +import org.springframework.security.web.webauthn.api.Bytes; |
| 177 | +import org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput; |
| 178 | +import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInput; |
| 179 | +import org.springframework.security.web.webauthn.api.ImmutableAuthenticationExtensionsClientInputs; |
| 180 | +import org.springframework.security.web.webauthn.api.PublicKeyCredentialDescriptor; |
| 181 | +import org.springframework.security.web.webauthn.api.PublicKeyCredentialRequestOptions; |
| 182 | +import org.springframework.security.web.webauthn.api.PublicKeyCredentialType; |
| 183 | +import org.springframework.security.web.webauthn.api.UserVerificationRequirement; |
173 | 184 |
|
174 | 185 | import static org.assertj.core.api.Assertions.assertThat; |
175 | 186 | import static org.assertj.core.api.Assertions.fail; |
| 187 | +import static org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput.*; |
| 188 | +import static org.springframework.security.web.webauthn.api.CredProtectAuthenticationExtensionsClientInput.CredProtect.ProtectionPolicy.*; |
176 | 189 |
|
177 | 190 | /** |
178 | 191 | * Tests that Spring Security classes that implements {@link Serializable} and have the |
@@ -322,6 +335,38 @@ class SpringSecurityCoreVersionSerializableTests { |
322 | 335 | generatorByClassName.put(OAuth2IntrospectionException.class, |
323 | 336 | (r) -> new OAuth2IntrospectionException("message", new RuntimeException())); |
324 | 337 |
|
| 338 | + //webauthn |
| 339 | + CredProtect credProtect = new CredProtect(USER_VERIFICATION_OPTIONAL, true); |
| 340 | + Bytes id = new Bytes(("test").getBytes()); |
| 341 | + AuthenticationExtensionsClientInputs inputs = new ImmutableAuthenticationExtensionsClientInputs(ImmutableAuthenticationExtensionsClientInput.credProps); |
| 342 | + // @formatter:off |
| 343 | + PublicKeyCredentialDescriptor descriptor = PublicKeyCredentialDescriptor.builder() |
| 344 | + .id(id) |
| 345 | + .type(PublicKeyCredentialType.PUBLIC_KEY) |
| 346 | + .transports(Set.of(AuthenticatorTransport.USB)) |
| 347 | + .build(); |
| 348 | + // @formatter:on |
| 349 | + generatorByClassName.put(AuthenticatorTransport.class, (a) -> AuthenticatorTransport.USB); |
| 350 | + generatorByClassName.put(PublicKeyCredentialType.class, (k) -> PublicKeyCredentialType.PUBLIC_KEY); |
| 351 | + generatorByClassName.put(UserVerificationRequirement.class, (r) -> UserVerificationRequirement.REQUIRED); |
| 352 | + generatorByClassName.put(CredProtect.class, (c) -> credProtect); |
| 353 | + generatorByClassName.put(CredProtectAuthenticationExtensionsClientInput.class, (c) -> new CredProtectAuthenticationExtensionsClientInput(credProtect)); |
| 354 | + generatorByClassName.put(ImmutableAuthenticationExtensionsClientInputs.class, (i) -> inputs); |
| 355 | + generatorByClassName.put(ImmutableAuthenticationExtensionsClientInput.class, (i) -> ImmutableAuthenticationExtensionsClientInput.credProps); |
| 356 | + generatorByClassName.put(Bytes.class, (b) -> id); |
| 357 | + generatorByClassName.put(PublicKeyCredentialDescriptor.class, (d) -> descriptor); |
| 358 | + // @formatter:off |
| 359 | + generatorByClassName.put(PublicKeyCredentialRequestOptions.class, (o) -> PublicKeyCredentialRequestOptions.builder() |
| 360 | + .allowCredentials(List.of(descriptor)) |
| 361 | + .rpId("example.localhost") |
| 362 | + .challenge(Bytes.fromBase64("I69THX904Q8ONhCgUgOu2PCQCcEjTDiNmokdbgsAsYU")) |
| 363 | + .userVerification(UserVerificationRequirement.REQUIRED) |
| 364 | + .extensions(inputs) |
| 365 | + .timeout(Duration.ofMinutes(5)) |
| 366 | + .build() |
| 367 | + ); |
| 368 | + // @formatter:on |
| 369 | + |
325 | 370 | // core |
326 | 371 | generatorByClassName.put(RunAsUserToken.class, (r) -> { |
327 | 372 | RunAsUserToken token = new RunAsUserToken("key", user, "creds", user.getAuthorities(), |
|
0 commit comments