Skip to content

Commit 0d75b1d

Browse files
author
Dmitriy Dubson
committed
Add logout success page to default client sample
Sample client (located in 'samples/messages-client' directory) is configured with a custom logout success page where the end-user is redirected to upon successful logout action. Fixes spring-projectsgh-1142
1 parent 128d439 commit 0d75b1d

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

samples/default-authorizationserver/src/main/java/sample/config/AuthorizationServerConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
/**
5656
* @author Joe Grandja
57+
* @author Dmitriy Dubson
5758
* @since 0.0.1
5859
*/
5960
@Configuration(proxyBeanMethods = false)
@@ -88,7 +89,7 @@ public RegisteredClientRepository registeredClientRepository(JdbcTemplate jdbcTe
8889
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
8990
.redirectUri("http://127.0.0.1:8080/login/oauth2/code/messaging-client-oidc")
9091
.redirectUri("http://127.0.0.1:8080/authorized")
91-
.postLogoutRedirectUri("http://127.0.0.1:8080/index")
92+
.postLogoutRedirectUri("http://127.0.0.1:8080/logged-out")
9293
.scope(OidcScopes.OPENID)
9394
.scope(OidcScopes.PROFILE)
9495
.scope("message.read")

samples/messages-client/src/main/java/sample/config/SecurityConfig.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
/**
3232
* @author Joe Grandja
33+
* @author Dmitriy Dubson
3334
* @since 0.0.1
3435
*/
3536
@EnableWebSecurity
@@ -49,7 +50,9 @@ WebSecurityCustomizer webSecurityCustomizer() {
4950
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
5051
http
5152
.authorizeHttpRequests(authorize ->
52-
authorize.anyRequest().authenticated()
53+
authorize
54+
.requestMatchers("/logged-out").permitAll()
55+
.anyRequest().authenticated()
5356
)
5457
.oauth2Login(oauth2Login ->
5558
oauth2Login.loginPage("/oauth2/authorization/messaging-client-oidc"))
@@ -66,7 +69,7 @@ private LogoutSuccessHandler oidcLogoutSuccessHandler() {
6669

6770
// Set the location that the End-User's User Agent will be redirected to
6871
// after the logout has been performed at the Provider
69-
oidcLogoutSuccessHandler.setPostLogoutRedirectUri("{baseUrl}/index");
72+
oidcLogoutSuccessHandler.setPostLogoutRedirectUri("{baseUrl}/logged-out");
7073

7174
return oidcLogoutSuccessHandler;
7275
}

samples/messages-client/src/main/java/sample/web/DefaultController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
/**
2222
* @author Joe Grandja
23+
* @author Dmitriy Dubson
2324
* @since 0.0.1
2425
*/
2526
@Controller
@@ -34,4 +35,10 @@ public String root() {
3435
public String index() {
3536
return "index";
3637
}
38+
39+
@GetMapping("/logged-out")
40+
public String loggedOut() {
41+
return "logged-out";
42+
}
43+
3744
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org" xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity6">
3+
<head>
4+
<title>Spring Security OAuth 2.0 Sample</title>
5+
<meta charset="utf-8"/>
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
7+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
8+
<link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.css"
9+
th:href="@{/webjars/bootstrap/css/bootstrap.css}"/>
10+
</head>
11+
<body>
12+
<div th:fragment="header">
13+
<nav class="navbar navbar-default"></nav>
14+
</div>
15+
<div class="container">
16+
<h1>You are now logged out.</h1>
17+
<a href="/" th:href="@{/}">Go back home</a>
18+
</div>
19+
<script src="/webjars/jquery/jquery.min.js" th:src="@{/webjars/jquery/jquery.min.js}"></script>
20+
<script src="/webjars/bootstrap/js/bootstrap.min.js" th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)