@@ -30,6 +30,7 @@ import org.springframework.security.core.userdetails.User
30
30
import org.springframework.security.core.userdetails.UserDetailsService
31
31
import org.springframework.security.provisioning.InMemoryUserDetailsManager
32
32
import org.springframework.security.web.SecurityFilterChain
33
+ import org.springframework.security.web.webauthn.registration.HttpSessionPublicKeyCredentialCreationOptionsRepository
33
34
import org.springframework.test.web.servlet.MockMvc
34
35
import org.springframework.test.web.servlet.get
35
36
import org.springframework.test.web.servlet.post
@@ -58,6 +59,16 @@ class WebAuthnDslTests {
58
59
}
59
60
}
60
61
62
+ @Test
63
+ fun `explicit PublicKeyCredentialCreationOptionsRepository` () {
64
+ this .spring.register(ExplicitPublicKeyCredentialCreationOptionsRepositoryConfig ::class .java).autowire()
65
+
66
+ this .mockMvc.post(" /test1" )
67
+ .andExpect {
68
+ status { isForbidden() }
69
+ }
70
+ }
71
+
61
72
@Test
62
73
fun `webauthn and formLogin configured with default registration page` () {
63
74
spring.register(DefaultWebauthnConfig ::class .java).autowire()
@@ -128,6 +139,33 @@ class WebAuthnDslTests {
128
139
}
129
140
}
130
141
142
+ @Configuration
143
+ @EnableWebSecurity
144
+ open class ExplicitPublicKeyCredentialCreationOptionsRepositoryConfig {
145
+ @Bean
146
+ open fun securityFilterChain (http : HttpSecurity ): SecurityFilterChain {
147
+ http {
148
+ webAuthn {
149
+ rpName = " Spring Security Relying Party"
150
+ rpId = " example.com"
151
+ allowedOrigins = setOf (" https://example.com" )
152
+ creationOptionsRepository = HttpSessionPublicKeyCredentialCreationOptionsRepository ()
153
+ }
154
+ }
155
+ return http.build()
156
+ }
157
+
158
+ @Bean
159
+ open fun userDetailsService (): UserDetailsService {
160
+ val userDetails = User .withDefaultPasswordEncoder()
161
+ .username(" rod" )
162
+ .password(" password" )
163
+ .roles(" USER" )
164
+ .build()
165
+ return InMemoryUserDetailsManager (userDetails)
166
+ }
167
+ }
168
+
131
169
@Configuration
132
170
@EnableWebSecurity
133
171
open class WebauthnConfig {
0 commit comments