From 015036741be0f8ed92d1cdb27a87a07cc1fb42a1 Mon Sep 17 00:00:00 2001 From: Talerngpong Virojwutikul Date: Thu, 10 Feb 2022 23:07:20 +0700 Subject: [PATCH] Add Kotlin example for logout configuration of reactive authentication Closes gh-10819 --- .../pages/reactive/authentication/logout.adoc | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/modules/ROOT/pages/reactive/authentication/logout.adoc b/docs/modules/ROOT/pages/reactive/authentication/logout.adoc index 0d4137d108..d4dafaa9c3 100644 --- a/docs/modules/ROOT/pages/reactive/authentication/logout.adoc +++ b/docs/modules/ROOT/pages/reactive/authentication/logout.adoc @@ -11,7 +11,8 @@ This will: Often, you will want to also invalidate the session on logout. To achieve this, you can add the `WebSessionServerLogoutHandler` to your logout configuration, like so: -[source,java] +.Java +[source,java,role="primary"] ---- @Bean SecurityWebFilterChain http(ServerHttpSecurity http) throws Exception { @@ -26,3 +27,23 @@ SecurityWebFilterChain http(ServerHttpSecurity http) throws Exception { return http.build(); } ---- + +.Kotlin +[source,kotlin,role="secondary"] +---- +@Bean +fun http(http: ServerHttpSecurity): SecurityWebFilterChain { + val customLogoutHandler = DelegatingServerLogoutHandler( + WebSessionServerLogoutHandler(), SecurityContextServerLogoutHandler() + ) + + return http { + authorizeExchange { + authorize(anyExchange, authenticated) + } + logout { + logoutHandler = customLogoutHandler + } + } +} +----