From 2edb7f68313a0271eee7de6e9a21640737f96819 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Thu, 3 Mar 2016 08:59:19 +0100 Subject: [PATCH] KEYCLOAK-2577 Rollback session in KeycloakSessionServletFilter if not committed by KeycloakTransactionCommitter --- .../services/filters/KeycloakSessionServletFilter.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/src/main/java/org/keycloak/services/filters/KeycloakSessionServletFilter.java b/services/src/main/java/org/keycloak/services/filters/KeycloakSessionServletFilter.java index 530447ea87..d6a3f13dc9 100755 --- a/services/src/main/java/org/keycloak/services/filters/KeycloakSessionServletFilter.java +++ b/services/src/main/java/org/keycloak/services/filters/KeycloakSessionServletFilter.java @@ -77,6 +77,12 @@ public class KeycloakSessionServletFilter implements Filter { try { filterChain.doFilter(servletRequest, servletResponse); } finally { + // KeycloakTransactionCommitter is responsible for committing the transaction, but if an exception is thrown it's not invoked and transaction + // should be rolled back + if (session.getTransaction() != null && session.getTransaction().isActive()) { + session.getTransaction().rollback(); + } + session.close(); ResteasyProviderFactory.clearContextData(); }