Merge pull request #2113 from stianst/KEYCLOAK-2327
KEYCLOAK-2327 Make sure transaction is only committed or rolledback before response is returned
This commit is contained in:
commit
301b61c4f9
4 changed files with 5 additions and 70 deletions
|
@ -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 <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @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() {
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue