From 0712fc32b038ec4fe053fa948fec7b4ca7dd1596 Mon Sep 17 00:00:00 2001 From: notshivansh Date: Wed, 26 Jun 2024 17:17:50 +0530 Subject: [PATCH] fix for multiple accounts --- .../main/java/com/akto/utils/RedactAlert.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/database-abstractor/src/main/java/com/akto/utils/RedactAlert.java b/apps/database-abstractor/src/main/java/com/akto/utils/RedactAlert.java index aae55b6b98..bc2d6dd9e8 100644 --- a/apps/database-abstractor/src/main/java/com/akto/utils/RedactAlert.java +++ b/apps/database-abstractor/src/main/java/com/akto/utils/RedactAlert.java @@ -1,6 +1,8 @@ package com.akto.utils; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.regex.Pattern; @@ -23,28 +25,31 @@ public class RedactAlert { static final Pattern pattern = Pattern.compile(regex); private static final int CACHE_INTERVAL = 2 * 60; - private static int lastFetched = 0; - private static boolean isRedactOn = false; + private static Map lastFetchedMap = new HashMap<>(); + private static Map redactMap = new HashMap<>(); private static boolean checkRedact() { int now = Context.now(); - if (lastFetched + CACHE_INTERVAL > now) { - return isRedactOn; + int accountId = Context.accountId.get(); + if (redactMap.containsKey(accountId) && + lastFetchedMap.containsKey(accountId) && + lastFetchedMap.get(accountId) + CACHE_INTERVAL > now) { + return redactMap.get(accountId); } - isRedactOn = false; + redactMap.put(accountId, false); AccountSettings accountSettings = AccountSettingsDao.instance.findOne(AccountSettingsDao.generateFilter()); List all = ApiCollectionsDao.instance.findAll(new BasicDBObject()); for (ApiCollection apiCollection : all) { if (apiCollection.getRedact()) { - isRedactOn = true; + redactMap.put(accountId, true); } } if (accountSettings.isRedactPayload()) { - isRedactOn = true; + redactMap.put(accountId, true); } - lastFetched = now; - return isRedactOn; + lastFetchedMap.put(accountId, now); + return redactMap.get(accountId); } public static void sendToCyborgSlack(String message) {