From e3daf6fcf89a96007aac96c4d604248d822edc5c Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Tue, 26 Jan 2016 13:55:39 +0100 Subject: [PATCH] KEYCLOAK-2327 Make sure transaction is only committed for success --- .../filters/ClientConnectionFilter.java | 48 ------------------- .../filters/KeycloakSessionServletFilter.java | 15 ------ .../filters/KeycloakTransactionCommitter.java | 7 ++- .../keycloak/testsuite/KeycloakServer.java | 5 -- 4 files changed, 5 insertions(+), 70 deletions(-) delete mode 100755 services/src/main/java/org/keycloak/services/filters/ClientConnectionFilter.java diff --git a/services/src/main/java/org/keycloak/services/filters/ClientConnectionFilter.java b/services/src/main/java/org/keycloak/services/filters/ClientConnectionFilter.java deleted file mode 100755 index 8a2ce95f83..0000000000 --- a/services/src/main/java/org/keycloak/services/filters/ClientConnectionFilter.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.keycloak.services.filters; - -import org.jboss.resteasy.spi.ResteasyProviderFactory; -import org.keycloak.common.ClientConnection; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import java.io.IOException; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -@Deprecated -public class ClientConnectionFilter implements Filter { - @Override - public void init(FilterConfig filterConfig) throws ServletException { - } - - @Override - public void doFilter(final ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - ResteasyProviderFactory.pushContext(ClientConnection.class, new ClientConnection() { - @Override - public String getRemoteAddr() { - return request.getRemoteAddr(); - } - - @Override - public String getRemoteHost() { - return request.getRemoteHost(); - } - - @Override - public int getReportPort() { - return request.getRemotePort(); - } - }); - chain.doFilter(request, response); - } - - @Override - public void destroy() { - } -} 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 84684bde31..fb8e14b1d7 100755 --- a/services/src/main/java/org/keycloak/services/filters/KeycloakSessionServletFilter.java +++ b/services/src/main/java/org/keycloak/services/filters/KeycloakSessionServletFilter.java @@ -59,25 +59,10 @@ public class KeycloakSessionServletFilter implements Filter { try { filterChain.doFilter(servletRequest, servletResponse); - if (tx.isActive()) { - if (tx.getRollbackOnly()) tx.rollback(); - else tx.commit(); - } - } catch (IOException ex) { - if (tx.isActive()) tx.rollback(); - throw ex; - } catch (ServletException ex) { - if (tx.isActive()) tx.rollback(); - throw ex; - } - catch (RuntimeException ex) { - if (tx.isActive()) tx.rollback(); - throw new RuntimeException("request path: " + request.getRequestURI(), ex); } finally { session.close(); ResteasyProviderFactory.clearContextData(); } - } @Override diff --git a/services/src/main/java/org/keycloak/services/filters/KeycloakTransactionCommitter.java b/services/src/main/java/org/keycloak/services/filters/KeycloakTransactionCommitter.java index ab3bc1bcbb..9fedcd58d0 100644 --- a/services/src/main/java/org/keycloak/services/filters/KeycloakTransactionCommitter.java +++ b/services/src/main/java/org/keycloak/services/filters/KeycloakTransactionCommitter.java @@ -20,8 +20,11 @@ public class KeycloakTransactionCommitter implements ContainerResponseFilter { public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException { KeycloakTransaction tx = ResteasyProviderFactory.getContextData(KeycloakTransaction.class); if (tx != null && tx.isActive()) { - if (tx.getRollbackOnly()) tx.rollback(); - else tx.commit(); + if (tx.getRollbackOnly()) { + tx.rollback(); + } else { + tx.commit(); + } } } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/KeycloakServer.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/KeycloakServer.java index 308fb67602..9f9d459ce8 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/KeycloakServer.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/KeycloakServer.java @@ -34,7 +34,6 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSessionFactory; import org.keycloak.models.RealmModel; import org.keycloak.representations.idm.RealmRepresentation; -import org.keycloak.services.filters.ClientConnectionFilter; import org.keycloak.services.filters.KeycloakSessionServletFilter; import org.keycloak.services.managers.ApplianceBootstrap; import org.keycloak.services.managers.RealmManager; @@ -318,10 +317,6 @@ public class KeycloakServer { di.addFilter(filter); di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST); - FilterInfo connectionFilter = Servlets.filter("ClientConnectionFilter", ClientConnectionFilter.class); - di.addFilter(connectionFilter); - di.addFilterUrlMapping("ClientConnectionFilter", "/*", DispatcherType.REQUEST); - server.deploy(di); sessionFactory = ((KeycloakApplication) deployment.getApplication()).getSessionFactory();