Merge pull request #734 from mposolda/master

Workaround for WFLY-3345 so logout can work for 'distributable' applicat...
This commit is contained in:
Marek Posolda 2014-10-03 11:27:28 +02:00
commit 18401815af

View file

@ -19,6 +19,7 @@ package org.keycloak.adapters.undertow;
import io.undertow.security.api.AuthenticatedSessionManager; import io.undertow.security.api.AuthenticatedSessionManager;
import io.undertow.server.HttpServerExchange; import io.undertow.server.HttpServerExchange;
import io.undertow.server.session.Session; import io.undertow.server.session.Session;
import io.undertow.server.session.SessionConfig;
import io.undertow.server.session.SessionListener; import io.undertow.server.session.SessionListener;
import io.undertow.server.session.SessionManager; import io.undertow.server.session.SessionManager;
import io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler; import io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler;
@ -108,7 +109,7 @@ public class UndertowUserSessionManagement implements SessionListener {
log.debug("invalidating session for user: " + user); log.debug("invalidating session for user: " + user);
String sessionId = entry.getKey(); String sessionId = entry.getKey();
String keycloakSessionId = entry.getValue(); String keycloakSessionId = entry.getValue();
Session session = manager.getSession(sessionId); Session session = getSessionById(manager, sessionId);
try { try {
session.invalidate(null); session.invalidate(null);
} catch (Exception e) { } catch (Exception e) {
@ -131,7 +132,7 @@ public class UndertowUserSessionManagement implements SessionListener {
} }
sessions.httpSessionToKeycloakSession.remove(sessionId); sessions.httpSessionToKeycloakSession.remove(sessionId);
Session session = manager.getSession(sessionId); Session session = getSessionById(manager, sessionId);
try { try {
session.invalidate(null); session.invalidate(null);
} catch (Exception e) { } 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 @Override
public void sessionCreated(Session session, HttpServerExchange exchange) { public void sessionCreated(Session session, HttpServerExchange exchange) {