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..c1832aca0b 100644 --- a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java +++ b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java @@ -2930,17 +2930,18 @@ 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); - BackwardCompatibilityDao.instance.updateOne( - Filters.eq("_id", backwardCompatibility.getId()), - Updates.set(BackwardCompatibility.MOVE_OKTA_OIDC_SSO, Context.now()) - ); + 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;