From 8ba7559cac62df47f586863b7b846e2ff2322fd6 Mon Sep 17 00:00:00 2001 From: mposolda Date: Mon, 11 Aug 2014 13:51:44 +0200 Subject: [PATCH] Fix transaction handling in KeycloakModelUtils.runJobInTransaction. Start sync tasks for configured federation providers at startup --- .../java/org/keycloak/models/utils/KeycloakModelUtils.java | 4 +++- .../org/keycloak/services/resources/KeycloakApplication.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/model/api/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java b/model/api/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java index 2f329b7858..3e8695c7df 100755 --- a/model/api/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java +++ b/model/api/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java @@ -156,10 +156,12 @@ public final class KeycloakModelUtils { tx.commit(); } } - } finally { + } catch (RuntimeException re) { if (tx.isActive()) { tx.rollback(); } + throw re; + } finally { session.close(); } } diff --git a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java index ca8db44e4c..27f9a2fdaa 100755 --- a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java +++ b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java @@ -15,6 +15,7 @@ import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.services.DefaultKeycloakSessionFactory; import org.keycloak.services.managers.ApplianceBootstrap; import org.keycloak.services.managers.BruteForceProtector; +import org.keycloak.services.managers.PeriodicSyncManager; import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.TokenManager; import org.keycloak.services.resources.admin.AdminRoot; @@ -148,6 +149,7 @@ public class KeycloakApplication extends Application { TimerProvider timer = sessionFactory.create().getProvider(TimerProvider.class); timer.schedule(new ScheduledTaskRunner(sessionFactory, new ClearExpiredAuditEvents()), interval, "ClearExpiredAuditEvents"); timer.schedule(new ScheduledTaskRunner(sessionFactory, new ClearExpiredUserSessions()), interval, "ClearExpiredUserSessions"); + new PeriodicSyncManager().bootstrap(sessionFactory, timer); } public KeycloakSessionFactory getSessionFactory() {