Skip to content

Commit 24ffda2

Browse files
committed
Fixes for webauthn tests after JSpecify
Issue spring-projectsgh-17839
1 parent 6a84f96 commit 24ffda2

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

config/src/test/java/org/springframework/security/config/annotation/web/configurers/WebAuthnConfigurerTests.java

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,15 @@ UserDetailsService userDetailsService() {
300300

301301
@Bean
302302
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
303-
return http.formLogin(Customizer.withDefaults()).webAuthn(Customizer.withDefaults()).build();
303+
// @formatter:off
304+
http
305+
.formLogin(Customizer.withDefaults())
306+
.webAuthn((authn) -> authn
307+
.rpId("spring.io")
308+
.rpName("spring")
309+
);
310+
// @formatter:on
311+
return http.build();
304312
}
305313

306314
}
@@ -316,7 +324,14 @@ UserDetailsService userDetailsService() {
316324

317325
@Bean
318326
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
319-
return http.webAuthn(Customizer.withDefaults()).build();
327+
// @formatter:off
328+
http
329+
.webAuthn((authn) -> authn
330+
.rpId("spring.io")
331+
.rpName("spring")
332+
);
333+
// @formatter:on
334+
return http.build();
320335
}
321336

322337
}
@@ -332,9 +347,16 @@ UserDetailsService userDetailsService() {
332347

333348
@Bean
334349
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
335-
return http.formLogin(Customizer.withDefaults())
336-
.webAuthn((webauthn) -> webauthn.disableDefaultRegistrationPage(true))
337-
.build();
350+
// @formatter:off
351+
http
352+
.formLogin(Customizer.withDefaults())
353+
.webAuthn((authn) -> authn
354+
.rpId("spring.io")
355+
.rpName("spring")
356+
.disableDefaultRegistrationPage(true)
357+
);
358+
// @formatter:on
359+
return http.build();
338360
}
339361

340362
}
@@ -350,9 +372,18 @@ UserDetailsService userDetailsService() {
350372

351373
@Bean
352374
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
353-
return http.formLogin((login) -> login.loginPage("/custom-login-page"))
354-
.webAuthn((webauthn) -> webauthn.disableDefaultRegistrationPage(true))
355-
.build();
375+
// @formatter:off
376+
http
377+
.formLogin((login) -> login
378+
.loginPage("/custom-login-page")
379+
)
380+
.webAuthn((authn) -> authn
381+
.rpId("spring.io")
382+
.rpName("spring")
383+
.disableDefaultRegistrationPage(true)
384+
);
385+
// @formatter:on
386+
return http.build();
356387
}
357388

358389
}

config/src/test/kotlin/org/springframework/security/config/annotation/web/WebAuthnDslTests.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
23
* Copyright 2004-present the original author or authors.
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -125,6 +126,8 @@ class WebAuthnDslTests {
125126
http{
126127
formLogin { }
127128
webAuthn {
129+
rpId = "spring.io"
130+
rpName = "spring"
128131
disableDefaultRegistrationPage = true
129132
}
130133
}
@@ -144,7 +147,10 @@ class WebAuthnDslTests {
144147
open fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
145148
http{
146149
formLogin { }
147-
webAuthn { }
150+
webAuthn {
151+
rpId = "spring.io"
152+
rpName = "spring"
153+
}
148154
}
149155
return http.build()
150156
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private ImmutableCredentialRecordBuilder(CredentialRecord other) {
211211
this.label = other.getLabel();
212212
}
213213

214-
public ImmutableCredentialRecordBuilder credentialType(PublicKeyCredentialType credentialType) {
214+
public ImmutableCredentialRecordBuilder credentialType(@Nullable PublicKeyCredentialType credentialType) {
215215
this.credentialType = credentialType;
216216
return this;
217217
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public final class PublicKeyCredential<R extends AuthenticatorResponse> implemen
3838

3939
private final String id;
4040

41-
private final PublicKeyCredentialType type;
41+
private final @Nullable PublicKeyCredentialType type;
4242

4343
private final Bytes rawId;
4444

@@ -48,7 +48,7 @@ public final class PublicKeyCredential<R extends AuthenticatorResponse> implemen
4848

4949
private final @Nullable AuthenticationExtensionsClientOutputs clientExtensionResults;
5050

51-
private PublicKeyCredential(String id, PublicKeyCredentialType type, Bytes rawId, R response,
51+
private PublicKeyCredential(String id, @Nullable PublicKeyCredentialType type, Bytes rawId, R response,
5252
@Nullable AuthenticatorAttachment authenticatorAttachment,
5353
@Nullable AuthenticationExtensionsClientOutputs clientExtensionResults) {
5454
this.id = id;
@@ -77,7 +77,7 @@ public String getId() {
7777
* specifies the credential type represented by this object.
7878
* @return the credential type
7979
*/
80-
public PublicKeyCredentialType getType() {
80+
public @Nullable PublicKeyCredentialType getType() {
8181
return this.type;
8282
}
8383

@@ -228,7 +228,6 @@ public PublicKeyCredentialBuilder clientExtensionResults(
228228
*/
229229
public PublicKeyCredential<R> build() {
230230
Assert.notNull(this.id, "id cannot be null");
231-
Assert.notNull(this.type, "type cannot be null");
232231
Assert.notNull(this.rawId, "rawId cannot be null");
233232
Assert.notNull(this.response, "response cannot be null");
234233
return new PublicKeyCredential(this.id, this.type, this.rawId, this.response, this.authenticatorAttachment,

0 commit comments

Comments
 (0)