Kotlin – Spring Security Customize Logout Success Handler
Tags: kotlin, springsecurity, springboot, logout
Published: 2021-05-21 16:18:44

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-spring-security-customize-logout-success-handler

Kotlin – Spring Security Customize Logout Success Handler


In the tutorial, we will show you how to customize Logout Success Handler with Kotlin Spring Security web application.

<!--more-->
<h2>I. Technologies</h2>
– Kotlin 1.2.20
– Apache Maven 3.5.2
– Spring Tool Suite – Version 3.9.0.RELEASE
– Spring Boot – 1.5.10.RELEASE
– Bootstrap
<h2>II. Goal</h2>
We create a Kotlin MVC Web Application as below:

<img src="https://grokonez.com/wp-content/uploads/2018/02/Kotlin-Spring-Security-Customize-LogOut-Successfully-project-structure.png" alt="Kotlin Spring Security - Customize LogOut Successfully - project structure" width="443" height="343" class="alignnone size-full wp-image-10691" />

We use <code>LogoutSuccessHandler</code> to customize a behaviour of Kotlin Spring Security after logout successfully. In the tutorial, it will redirect to <code>logoutsuccessful.html</code> page:

<img src="https://grokonez.com/wp-content/uploads/2018/02/Kotlin-Spring-Security-Customize-LogOut-Successfully-logout-succesfully.png" alt="Kotlin Spring Security - Customize LogOut Successfully - logout succesfully" width="506" height="179" class="alignnone size-full wp-image-10692" />
<h2>III. Implementation</h2>
<h3>1. Create Kotlin Spring Security web application</h3>
-> Follow the article: <a href="https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-springboot-configure-spring-security">Kotlin SpringBoot – Configure Spring Security</a>
<h3>2. Customize LogoutSuccessHandler</h3>
<h6>2.1. Create logoutsuccessful.html page</h6>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
	xmlns:th=&quot;http://www.thymeleaf.org&quot;
	xmlns:sec=&quot;http://www.thymeleaf.org/thymeleaf-extras-springsecurity3&quot;&gt;
&lt;head&gt;
	&lt;title&gt;Welcome Security with Spring Boot!&lt;/title&gt;
	&lt;meta charset=&quot;utf-8&quot;/&gt;
	&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;/&gt;
	&lt;link rel=&quot;stylesheet&quot;
		href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&quot;/&gt;
	&lt;script
		src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
	&lt;script
		src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body class=&quot;container&quot; style=&quot;margin:50px&quot;&gt;
	&lt;div class=&quot;row col-sm-5&quot; 
				style=&quot;border: 1px ridge #003312; padding:20px; float: none; margin: 0 auto;&quot;&gt;
			&lt;h1&gt;Logout Successfully!&lt;/h1&gt;
			&lt;a style=&quot;color: blue&quot; th:href=&quot;@{/}&quot;&gt;Home Page&lt;/a&gt;
			&lt;br /&gt;
			&lt;a style=&quot;color: blue&quot; th:href=&quot;@{/login}&quot;&gt;Login Page&lt;/a&gt;
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<h6>2.2 Customize LogoutSuccessHandler</h6>


More at:

https://grokonez.com/spring-framework/spring-boot/kotlin-spring-boot/kotlin-spring-security-customize-logout-success-handler

Kotlin – Spring Security Customize Logout Success Handler