Skip to content

Commit

Permalink
Fixing saving of id
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark2307 committed Jan 3, 2025
1 parent 4710d70 commit 66c867d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import java.util.ArrayList;

import org.yaml.snakeyaml.scanner.Constant;
import org.bson.conversions.Bson;

import com.akto.action.UserAction;
import com.akto.dao.ConfigsDao;
import com.akto.dao.UsersDao;
import com.akto.dao.context.Context;
import com.akto.dto.Config;
import com.akto.dto.User;
import com.akto.dto.Config.ConfigType;
import com.akto.dto.Config.OktaConfig;
import com.akto.util.Constants;
import com.akto.util.DashboardMode;
import com.akto.utils.sso.SsoUtils;
Expand All @@ -33,7 +33,9 @@ public String addOktaSso() {
return ERROR.toUpperCase();
}

Config.OktaConfig oktaConfig = new Config.OktaConfig();
int accountId = Context.accountId.get();

Config.OktaConfig oktaConfig = new Config.OktaConfig(accountId);
oktaConfig.setClientId(clientId);
oktaConfig.setClientSecret(clientSecret);
oktaConfig.setAuthorisationServerId(authorisationServerId);
Expand All @@ -51,17 +53,9 @@ public String addOktaSso() {
}

public String deleteOktaSso() {
DeleteResult result;
if(DashboardMode.isOnPremDeployment()) {
result = ConfigsDao.instance.deleteAll(Filters.eq("_id", "OKTA-ankush"));
} else {
result = ConfigsDao.instance.deleteAll(
Filters.and(
Filters.eq("_id", "OKTA-ankush"),
Filters.eq(Config.OktaConfig.ACCOUNT_ID, Context.accountId.get())
)
);
}
int accountId = Context.accountId.get();
Bson idFilter = Filters.eq(Constants.ID, OktaConfig.getOktaId(accountId));
DeleteResult result = ConfigsDao.instance.deleteAll(idFilter);

if (result.getDeletedCount() > 0) {
for (Object obj : UsersDao.instance.getAllUsersInfoForTheAccount(Context.accountId.get())) {
Expand All @@ -76,14 +70,9 @@ public String deleteOktaSso() {

@Override
public String execute() throws Exception {
Config.OktaConfig oktaConfig;
if(DashboardMode.isOnPremDeployment()) {
int accountId = Context.accountId.get();
oktaConfig = (Config.OktaConfig) ConfigsDao.instance.findOne(Constants.ID, ConfigType.OKTA.name() + "_" + accountId);
} else {
String email = getSUser().getLogin();
oktaConfig = Config.getOktaConfig(email);
}
int accountId = Context.accountId.get();
Config.OktaConfig oktaConfig = (Config.OktaConfig) ConfigsDao.instance.findOne(Constants.ID, OktaConfig.getOktaId(accountId));

if (SsoUtils.isAnySsoActive() && oktaConfig == null) {
addActionError("A different SSO Integration already exists.");
return ERROR.toUpperCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.akto.dto.ApiCollectionUsers.CollectionType;
import com.akto.dto.Config.AzureConfig;
import com.akto.dto.Config.ConfigType;
import com.akto.dto.Config.OktaConfig;
import com.akto.dto.RBAC.Role;
import com.akto.dto.User.AktoUIMode;
import com.akto.dto.data_types.Conditions;
Expand Down Expand Up @@ -2930,7 +2931,7 @@ private static void moveOktaOidcSSO(BackwardCompatibility backwardCompatibility)
Filters.eq(Constants.ID, saltId)
);
int accountId = Context.accountId.get();
oktaConfig.setId(saltId + "_" + accountId);
oktaConfig.setId(OktaConfig.getOktaId(accountId));
ConfigsDao.instance.deleteAll(
Filters.eq(Constants.ID, saltId)
);
Expand Down
5 changes: 3 additions & 2 deletions apps/dashboard/src/main/java/com/akto/utils/sso/SsoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static boolean isAnySsoActive(int accountId){
}

public static boolean isAnySsoActive(){
int accountId = Context.accountId.get();
if(DashboardMode.isMetered() && !DashboardMode.isOnPremDeployment()){
int accountId = Context.accountId.get();
if(!isAnySsoActive(accountId)){
return ConfigsDao.instance.count(Filters.and(
Filters.eq(Constants.ID, "OKTA-ankush"),
Expand All @@ -46,7 +46,8 @@ public static boolean isAnySsoActive(){
return true;
}
}else{
List<String> ssoList = Arrays.asList("OKTA-ankush", "GITHUB-ankush", "AZURE-ankush");
String oktaIdString = OktaConfig.getOktaId(accountId);
List<String> ssoList = Arrays.asList(oktaIdString, "GITHUB-ankush", "AZURE-ankush");
Bson filter = Filters.in("_id", ssoList);
return ConfigsDao.instance.count(filter) > 0;
}
Expand Down
14 changes: 11 additions & 3 deletions libs/dao/src/main/java/com/akto/dto/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,17 @@ public static class OktaConfig extends Config {

public static final String CONFIG_ID = ConfigType.OKTA.name() + CONFIG_SALT;

public OktaConfig() {
public OktaConfig(){
this.configType = ConfigType.OKTA;
this.id = CONFIG_ID + "_" + this.accountId;
}

public static String getOktaId(int accountId){
return CONFIG_ID + "_" + accountId;
}

public OktaConfig(int id) {
this.configType = ConfigType.OKTA;
this.id = CONFIG_ID + "_" + id;
}

public String getClientId() {
Expand Down Expand Up @@ -686,7 +694,7 @@ public static boolean isConfigSSOType(ConfigType configType){
}

public static OktaConfig getOktaConfig(int accountId) {
String id = ConfigType.OKTA.name() + CONFIG_SALT + "_" + accountId;
String id = OktaConfig.getOktaId(accountId);
OktaConfig config = (OktaConfig) ConfigsDao.instance.findOne(
Filters.and(
Filters.eq("_id", id),
Expand Down

0 comments on commit 66c867d

Please sign in to comment.