File tree Expand file tree Collapse file tree 3 files changed +60
-1
lines changed
main/java/org/springframework/security/config/web/server
test/java/org/springframework/security/config
annotation/web/configurers Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -2765,7 +2765,9 @@ public ServerHttpSecurity disable() {
2765
2765
protected void configure (ServerHttpSecurity http ) {
2766
2766
if (this .csrfTokenRepository != null ) {
2767
2767
this .filter .setCsrfTokenRepository (this .csrfTokenRepository );
2768
- http .logout ().addLogoutHandler (new CsrfServerLogoutHandler (this .csrfTokenRepository ));
2768
+ if (ServerHttpSecurity .this .logout != null ) {
2769
+ ServerHttpSecurity .this .logout .addLogoutHandler (new CsrfServerLogoutHandler (this .csrfTokenRepository ));
2770
+ }
2769
2771
}
2770
2772
http .addFilterAt (this .filter , SecurityWebFiltersOrder .CSRF );
2771
2773
}
Original file line number Diff line number Diff line change @@ -458,4 +458,25 @@ public void logoutWhenXMLHttpRequestThenReturnsStatusNoContent() throws Exceptio
458
458
@ EnableWebSecurity
459
459
static class BasicSecurityConfig extends WebSecurityConfigurerAdapter {
460
460
}
461
+
462
+ @ Test
463
+ public void logoutWhenDisabledThenLogoutUrlNotFound () throws Exception {
464
+ this .spring .register (LogoutDisabledConfig .class ).autowire ();
465
+
466
+ this .mvc .perform (post ("/logout" )
467
+ .with (csrf ()))
468
+ .andExpect (status ().isNotFound ());
469
+ }
470
+
471
+ @ EnableWebSecurity
472
+ static class LogoutDisabledConfig extends WebSecurityConfigurerAdapter {
473
+ @ Override
474
+ protected void configure (HttpSecurity http ) throws Exception {
475
+ // @formatter:off
476
+ http
477
+ .logout ()
478
+ .disable ();
479
+ // @formatter:on
480
+ }
481
+ }
461
482
}
Original file line number Diff line number Diff line change @@ -164,4 +164,40 @@ public void logoutWhenCustomLogoutInLambdaThenCustomLogoutUsed() {
164
164
.assertAt ()
165
165
.assertLogout ();
166
166
}
167
+
168
+ @ Test
169
+ public void logoutWhenDisabledThenPostToLogoutDoesNothing () {
170
+ SecurityWebFilterChain securityWebFilter = this .http
171
+ .authorizeExchange ()
172
+ .anyExchange ().authenticated ()
173
+ .and ()
174
+ .formLogin ().and ()
175
+ .logout ().disable ()
176
+ .build ();
177
+
178
+ WebTestClient webTestClient = WebTestClientBuilder
179
+ .bindToWebFilters (securityWebFilter )
180
+ .build ();
181
+
182
+ WebDriver driver = WebTestClientHtmlUnitDriverBuilder
183
+ .webTestClientSetup (webTestClient )
184
+ .build ();
185
+
186
+ FormLoginTests .DefaultLoginPage loginPage = FormLoginTests .HomePage .to (driver , FormLoginTests .DefaultLoginPage .class )
187
+ .assertAt ();
188
+
189
+ FormLoginTests .HomePage homePage = loginPage .loginForm ()
190
+ .username ("user" )
191
+ .password ("password" )
192
+ .submit (FormLoginTests .HomePage .class );
193
+
194
+ homePage .assertAt ();
195
+
196
+ FormLoginTests .DefaultLogoutPage .to (driver )
197
+ .assertAt ()
198
+ .logout ();
199
+
200
+ homePage
201
+ .assertAt ();
202
+ }
167
203
}
You can’t perform that action at this time.
0 commit comments