Skip to content

Commit decf4de

Browse files
franticticktickrwinch
authored andcommitted
Add Support disableDefaultRegistrationPage to WebAuthnDsl
Closes gh-16395 Signed-off-by: Max Batischev <[email protected]>
1 parent 882766e commit decf4de

File tree

2 files changed

+39
-0
lines changed
  • config/src

2 files changed

+39
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ 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
2930
* @author Max Batischev
@@ -33,12 +34,14 @@ class WebAuthnDsl {
3334
var rpName: String? = null
3435
var rpId: String? = null
3536
var allowedOrigins: Set<String>? = null
37+
var disableDefaultRegistrationPage: Boolean? = false
3638

3739
internal fun get(): (WebAuthnConfigurer<HttpSecurity>) -> Unit {
3840
return { webAuthn ->
3941
rpName?.also { webAuthn.rpName(rpName) }
4042
rpId?.also { webAuthn.rpId(rpId) }
4143
allowedOrigins?.also { webAuthn.allowedOrigins(allowedOrigins) }
44+
disableDefaultRegistrationPage?.also { webAuthn.disableDefaultRegistrationPage(disableDefaultRegistrationPage!!) }
4245
}
4346
}
4447
}

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

+36
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,42 @@ class WebAuthnDslTests {
7474
}
7575
}
7676

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+
77113
@Configuration
78114
@EnableWebSecurity
79115
open class DefaultWebauthnConfig {

0 commit comments

Comments
 (0)