From 10e618dee9f1941a475befec46f446984e0d9e54 Mon Sep 17 00:00:00 2001 From: mposolda Date: Fri, 3 Oct 2014 11:20:02 +0200 Subject: [PATCH] Workaround for WFLY-3345 so logout can work for 'distributable' applications --- .../UndertowUserSessionManagement.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/integration/undertow/src/main/java/org/keycloak/adapters/undertow/UndertowUserSessionManagement.java b/integration/undertow/src/main/java/org/keycloak/adapters/undertow/UndertowUserSessionManagement.java index 352b3a3345..f39fe6a5bc 100755 --- a/integration/undertow/src/main/java/org/keycloak/adapters/undertow/UndertowUserSessionManagement.java +++ b/integration/undertow/src/main/java/org/keycloak/adapters/undertow/UndertowUserSessionManagement.java @@ -19,6 +19,7 @@ package org.keycloak.adapters.undertow; import io.undertow.security.api.AuthenticatedSessionManager; import io.undertow.server.HttpServerExchange; import io.undertow.server.session.Session; +import io.undertow.server.session.SessionConfig; import io.undertow.server.session.SessionListener; import io.undertow.server.session.SessionManager; import io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler; @@ -108,7 +109,7 @@ public class UndertowUserSessionManagement implements SessionListener { log.debug("invalidating session for user: " + user); String sessionId = entry.getKey(); String keycloakSessionId = entry.getValue(); - Session session = manager.getSession(sessionId); + Session session = getSessionById(manager, sessionId); try { session.invalidate(null); } catch (Exception e) { @@ -131,7 +132,7 @@ public class UndertowUserSessionManagement implements SessionListener { } sessions.httpSessionToKeycloakSession.remove(sessionId); - Session session = manager.getSession(sessionId); + Session session = getSessionById(manager, sessionId); try { session.invalidate(null); } catch (Exception e) { @@ -142,6 +143,41 @@ public class UndertowUserSessionManagement implements SessionListener { } } + protected Session getSessionById(SessionManager manager, final String sessionId) { + // TODO: Workaround for WFLY-3345. Remove this once we move to wildfly 8.2 + if (manager.getClass().getName().equals("org.wildfly.clustering.web.undertow.session.DistributableSessionManager")) { + return manager.getSession(null, new SessionConfig() { + + @Override + public void setSessionId(HttpServerExchange exchange, String sessionId) { + } + + @Override + public void clearSession(HttpServerExchange exchange, String sessionId) { + } + + @Override + public String findSessionId(HttpServerExchange exchange) { + return sessionId; + } + + @Override + public SessionCookieSource sessionCookieSource(HttpServerExchange exchange) { + return null; + } + + @Override + public String rewriteUrl(String originalUrl, String sessionId) { + return null; + } + + }); + + } else { + return manager.getSession(sessionId); + } + } + @Override public void sessionCreated(Session session, HttpServerExchange exchange) {