|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2019 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2022 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -25,12 +25,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.security.config.annotation.ObjectPostProcessor;
|
|
import org.springframework.security.config.annotation.ObjectPostProcessor;
|
|
|
|
+import org.springframework.security.config.annotation.SecurityContextChangedListenerConfig;
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
import org.springframework.security.config.test.SpringTestContext;
|
|
import org.springframework.security.config.test.SpringTestContext;
|
|
import org.springframework.security.config.test.SpringTestContextExtension;
|
|
import org.springframework.security.config.test.SpringTestContextExtension;
|
|
|
|
+import org.springframework.security.core.context.SecurityContextHolderStrategy;
|
|
import org.springframework.security.web.authentication.RememberMeServices;
|
|
import org.springframework.security.web.authentication.RememberMeServices;
|
|
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
|
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
|
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
|
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
|
@@ -40,6 +42,7 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
+import static org.mockito.Mockito.atLeastOnce;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.spy;
|
|
import static org.mockito.Mockito.spy;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.verify;
|
|
@@ -241,6 +244,22 @@ public class LogoutConfigurerTests {
|
|
// @formatter:on
|
|
// @formatter:on
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void logoutWhenCustomSecurityContextHolderStrategyThenUses() throws Exception {
|
|
|
|
+ this.spring.register(BasicSecurityConfig.class, SecurityContextChangedListenerConfig.class).autowire();
|
|
|
|
+ // @formatter:off
|
|
|
|
+ MockHttpServletRequestBuilder logoutRequest = post("/logout")
|
|
|
|
+ .with(csrf())
|
|
|
|
+ .with(user("user"))
|
|
|
|
+ .header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE);
|
|
|
|
+ this.mvc.perform(logoutRequest)
|
|
|
|
+ .andExpect(status().isFound())
|
|
|
|
+ .andExpect(redirectedUrl("/login?logout"));
|
|
|
|
+ // @formatter:on
|
|
|
|
+ SecurityContextHolderStrategy strategy = this.spring.getContext().getBean(SecurityContextHolderStrategy.class);
|
|
|
|
+ verify(strategy, atLeastOnce()).getContext();
|
|
|
|
+ }
|
|
|
|
+
|
|
// gh-3282
|
|
// gh-3282
|
|
@Test
|
|
@Test
|
|
public void logoutWhenAcceptApplicationJsonThenReturnsStatusNoContent() throws Exception {
|
|
public void logoutWhenAcceptApplicationJsonThenReturnsStatusNoContent() throws Exception {
|