diff --git a/apps/dashboard/src/main/java/com/akto/action/AccountAction.java b/apps/dashboard/src/main/java/com/akto/action/AccountAction.java index 2a35c17a8d..1fa2522eae 100644 --- a/apps/dashboard/src/main/java/com/akto/action/AccountAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/AccountAction.java @@ -276,8 +276,7 @@ public String createNewAccount() { } public static User initializeAccount(String email, int newAccountId, String newAccountName, boolean isNew, RBAC.Role role) { - UsersDao.addAccount(email, newAccountId, newAccountName); - User user = UsersDao.instance.findOne(eq(User.LOGIN, email)); + User user = UsersDao.addAccount(email, newAccountId, newAccountName); RBACDao.instance.insertOne(new RBAC(user.getId(), role, newAccountId)); Context.accountId.set(newAccountId); try { diff --git a/apps/dashboard/src/main/java/com/akto/action/ProfileAction.java b/apps/dashboard/src/main/java/com/akto/action/ProfileAction.java index 0de65672ab..2bcd2b2256 100644 --- a/apps/dashboard/src/main/java/com/akto/action/ProfileAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/ProfileAction.java @@ -118,7 +118,10 @@ public static void executeMeta1(Utility utility, User user, HttpServletRequest r if(currAccount != null && !currAccount.getTimezone().isEmpty()){ timeZone = currAccount.getTimezone(); } - String dashboardVersion = accountSettings.getDashboardVersion(); + String dashboardVersion = ""; + if(accountSettings != null){ + dashboardVersion = accountSettings.getDashboardVersion(); + } String[] versions = dashboardVersion.split(" - "); User userFromDB = UsersDao.instance.findOne(Filters.eq(Constants.ID, user.getId())); RBAC.Role userRole = RBACDao.getCurrentRoleForUser(user.getId(), Context.accountId.get()); diff --git a/apps/dashboard/src/main/java/com/akto/action/SignupAction.java b/apps/dashboard/src/main/java/com/akto/action/SignupAction.java index d36d1656ab..587a297ea3 100644 --- a/apps/dashboard/src/main/java/com/akto/action/SignupAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/SignupAction.java @@ -86,7 +86,7 @@ public class SignupAction implements Action, ServletResponseAware, ServletReques public static final String BUSINESS_EMAIL_REQUIRED_ERROR = "BUSINESS_EMAIL_REQUIRED"; public static final String ERROR_STR = "error"; public static final String ERROR_DESCRIPTION = "error_description"; - private static final Logger logger = LoggerFactory.getLogger(ProfileAction.class); + private static final Logger logger = LoggerFactory.getLogger(SignupAction.class); private static final LoggerMaker loggerMaker = new LoggerMaker(SignupAction.class); public String getCode() { 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 c88ed2a3ea..87640d0e78 100644 --- a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java +++ b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java @@ -595,7 +595,10 @@ public static void executePIISourceFetch() { (existingCDT != null && existingCDT.getDataTypePriority() != null) && (existingCDT.getCategoriesList() != null && !existingCDT.getCategoriesList().isEmpty()); - boolean userHasChangedCondition = existingCDT.getUserModifiedTimestamp() > 0; + boolean userHasChangedCondition = false; + if(existingCDT != null && existingCDT.getUserModifiedTimestamp() > 0){ + userHasChangedCondition = true; + } if (userHasChangedCondition || hasNotChangedCondition) { continue; @@ -2451,26 +2454,24 @@ public static void insertPiiSources(){ static boolean executedOnce = false; - private final static int REFRESH_INTERVAL = 60 * 1; // 1 minute + private final static int REFRESH_INTERVAL = 60 * 15; // 15 minute public static Organization fetchAndSaveFeatureWiseAllowed(Organization organization) { - + + int lastFeatureMapUpdate = organization.getLastFeatureMapUpdate(); + if((lastFeatureMapUpdate + REFRESH_INTERVAL) >= Context.now()){ + return organization; + } HashMap featureWiseAllowed = new HashMap<>(); try { int gracePeriod = organization.getGracePeriod(); String hotjarSiteId = organization.getHotjarSiteId(); String organizationId = organization.getId(); - - int lastFeatureMapUpdate = organization.getLastFeatureMapUpdate(); - /* * This ensures, we don't fetch feature wise allowed from akto too often. * This helps the dashboard to be more responsive. */ - if(lastFeatureMapUpdate + REFRESH_INTERVAL > Context.now()){ - return organization; - } HashMap initialFeatureWiseAllowed = organization.getFeatureWiseAllowed(); if (initialFeatureWiseAllowed == null) { diff --git a/apps/dashboard/src/main/java/com/akto/utils/Token.java b/apps/dashboard/src/main/java/com/akto/utils/Token.java index 5adf6df529..f829974188 100644 --- a/apps/dashboard/src/main/java/com/akto/utils/Token.java +++ b/apps/dashboard/src/main/java/com/akto/utils/Token.java @@ -29,8 +29,8 @@ public static String generateAccessToken(String username, String signedUp) throw claims, "Akto", "login", - Calendar.MINUTE, - 15 + Calendar.HOUR, + 2 ); } diff --git a/libs/dao/src/main/java/com/akto/dao/UsersDao.java b/libs/dao/src/main/java/com/akto/dao/UsersDao.java index 5a5a04b178..8c18af835b 100644 --- a/libs/dao/src/main/java/com/akto/dao/UsersDao.java +++ b/libs/dao/src/main/java/com/akto/dao/UsersDao.java @@ -1,11 +1,15 @@ package com.akto.dao; +import com.akto.dao.context.Context; import com.akto.dto.*; import com.mongodb.BasicDBList; import com.mongodb.BasicDBObject; import com.mongodb.client.MongoCursor; import com.mongodb.client.model.Filters; +import com.mongodb.client.model.FindOneAndUpdateOptions; +import com.mongodb.client.model.ReturnDocument; import com.mongodb.client.model.Sorts; +import com.mongodb.client.model.Updates; import java.util.Collection; import java.util.HashMap; @@ -40,9 +44,14 @@ public static User addUser(String login, String name, String password, boolean e return null; } - public static void addAccount(String login, int accountId, String name) { + public static User addAccount(String login, int accountId, String name) { BasicDBObject setQ = new BasicDBObject(User.ACCOUNTS + "." + accountId,new UserAccountEntry(accountId, name)); - UsersDao.instance.getMCollection().updateOne(eq(User.LOGIN, login), new BasicDBObject(SET, setQ)); + + User tempUser = UsersDao.instance.getMCollection().findOneAndUpdate( + eq(User.LOGIN, login), new BasicDBObject(SET, setQ), + new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER) + ); + return tempUser; } public static void addNewAccount(String login, Account account){ diff --git a/libs/utils/src/main/java/com/akto/stigg/StiggReporterClient.java b/libs/utils/src/main/java/com/akto/stigg/StiggReporterClient.java index 4d0257f492..bcd382fa71 100644 --- a/libs/utils/src/main/java/com/akto/stigg/StiggReporterClient.java +++ b/libs/utils/src/main/java/com/akto/stigg/StiggReporterClient.java @@ -50,6 +50,7 @@ private String executeGraphQL(String query, String vars) throws IllegalStateExce if (stiggConfig == null) { throw new IllegalStateException("Stigg config is not initialised"); } + int timeNow = Context.now(); String requestBody = String.format("{\"query\":\"%s\",\"variables\":%s}", query, vars); // Set the GraphQL endpoint URL @@ -67,12 +68,18 @@ private String executeGraphQL(String query, String vars) throws IllegalStateExce // Execute the request and get the response try (Response response = client.newCall(request).execute()) { + String[] queryTypes = query.split("("); + String queryString = queryTypes[0]; + if (!response.isSuccessful()) { throw new IOException("Unexpected response code: " + response); } - String responseBodyStr = response.body().string(); + loggerMaker.infoAndAddToDb("Time taken by stigg call for query: "+ queryString + " is: " + (Context.now() - timeNow)); + + timeNow = Context.now(); BasicDBObject responseBodyObj = BasicDBObject.parse(responseBodyStr); + loggerMaker.infoAndAddToDb("Time taken by parsing response for query: "+ queryString + " is: " + (Context.now() - timeNow)); return responseBodyObj.toJson(); } catch (Exception e) { return new BasicDBObject("err", e.getMessage()).toJson();