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 @@ -2775,7 +2775,9 @@ public ServerHttpSecurity disable() {
2775
2775
protected void configure (ServerHttpSecurity http ) {
2776
2776
if (this .csrfTokenRepository != null ) {
2777
2777
this .filter .setCsrfTokenRepository (this .csrfTokenRepository );
2778
- http .logout ().addLogoutHandler (new CsrfServerLogoutHandler (this .csrfTokenRepository ));
2778
+ if (ServerHttpSecurity .this .logout != null ) {
2779
+ ServerHttpSecurity .this .logout .addLogoutHandler (new CsrfServerLogoutHandler (this .csrfTokenRepository ));
2780
+ }
2779
2781
}
2780
2782
http .addFilterAt (this .filter , SecurityWebFiltersOrder .CSRF );
2781
2783
}
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