mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-30 22:28:46 +00:00 
			
		
		
		
	Add Kotlin example for logout configuration of reactive authentication
Closes gh-10819
This commit is contained in:
		
							parent
							
								
									9f9fbb395f
								
							
						
					
					
						commit
						d0faff62df
					
				| @ -11,7 +11,8 @@ This will: | |||||||
| Often, you will want to also invalidate the session on logout. | 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: | To achieve this, you can add the `WebSessionServerLogoutHandler` to your logout configuration, like so: | ||||||
| 
 | 
 | ||||||
| [source,java] | .Java | ||||||
|  | [source,java,role="primary"] | ||||||
| ---- | ---- | ||||||
| @Bean | @Bean | ||||||
| SecurityWebFilterChain http(ServerHttpSecurity http) throws Exception { | SecurityWebFilterChain http(ServerHttpSecurity http) throws Exception { | ||||||
| @ -26,3 +27,23 @@ SecurityWebFilterChain http(ServerHttpSecurity http) throws Exception { | |||||||
|     return http.build(); |     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 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | ---- | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user