From 4f725dd73cff4c2673661a3d42c6a32992954502 Mon Sep 17 00:00:00 2001 From: Samin Rahman Date: Tue, 20 Jan 2026 11:39:45 +1100 Subject: [PATCH] Removed unused getOldestClientKey from RotatingClientKeyProvider --- .../uid2/shared/store/IClientKeyProvider.java | 1 - .../reader/RotatingClientKeyProvider.java | 25 ------------- .../auth/RotatingClientKeyProviderTest.java | 35 ------------------- 3 files changed, 61 deletions(-) delete mode 100644 src/test/java/com/uid2/shared/auth/RotatingClientKeyProviderTest.java diff --git a/src/main/java/com/uid2/shared/store/IClientKeyProvider.java b/src/main/java/com/uid2/shared/store/IClientKeyProvider.java index 54082f07..39a79a71 100644 --- a/src/main/java/com/uid2/shared/store/IClientKeyProvider.java +++ b/src/main/java/com/uid2/shared/store/IClientKeyProvider.java @@ -9,5 +9,4 @@ public interface IClientKeyProvider extends IAuthorizableProvider { ClientKey getClientKey(String key); ClientKey getClientKeyFromHash(String hash); Collection getAll(); - ClientKey getOldestClientKey(int siteId); } diff --git a/src/main/java/com/uid2/shared/store/reader/RotatingClientKeyProvider.java b/src/main/java/com/uid2/shared/store/reader/RotatingClientKeyProvider.java index 493a19f5..fb63cfd5 100644 --- a/src/main/java/com/uid2/shared/store/reader/RotatingClientKeyProvider.java +++ b/src/main/java/com/uid2/shared/store/reader/RotatingClientKeyProvider.java @@ -44,10 +44,6 @@ public class RotatingClientKeyProvider implements IClientKeyProvider, StoreReader> { private final ScopedStoreReader> reader; private final AuthorizableStore authorizableStore; - private final ConcurrentHashMap oldestClientKeyBySiteIdCache = new ConcurrentHashMap<>(); - private volatile long snapshotVersion = 0; - - private record VersionedValue(long version, Optional value) {} public RotatingClientKeyProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope) { this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new ClientParser(), "auth keys"); @@ -73,10 +69,6 @@ public long getVersion(JsonObject metadata) { public long loadContent(JsonObject metadata) throws Exception { long version = reader.loadContent(metadata, "client_keys"); authorizableStore.refresh(getAll()); - - // Versioning to prevent race conditions when reading the oldest client key - oldestClientKeyBySiteIdCache.clear(); - snapshotVersion = getVersion(metadata); return version; } @@ -109,21 +101,4 @@ public CloudPath getMetadataPath() { public IAuthorizable get(String key) { return getClientKey(key); } - - @Override - public ClientKey getOldestClientKey(int siteId) { - long currentVersion = snapshotVersion; - VersionedValue cached = oldestClientKeyBySiteIdCache.get(siteId); - - if (cached != null && cached.version() == currentVersion) { - return cached.value().orElse(null); - } - - Optional computed = this.reader.getSnapshot().stream() - .filter(k -> k.getSiteId() == siteId) - .min(Comparator.comparingLong(ClientKey::getCreated)); - - oldestClientKeyBySiteIdCache.put(siteId, new VersionedValue(currentVersion, computed)); - return computed.orElse(null); - } } diff --git a/src/test/java/com/uid2/shared/auth/RotatingClientKeyProviderTest.java b/src/test/java/com/uid2/shared/auth/RotatingClientKeyProviderTest.java deleted file mode 100644 index e0f7f4c6..00000000 --- a/src/test/java/com/uid2/shared/auth/RotatingClientKeyProviderTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.uid2.shared.auth; - -import com.uid2.shared.cloud.EmbeddedResourceStorage; -import com.uid2.shared.store.CloudPath; -import com.uid2.shared.store.reader.RotatingClientKeyProvider; -import com.uid2.shared.store.scope.GlobalScope; -import io.vertx.core.json.JsonObject; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; -import static org.assertj.core.api.Assertions.assertThat; - -public class RotatingClientKeyProviderTest { - @Test - public void testGetOldestClientKeyBySiteId() throws Exception { - RotatingClientKeyProvider provider = new RotatingClientKeyProvider( - new EmbeddedResourceStorage(RotatingClientKeyProviderTest.class), - new GlobalScope(new CloudPath("/com.uid2.shared/test/clients/metadata.json"))); - - JsonObject metadata = provider.getMetadata(); - provider.loadContent(metadata); - assertEquals(1, provider.getVersion(metadata)); - - // a site that has multiple client keys - ClientKey expected = provider.getClientKey("trusted-partner-key"); - assertNotNull(expected); - ClientKey actual = provider.getOldestClientKey(expected.getSiteId()); - assertNotNull(actual); - assertThat(actual).isEqualTo(expected); - - // a site that doesn't have client keys - actual = provider.getOldestClientKey(1234567890); - assertNull(actual); - } -}