|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -33,6 +33,7 @@ import org.springframework.security.config.test.SpringTestContextExtension
|
33 | 33 | import org.springframework.security.core.userdetails.User
|
34 | 34 | import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin
|
35 | 35 | import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf
|
| 36 | +import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated |
36 | 37 | import org.springframework.security.web.SecurityFilterChain
|
37 | 38 | import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler
|
38 | 39 | import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler
|
@@ -367,6 +368,50 @@ class FormLoginDslTests {
|
367 | 368 | verify(exactly = 1) { CustomAuthenticationDetailsSourceConfig.AUTHENTICATION_DETAILS_SOURCE.buildDetails(any()) }
|
368 | 369 | }
|
369 | 370 |
|
| 371 | + @Configuration |
| 372 | + @EnableWebSecurity |
| 373 | + open class CustomUsernameParameterConfig { |
| 374 | + @Bean |
| 375 | + open fun securityFilterChain(http: HttpSecurity): SecurityFilterChain { |
| 376 | + http { |
| 377 | + formLogin { |
| 378 | + usernameParameter = "custom-username" |
| 379 | + } |
| 380 | + } |
| 381 | + return http.build() |
| 382 | + } |
| 383 | + } |
| 384 | + |
| 385 | + @Test |
| 386 | + fun `form login when custom username parameter then used`() { |
| 387 | + this.spring.register(CustomUsernameParameterConfig::class.java, UserConfig::class.java).autowire() |
| 388 | + |
| 389 | + this.mockMvc.perform(formLogin().userParameter("custom-username")) |
| 390 | + .andExpect(authenticated()) |
| 391 | + } |
| 392 | + |
| 393 | + @Configuration |
| 394 | + @EnableWebSecurity |
| 395 | + open class CustomPasswordParameterConfig { |
| 396 | + @Bean |
| 397 | + open fun securityFilterChain(http: HttpSecurity): SecurityFilterChain { |
| 398 | + http { |
| 399 | + formLogin { |
| 400 | + passwordParameter = "custom-password" |
| 401 | + } |
| 402 | + } |
| 403 | + return http.build() |
| 404 | + } |
| 405 | + } |
| 406 | + |
| 407 | + @Test |
| 408 | + fun `form login when custom password parameter then used`() { |
| 409 | + this.spring.register(CustomPasswordParameterConfig::class.java, UserConfig::class.java).autowire() |
| 410 | + |
| 411 | + this.mockMvc.perform(formLogin().passwordParam("custom-password")) |
| 412 | + .andExpect(authenticated()) |
| 413 | + } |
| 414 | + |
370 | 415 | @Configuration
|
371 | 416 | @EnableWebSecurity
|
372 | 417 | open class CustomAuthenticationDetailsSourceConfig {
|
|
0 commit comments