From 30ebddc9048ee3a4727f821201dd814f590cf9ba Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 1 Mar 2024 08:52:23 +0000 Subject: [PATCH] Fix concurrency issues in secret manager --- .../java/io/xpipe/app/util/SecretManager.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/util/SecretManager.java b/app/src/main/java/io/xpipe/app/util/SecretManager.java index 01896ed52..3b75795be 100644 --- a/app/src/main/java/io/xpipe/app/util/SecretManager.java +++ b/app/src/main/java/io/xpipe/app/util/SecretManager.java @@ -13,7 +13,7 @@ public class SecretManager { private static final Map secrets = new HashMap<>(); private static final Set progress = new HashSet<>(); - public static Optional getProgress(UUID requestId, UUID storeId) { + public static synchronized Optional getProgress(UUID requestId, UUID storeId) { return progress.stream() .filter(secretQueryProgress -> secretQueryProgress.getRequestId().equals(requestId) @@ -21,14 +21,14 @@ public class SecretManager { .findFirst(); } - public static Optional getProgress(UUID requestId) { + public static synchronized Optional getProgress(UUID requestId) { return progress.stream() .filter(secretQueryProgress -> secretQueryProgress.getRequestId().equals(requestId)) .findFirst(); } - public static SecretQueryProgress expectElevationPrompt( + public static synchronized SecretQueryProgress expectElevationPrompt( UUID request, UUID secretId, CountDown countDown, boolean askIfNeeded) { var p = new SecretQueryProgress( request, @@ -40,7 +40,7 @@ public class SecretManager { return p; } - public static SecretQueryProgress expectAskpass( + public static synchronized SecretQueryProgress expectAskpass( UUID request, UUID storeId, List suppliers, SecretQuery fallback, CountDown countDown) { var p = new SecretQueryProgress(request, storeId, suppliers, fallback, countDown); progress.add(p); @@ -69,7 +69,7 @@ public class SecretManager { return r; } - public static void completeRequest(UUID request) { + public static synchronized void completeRequest(UUID request) { if (progress.removeIf( secretQueryProgress -> secretQueryProgress.getRequestId().equals(request))) { TrackEvent.withTrace("Completed secret request") @@ -78,22 +78,22 @@ public class SecretManager { } } - public static void clearAll(Object store) { + public static synchronized void clearAll(Object store) { var id = UuidHelper.generateFromObject(store); secrets.entrySet() .removeIf(secretReferenceSecretValueEntry -> secretReferenceSecretValueEntry.getKey().getSecretId().equals(id)); } - public static void clear(SecretReference ref) { + public static synchronized void clear(SecretReference ref) { secrets.remove(ref); } - public static void set(SecretReference ref, SecretValue value) { + public static synchronized void set(SecretReference ref, SecretValue value) { secrets.put(ref, value); } - public static Optional get(SecretReference ref) { + public static synchronized Optional get(SecretReference ref) { return Optional.ofNullable(secrets.get(ref)); } }