1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.sra.security.oauth2;
20
21 import org.apache.syncope.sra.SessionConfig;
22 import org.springframework.cache.CacheManager;
23 import org.springframework.security.core.Authentication;
24 import org.springframework.security.web.server.WebFilterExchange;
25 import org.springframework.security.web.server.authentication.logout.ServerLogoutHandler;
26 import org.springframework.web.server.WebSession;
27 import reactor.core.publisher.Mono;
28
29 public class OAuth2SessionRemovalServerLogoutHandler implements ServerLogoutHandler {
30
31 private final CacheManager cacheManager;
32
33 public OAuth2SessionRemovalServerLogoutHandler(final CacheManager cacheManager) {
34 this.cacheManager = cacheManager;
35 }
36
37 @Override
38 public Mono<Void> logout(final WebFilterExchange exchange, final Authentication authentication) {
39 return exchange.getExchange().getSession().
40 doOnNext(session -> cacheManager.getCache(SessionConfig.DEFAULT_CACHE).evictIfPresent(session.getId())).
41 flatMap(WebSession::invalidate);
42 }
43 }