Added jax-rs response filter to commit transaction

This commit is contained in:
Stian Thorgersen 2016-01-15 15:50:38 +01:00
parent 435980d776
commit 33565ff8d9
2 changed files with 31 additions and 0 deletions

View file

@ -0,0 +1,28 @@
/*
*/
package org.keycloak.services.filters;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.models.KeycloakTransaction;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import java.io.IOException;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class KeycloakTransactionCommitter implements ContainerResponseFilter {
@Override
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();
}
}
}

View file

@ -15,6 +15,7 @@ import org.keycloak.models.utils.RepresentationToModel;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.services.DefaultKeycloakSessionFactory;
import org.keycloak.services.filters.KeycloakTransactionCommitter;
import org.keycloak.services.managers.ApplianceBootstrap;
import org.keycloak.services.managers.BruteForceProtector;
import org.keycloak.services.managers.RealmManager;
@ -75,6 +76,8 @@ public class KeycloakApplication extends Application {
classes.add(ThemeResource.class);
classes.add(JsResource.class);
classes.add(KeycloakTransactionCommitter.class);
singletons.add(new ObjectMapperResolver(Boolean.parseBoolean(System.getProperty("keycloak.jsonPrettyPrint", "false"))));
migrateModel();