DEV Community

loizenai
loizenai

Posted on

Kotlin – Spring Security Customize Logout Success Handler

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.

I. Technologies

– Kotlin 1.2.20
– Apache Maven 3.5.2
– Spring Tool Suite – Version 3.9.0.RELEASE
– Spring Boot – 1.5.10.RELEASE
– Bootstrap

II. Goal

We create a Kotlin MVC Web Application as below:

Kotlin Spring Security - Customize LogOut Successfully - project structure

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

Kotlin Spring Security - Customize LogOut Successfully - logout succesfully

III. Implementation

1. Create Kotlin Spring Security web application

-> Follow the article: Kotlin SpringBoot – Configure Spring Security

2. Customize LogoutSuccessHandler

2.1. Create logoutsuccessful.html page
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:th="http://www.thymeleaf.org"
    xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <title>Welcome Security with Spring Boot!</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet"
        href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
    <script
        src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script
        src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body class="container" style="margin:50px">
    <div class="row col-sm-5" 
                style="border: 1px ridge #003312; padding:20px; float: none; margin: 0 auto;">
            <h1>Logout Successfully!</h1>
            <a style="color: blue" th:href="@{/}">Home Page</a>
            <br />
            <a style="color: blue" th:href="@{/login}">Login Page</a>
    </div>
</body>
</html>
2.2 Customize LogoutSuccessHandler

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

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay