|
@@ -30,6 +30,7 @@ import org.springframework.security.core.userdetails.User
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService
|
|
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager
|
|
|
import org.springframework.security.web.SecurityFilterChain
|
|
|
+import org.springframework.security.web.webauthn.registration.HttpSessionPublicKeyCredentialCreationOptionsRepository
|
|
|
import org.springframework.test.web.servlet.MockMvc
|
|
|
import org.springframework.test.web.servlet.get
|
|
|
import org.springframework.test.web.servlet.post
|
|
@@ -58,6 +59,16 @@ class WebAuthnDslTests {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ fun `explicit PublicKeyCredentialCreationOptionsRepository`() {
|
|
|
+ this.spring.register(ExplicitPublicKeyCredentialCreationOptionsRepositoryConfig::class.java).autowire()
|
|
|
+
|
|
|
+ this.mockMvc.post("/test1")
|
|
|
+ .andExpect {
|
|
|
+ status { isForbidden() }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
fun `webauthn and formLogin configured with default registration page`() {
|
|
|
spring.register(DefaultWebauthnConfig::class.java).autowire()
|
|
@@ -128,6 +139,33 @@ class WebAuthnDslTests {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Configuration
|
|
|
+ @EnableWebSecurity
|
|
|
+ open class ExplicitPublicKeyCredentialCreationOptionsRepositoryConfig {
|
|
|
+ @Bean
|
|
|
+ open fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
|
|
|
+ http {
|
|
|
+ webAuthn {
|
|
|
+ rpName = "Spring Security Relying Party"
|
|
|
+ rpId = "example.com"
|
|
|
+ allowedOrigins = setOf("https://example.com")
|
|
|
+ creationOptionsRepository = HttpSessionPublicKeyCredentialCreationOptionsRepository()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return http.build()
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ open fun userDetailsService(): UserDetailsService {
|
|
|
+ val userDetails = User.withDefaultPasswordEncoder()
|
|
|
+ .username("rod")
|
|
|
+ .password("password")
|
|
|
+ .roles("USER")
|
|
|
+ .build()
|
|
|
+ return InMemoryUserDetailsManager(userDetails)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Configuration
|
|
|
@EnableWebSecurity
|
|
|
open class WebauthnConfig {
|