浏览代码

Add Kotlin example for logout configuration of reactive authentication

Closes gh-10819
Talerngpong Virojwutikul 3 年之前
父节点
当前提交
d0faff62df
共有 1 个文件被更改,包括 22 次插入1 次删除
  1. 22 1
      docs/modules/ROOT/pages/reactive/authentication/logout.adoc

+ 22 - 1
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
+        }
+    }
+}
+----