From 1db4c11fa54b15e9f34b60401bc9800b3b8697c9 Mon Sep 17 00:00:00 2001 From: Emmanuel Durin Date: Mon, 15 Jan 2024 22:37:09 +0100 Subject: [PATCH] logged out user --- .../security/ResolveGeorchestraUserGlobalFilter.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gateway/src/main/java/org/georchestra/gateway/security/ResolveGeorchestraUserGlobalFilter.java b/gateway/src/main/java/org/georchestra/gateway/security/ResolveGeorchestraUserGlobalFilter.java index 3c559380..ce539741 100644 --- a/gateway/src/main/java/org/georchestra/gateway/security/ResolveGeorchestraUserGlobalFilter.java +++ b/gateway/src/main/java/org/georchestra/gateway/security/ResolveGeorchestraUserGlobalFilter.java @@ -31,9 +31,11 @@ import org.springframework.cloud.gateway.route.Route; import org.springframework.core.Ordered; import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.server.DefaultServerRedirectStrategy; import org.springframework.security.web.server.ServerRedirectStrategy; import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.WebSession; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -97,8 +99,10 @@ public class ResolveGeorchestraUserGlobalFilter implements GlobalFilter, Ordered })// .map(user -> { if (user.isEmpty()) { - return this.redirectStrategy.sendRedirect(exchange, URI - .create("https://georchestra-127-0-1-1.traefik.me/login?error=" + DUPLICATE_ACCOUNT)); + SecurityContextHolder.getContext(); + return this.redirectStrategy // + .sendRedirect(exchange, URI.create("/login?error=" + DUPLICATE_ACCOUNT)) // + .then(exchange.getSession().flatMap(WebSession::invalidate)); } GeorchestraUser usr = user.orElse(null); @@ -110,8 +114,8 @@ public class ResolveGeorchestraUserGlobalFilter implements GlobalFilter, Ordered } return chain.filter(exchange); })// - .defaultIfEmpty(chain.filter(exchange))// - .flatMap(Function.identity()); + .flatMap(Function.identity()) // + .switchIfEmpty(Mono.fromRunnable(() -> chain.filter(exchange))); System.out.println(res); return res;