From b321ba6308a7069d57a4c538f50ccef27d7d8f51 Mon Sep 17 00:00:00 2001 From: Ark2307 Date: Fri, 3 Jan 2025 23:09:27 +0530 Subject: [PATCH] Fixing npe --- .../com/akto/listener/InitializerListener.java | 15 ++++++++------- .../src/main/java/com/akto/utils/OktaLogin.java | 3 ++- .../main/java/com/akto/utils/sso/SsoUtils.java | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java index 5bf7a2bcc1..6e7a7e78c7 100644 --- a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java +++ b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java @@ -2930,13 +2930,14 @@ private static void moveOktaOidcSSO(BackwardCompatibility backwardCompatibility) Config.OktaConfig oktaConfig = (Config.OktaConfig) ConfigsDao.instance.findOne( Filters.eq(Constants.ID, saltId) ); - int accountId = Context.accountId.get(); - oktaConfig.setId(OktaConfig.getOktaId(accountId)); - ConfigsDao.instance.deleteAll( - Filters.eq(Constants.ID, saltId) - ); - - ConfigsDao.instance.insertOne(oktaConfig); + if(oktaConfig != null){ + int accountId = Context.accountId.get(); + oktaConfig.setId(OktaConfig.getOktaId(accountId)); + ConfigsDao.instance.insertOne(oktaConfig); + ConfigsDao.instance.deleteAll( + Filters.eq(Constants.ID, saltId) + ); + } BackwardCompatibilityDao.instance.updateOne( Filters.eq("_id", backwardCompatibility.getId()), Updates.set(BackwardCompatibility.MOVE_OKTA_OIDC_SSO, Context.now()) diff --git a/apps/dashboard/src/main/java/com/akto/utils/OktaLogin.java b/apps/dashboard/src/main/java/com/akto/utils/OktaLogin.java index 317690ae59..320040d9fa 100644 --- a/apps/dashboard/src/main/java/com/akto/utils/OktaLogin.java +++ b/apps/dashboard/src/main/java/com/akto/utils/OktaLogin.java @@ -8,6 +8,7 @@ import com.akto.dao.context.Context; import com.akto.dto.Config; import com.akto.dto.Config.OktaConfig; +import com.akto.util.Constants; import com.akto.utils.sso.SsoUtils; public class OktaLogin { @@ -23,7 +24,7 @@ public static OktaLogin getInstance() { } if (shouldProbeAgain) { - OktaConfig oktaConfig = (Config.OktaConfig) ConfigsDao.instance.findOne("_id", "OKTA-ankush"); + OktaConfig oktaConfig = (Config.OktaConfig) ConfigsDao.instance.findOne(Constants.ID, OktaConfig.getOktaId(Context.accountId.get())); if (instance == null) { instance = new OktaLogin(); } diff --git a/apps/dashboard/src/main/java/com/akto/utils/sso/SsoUtils.java b/apps/dashboard/src/main/java/com/akto/utils/sso/SsoUtils.java index 4f3e3de1e9..b2e4b89254 100644 --- a/apps/dashboard/src/main/java/com/akto/utils/sso/SsoUtils.java +++ b/apps/dashboard/src/main/java/com/akto/utils/sso/SsoUtils.java @@ -36,17 +36,17 @@ public static boolean isAnySsoActive(int accountId){ public static boolean isAnySsoActive(){ int accountId = Context.accountId.get(); + String oktaIdString = OktaConfig.getOktaId(accountId); if(DashboardMode.isMetered() && !DashboardMode.isOnPremDeployment()){ if(!isAnySsoActive(accountId)){ return ConfigsDao.instance.count(Filters.and( - Filters.eq(Constants.ID, "OKTA-ankush"), + Filters.eq(Constants.ID, oktaIdString), Filters.eq(OktaConfig.ACCOUNT_ID, accountId) )) > 0; }else{ return true; } }else{ - String oktaIdString = OktaConfig.getOktaId(accountId); List ssoList = Arrays.asList(oktaIdString, "GITHUB-ankush", "AZURE-ankush"); Bson filter = Filters.in("_id", ssoList); return ConfigsDao.instance.count(filter) > 0;