Skip to content

Commit 44aae09

Browse files
authored
Merge pull request apolloconfig#1529 from nobodyiam/fix-spring-security-5-logout
fix logout issue with spring security 5
2 parents b70060f + a8f00d4 commit 44aae09

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/controller/ControllerIntegrationExceptionTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.ctrip.framework.apollo.common.dto.AppDTO;
88
import com.ctrip.framework.apollo.common.entity.App;
99

10+
import org.junit.After;
1011
import org.junit.Assert;
1112
import org.junit.Before;
1213
import org.junit.Test;
@@ -31,6 +32,8 @@ public class ControllerIntegrationExceptionTest extends AbstractControllerTest {
3132
@Mock
3233
AdminService adminService;
3334

35+
private Object realAdminService;
36+
3437
@Autowired
3538
AppService appService;
3639

@@ -39,9 +42,17 @@ public class ControllerIntegrationExceptionTest extends AbstractControllerTest {
3942
@Before
4043
public void setUp() {
4144
MockitoAnnotations.initMocks(this);
45+
46+
realAdminService = ReflectionTestUtils.getField(appController, "adminService");
47+
4248
ReflectionTestUtils.setField(appController, "adminService", adminService);
4349
}
4450

51+
@After
52+
public void tearDown() throws Exception {
53+
ReflectionTestUtils.setField(appController, "adminService", realAdminService);
54+
}
55+
4556
private String getBaseAppUrl() {
4657
return "http://localhost:" + port + "/apps/";
4758
}

apollo-mockserver/src/test/java/com/ctrip/framework/apollo/mockserver/ApolloMockServerApiTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class ApolloMockServerApiTest {
1616

17-
private static final String otherNamespace = "otherNamespace";
17+
private static final String anotherNamespace = "anotherNamespace";
1818

1919
@ClassRule
2020
public static EmbeddedApollo embeddedApollo = new EmbeddedApollo();
@@ -31,7 +31,7 @@ public void testGetProperty() throws Exception {
3131
public void testUpdateProperties() throws Exception {
3232
String someNewValue = "someNewValue";
3333

34-
Config otherConfig = ConfigService.getConfig(otherNamespace);
34+
Config otherConfig = ConfigService.getConfig(anotherNamespace);
3535

3636
final SettableFuture<ConfigChangeEvent> future = SettableFuture.create();
3737

@@ -45,7 +45,7 @@ public void onChange(ConfigChangeEvent changeEvent) {
4545
assertEquals("otherValue1", otherConfig.getProperty("key1", null));
4646
assertEquals("otherValue2", otherConfig.getProperty("key2", null));
4747

48-
embeddedApollo.addOrModifyProperty(otherNamespace, "key1", someNewValue);
48+
embeddedApollo.addOrModifyProperty(anotherNamespace, "key1", someNewValue);
4949

5050
ConfigChangeEvent changeEvent = future.get(5, TimeUnit.SECONDS);
5151

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
key1=otherValue1
2+
key2=otherValue2

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
4747
import org.springframework.security.provisioning.JdbcUserDetailsManager;
4848
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
49+
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
4950

5051

5152
@Configuration
@@ -270,8 +271,10 @@ protected void configure(HttpSecurity http) throws Exception {
270271
.antMatchers("/openapi/**", "/vendor/**", "/styles/**", "/scripts/**", "/views/**", "/img/**").permitAll()
271272
.antMatchers("/**").hasAnyRole(USER_ROLE);
272273
http.formLogin().loginPage("/signin").permitAll().failureUrl("/signin?#/error").and().httpBasic();
274+
SimpleUrlLogoutSuccessHandler urlLogoutHandler = new SimpleUrlLogoutSuccessHandler();
275+
urlLogoutHandler.setDefaultTargetUrl("/signin?#/logout");
273276
http.logout().logoutUrl("/user/logout").invalidateHttpSession(true).clearAuthentication(true)
274-
.logoutSuccessUrl("/signin?#/logout");
277+
.logoutSuccessHandler(urlLogoutHandler);
275278
http.exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/signin"));
276279
}
277280

0 commit comments

Comments
 (0)