Commit 44aae099 authored by Jason Song's avatar Jason Song Committed by GitHub

Merge pull request #1529 from nobodyiam/fix-spring-security-5-logout

fix logout issue with spring security 5
parents b70060ff a8f00d48
......@@ -7,6 +7,7 @@ import com.ctrip.framework.apollo.biz.service.AppService;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.entity.App;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
......@@ -31,6 +32,8 @@ public class ControllerIntegrationExceptionTest extends AbstractControllerTest {
@Mock
AdminService adminService;
private Object realAdminService;
@Autowired
AppService appService;
......@@ -39,9 +42,17 @@ public class ControllerIntegrationExceptionTest extends AbstractControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
realAdminService = ReflectionTestUtils.getField(appController, "adminService");
ReflectionTestUtils.setField(appController, "adminService", adminService);
}
@After
public void tearDown() throws Exception {
ReflectionTestUtils.setField(appController, "adminService", realAdminService);
}
private String getBaseAppUrl() {
return "http://localhost:" + port + "/apps/";
}
......
......@@ -14,7 +14,7 @@ import org.junit.Test;
public class ApolloMockServerApiTest {
private static final String otherNamespace = "otherNamespace";
private static final String anotherNamespace = "anotherNamespace";
@ClassRule
public static EmbeddedApollo embeddedApollo = new EmbeddedApollo();
......@@ -31,7 +31,7 @@ public class ApolloMockServerApiTest {
public void testUpdateProperties() throws Exception {
String someNewValue = "someNewValue";
Config otherConfig = ConfigService.getConfig(otherNamespace);
Config otherConfig = ConfigService.getConfig(anotherNamespace);
final SettableFuture<ConfigChangeEvent> future = SettableFuture.create();
......@@ -45,7 +45,7 @@ public class ApolloMockServerApiTest {
assertEquals("otherValue1", otherConfig.getProperty("key1", null));
assertEquals("otherValue2", otherConfig.getProperty("key2", null));
embeddedApollo.addOrModifyProperty(otherNamespace, "key1", someNewValue);
embeddedApollo.addOrModifyProperty(anotherNamespace, "key1", someNewValue);
ConfigChangeEvent changeEvent = future.get(5, TimeUnit.SECONDS);
......
......@@ -46,6 +46,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
import org.springframework.security.provisioning.JdbcUserDetailsManager;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
@Configuration
......@@ -270,8 +271,10 @@ public class AuthConfiguration {
.antMatchers("/openapi/**", "/vendor/**", "/styles/**", "/scripts/**", "/views/**", "/img/**").permitAll()
.antMatchers("/**").hasAnyRole(USER_ROLE);
http.formLogin().loginPage("/signin").permitAll().failureUrl("/signin?#/error").and().httpBasic();
SimpleUrlLogoutSuccessHandler urlLogoutHandler = new SimpleUrlLogoutSuccessHandler();
urlLogoutHandler.setDefaultTargetUrl("/signin?#/logout");
http.logout().logoutUrl("/user/logout").invalidateHttpSession(true).clearAuthentication(true)
.logoutSuccessUrl("/signin?#/logout");
.logoutSuccessHandler(urlLogoutHandler);
http.exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/signin"));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment