fix integer overflow with explicit cast

Closes #28564

Signed-off-by: tqe1999 <tqe1999@gmail.com>
This commit is contained in:
tqe1999 2024-04-11 16:58:44 +08:00 committed by GitHub
parent 9b94b6f47e
commit 6e0fc8a774
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 2 deletions

View file

@ -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);

View file

@ -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);