File tree 2 files changed +29
-1
lines changed
main/java/org/springframework/security/config/web/server
test/java/org/springframework/security/config/web/server 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -3049,7 +3049,9 @@ public FormLoginSpec authenticationSuccessHandler(
3049
3049
public FormLoginSpec loginPage (String loginPage ) {
3050
3050
this .defaultEntryPoint = new RedirectServerAuthenticationEntryPoint (loginPage );
3051
3051
this .authenticationEntryPoint = this .defaultEntryPoint ;
3052
- this .requiresAuthenticationMatcher = ServerWebExchangeMatchers .pathMatchers (HttpMethod .POST , loginPage );
3052
+ if (this .requiresAuthenticationMatcher == null ) {
3053
+ this .requiresAuthenticationMatcher = ServerWebExchangeMatchers .pathMatchers (HttpMethod .POST , loginPage );
3054
+ }
3053
3055
if (this .authenticationFailureHandler == null ) {
3054
3056
this .authenticationFailureHandler = new RedirectServerAuthenticationFailureHandler (loginPage + "?error" );
3055
3057
}
Original file line number Diff line number Diff line change 37
37
import org .springframework .security .web .server .authentication .RedirectServerAuthenticationSuccessHandler ;
38
38
import org .springframework .security .web .server .context .ServerSecurityContextRepository ;
39
39
import org .springframework .security .web .server .csrf .CsrfToken ;
40
+ import org .springframework .security .web .server .util .matcher .PathPatternParserServerWebExchangeMatcher ;
40
41
import org .springframework .stereotype .Controller ;
41
42
import org .springframework .test .web .reactive .server .WebTestClient ;
42
43
import org .springframework .web .bind .annotation .GetMapping ;
@@ -245,6 +246,31 @@ public void formLoginWhenCustomAuthenticationFailureHandlerThenUsed() {
245
246
assertThat (driver .getCurrentUrl ()).endsWith ("/failure" );
246
247
}
247
248
249
+ @ Test
250
+ public void formLoginWhenCustomRequiresAuthenticationMatcherThenUsed () {
251
+ SecurityWebFilterChain securityWebFilter = this .http
252
+ .authorizeExchange ()
253
+ .pathMatchers ("/login" , "/sign-in" ).permitAll ()
254
+ .anyExchange ().authenticated ()
255
+ .and ()
256
+ .formLogin ()
257
+ .requiresAuthenticationMatcher (new PathPatternParserServerWebExchangeMatcher ("/sign-in" ))
258
+ .and ()
259
+ .build ();
260
+
261
+ WebTestClient webTestClient = WebTestClientBuilder
262
+ .bindToWebFilters (securityWebFilter )
263
+ .build ();
264
+
265
+ WebDriver driver = WebTestClientHtmlUnitDriverBuilder
266
+ .webTestClientSetup (webTestClient )
267
+ .build ();
268
+
269
+ driver .get ("http://localhost/sign-in" );
270
+
271
+ assertThat (driver .getCurrentUrl ()).endsWith ("/login?error" );
272
+ }
273
+
248
274
@ Test
249
275
public void authenticationSuccess () {
250
276
SecurityWebFilterChain securityWebFilter = this .http
You can’t perform that action at this time.
0 commit comments