diff --git a/model/storage-private/src/main/java/org/keycloak/storage/managers/UserStorageSyncManager.java b/model/storage-private/src/main/java/org/keycloak/storage/managers/UserStorageSyncManager.java index e9d46bd8b9..1b58186da2 100755 --- a/model/storage-private/src/main/java/org/keycloak/storage/managers/UserStorageSyncManager.java +++ b/model/storage-private/src/main/java/org/keycloak/storage/managers/UserStorageSyncManager.java @@ -207,7 +207,7 @@ public class UserStorageSyncManager { if (provider.getFullSyncPeriod() > 0) { // schedule periodic full sync for this provider UserStorageSyncTask task = new UserStorageSyncTask(provider, realm, sessionFactory, UserStorageSyncTask.SyncMode.FULL); - timer.schedule(task, provider.getFullSyncPeriod() * 1000, fullSyncTaskName); + timer.schedule(task, provider.getFullSyncPeriod() * 1000L, fullSyncTaskName); } else { // cancel potentially dangling task timer.cancelTask(fullSyncTaskName); @@ -217,7 +217,7 @@ public class UserStorageSyncManager { if (provider.getChangedSyncPeriod() > 0) { // schedule periodic changed user sync for this provider UserStorageSyncTask task = new UserStorageSyncTask(provider, realm, sessionFactory, UserStorageSyncTask.SyncMode.CHANGED); - timer.schedule(task, provider.getChangedSyncPeriod() * 1000, changedSyncTaskName); + timer.schedule(task, provider.getChangedSyncPeriod() * 1000L, changedSyncTaskName); } else { // cancel potentially dangling task timer.cancelTask(changedSyncTaskName); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/sync/SyncFederationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/sync/SyncFederationTest.java index 8394570adf..0be94dc778 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/sync/SyncFederationTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/sync/SyncFederationTest.java @@ -365,6 +365,47 @@ public class SyncFederationTest extends AbstractAuthTest { }); } + @Test + public void test05LongSync() throws Exception { + // Add IgnoredDummyUserFederationProviderFactory provider + testingClient.server().run(session -> { + RealmModel appRealm = session.realms().getRealmByName(AuthRealm.TEST); + UserStorageProviderModel model = new UserStorageProviderModel(); + model.setProviderId(IgnoredDummyUserFederationProviderFactory.IGNORED_PROVIDER_ID); + model.setPriority(1); + model.setName("test-sync-dummy"); + model.setFullSyncPeriod(2147484); + model.setChangedSyncPeriod(2147484); + model.setLastSync(0); + appRealm.addComponentModel(model); + }); + + // run both sync methods that will be ignored + testingClient.server().run(session -> { + RealmModel appRealm = session.realms().getRealmByName(AuthRealm.TEST); + UserStorageProviderModel dummyModel = findDummyProviderModel(appRealm); + KeycloakSessionFactory sessionFactory = session.getKeycloakSessionFactory(); + SynchronizationResult syncResult = UserStorageSyncManager.syncAllUsers(sessionFactory, appRealm.getId(), dummyModel); + Assert.assertTrue(syncResult.isIgnored()); + syncResult = UserStorageSyncManager.syncChangedUsers(sessionFactory, appRealm.getId(), dummyModel); + Assert.assertTrue(syncResult.isIgnored()); + }); + + // assert the last sync is not updated + testingClient.server().run(session -> { + RealmModel appRealm = session.realms().getRealmByName(AuthRealm.TEST); + UserStorageProviderModel dummyModel = findDummyProviderModel(appRealm); + Assert.assertEquals(0, dummyModel.getLastSync()); + }); + + // remove provider + testingClient.server().run(session -> { + RealmModel appRealm = session.realms().getRealmByName(AuthRealm.TEST); + UserStorageProviderModel dummyModel = findDummyProviderModel(appRealm); + appRealm.removeComponent(dummyModel); + }); + } + private static void sleep(long ms) { try { log.infof("Sleeping for %d ms", ms);