Skip to content

Commit 85b854c

Browse files
committed
Merge branch '6.4.x'
- Fix Kotlin DSL webAuthn { } - Add Support disableDefaultRegistrationPage to WebAuthnDsl Closes gh-16403 Closes gh-16404
2 parents cc481a1 + decf4de commit 85b854c

File tree

2 files changed

+83
-6
lines changed
  • config/src

2 files changed

+83
-6
lines changed

config/src/main/kotlin/org/springframework/security/config/annotation/web/WebAuthnDsl.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -24,20 +24,24 @@ import org.springframework.security.config.annotation.web.configurers.WebAuthnCo
2424
* @property rpName the relying party name
2525
* @property rpId the relying party id
2626
* @property the allowed origins
27+
* @property disableDefaultRegistrationPage disable default webauthn registration page
2728
* @since 6.4
2829
* @author Rob Winch
30+
* @author Max Batischev
2931
*/
3032
@SecurityMarker
3133
class WebAuthnDsl {
3234
var rpName: String? = null
3335
var rpId: String? = null
3436
var allowedOrigins: Set<String>? = null
37+
var disableDefaultRegistrationPage: Boolean? = false
3538

3639
internal fun get(): (WebAuthnConfigurer<HttpSecurity>) -> Unit {
37-
return { webAuthn -> webAuthn
38-
.rpId(rpId)
39-
.rpName(rpName)
40-
.allowedOrigins(allowedOrigins);
40+
return { webAuthn ->
41+
rpName?.also { webAuthn.rpName(rpName) }
42+
rpId?.also { webAuthn.rpId(rpId) }
43+
allowedOrigins?.also { webAuthn.allowedOrigins(allowedOrigins) }
44+
disableDefaultRegistrationPage?.also { webAuthn.disableDefaultRegistrationPage(disableDefaultRegistrationPage!!) }
4145
}
4246
}
4347
}

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

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 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.config.annotation.web
1818

19+
import org.hamcrest.Matchers
1920
import org.junit.jupiter.api.Test
2021
import org.junit.jupiter.api.extension.ExtendWith
2122
import org.springframework.beans.factory.annotation.Autowired
@@ -30,7 +31,9 @@ import org.springframework.security.core.userdetails.UserDetailsService
3031
import org.springframework.security.provisioning.InMemoryUserDetailsManager
3132
import org.springframework.security.web.SecurityFilterChain
3233
import org.springframework.test.web.servlet.MockMvc
34+
import org.springframework.test.web.servlet.get
3335
import org.springframework.test.web.servlet.post
36+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
3437

3538
/**
3639
* Tests for [WebAuthnDsl]
@@ -55,6 +58,76 @@ class WebAuthnDslTests {
5558
}
5659
}
5760

61+
@Test
62+
fun `webauthn and formLogin configured with default registration page`() {
63+
spring.register(DefaultWebauthnConfig::class.java).autowire()
64+
65+
this.mockMvc.get("/login/webauthn.js")
66+
.andExpect {
67+
MockMvcResultMatchers.status().isOk
68+
header {
69+
string("content-type", "text/javascript;charset=UTF-8")
70+
}
71+
content {
72+
string(Matchers.containsString("async function authenticate("))
73+
}
74+
}
75+
}
76+
77+
@Test
78+
fun `webauthn and formLogin configured with disabled default registration page`() {
79+
spring.register(FormLoginAndNoDefaultRegistrationPageConfiguration::class.java).autowire()
80+
81+
this.mockMvc.get("/login/webauthn.js")
82+
.andExpect {
83+
MockMvcResultMatchers.status().isOk
84+
header {
85+
string("content-type", "text/javascript;charset=UTF-8")
86+
}
87+
content {
88+
string(Matchers.containsString("async function authenticate("))
89+
}
90+
}
91+
}
92+
93+
@Configuration
94+
@EnableWebSecurity
95+
open class FormLoginAndNoDefaultRegistrationPageConfiguration {
96+
@Bean
97+
open fun userDetailsService(): UserDetailsService =
98+
InMemoryUserDetailsManager()
99+
100+
101+
@Bean
102+
open fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
103+
http{
104+
formLogin { }
105+
webAuthn {
106+
disableDefaultRegistrationPage = true
107+
}
108+
}
109+
return http.build()
110+
}
111+
}
112+
113+
@Configuration
114+
@EnableWebSecurity
115+
open class DefaultWebauthnConfig {
116+
@Bean
117+
open fun userDetailsService(): UserDetailsService =
118+
InMemoryUserDetailsManager()
119+
120+
121+
@Bean
122+
open fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
123+
http{
124+
formLogin { }
125+
webAuthn { }
126+
}
127+
return http.build()
128+
}
129+
}
130+
58131
@Configuration
59132
@EnableWebSecurity
60133
open class WebauthnConfig {

0 commit comments

Comments
 (0)