diff --git a/src/main/java/com/salessparrow/api/config/CoreConstants.java b/src/main/java/com/salessparrow/api/config/CoreConstants.java index 24bebb94..eafb853d 100644 --- a/src/main/java/com/salessparrow/api/config/CoreConstants.java +++ b/src/main/java/com/salessparrow/api/config/CoreConstants.java @@ -79,6 +79,10 @@ public static String defaultTestUserPassword() { return SecretConstants.defaultTestUserPassword(); } + public static String defaultTestUserCode() { + return "test_12341234"; + } + /** * This method returns the memcached address that is going to be used for locals * @return String diff --git a/src/main/java/com/salessparrow/api/lib/globalConstants/CacheConstants.java b/src/main/java/com/salessparrow/api/lib/globalConstants/CacheConstants.java index 9827578f..3ea8be41 100644 --- a/src/main/java/com/salessparrow/api/lib/globalConstants/CacheConstants.java +++ b/src/main/java/com/salessparrow/api/lib/globalConstants/CacheConstants.java @@ -6,34 +6,34 @@ @Component public class CacheConstants { - public static final String CACHE_SUFFIX; + public static final String CACHE_SUFFIX = getCacheSuffix(); - static { + public static final String SALESFORCE_USER_CACHE = "sf_user"; + + public static final Integer SALESFORCE_USER_CACHE_EXP = 30 * 24 * 60 * 60; // 30 + // days + + public static final String SALESFORCE_OAUTH_TOKEN_CACHE = "sf_oauth_token"; + + public static final Integer SALESFORCE_OAUTH_TOKEN_CACHE_EXP = 30 * 24 * 60 * 60; // 30 + // days + + public static String getCacheSuffix() { if (CoreConstants.isProductionEnvironment()) { - CACHE_SUFFIX = "_prod"; + return "_prod"; } else if (CoreConstants.isStagingEnvironment()) { - CACHE_SUFFIX = "_stag"; + return "_stag"; } else if (CoreConstants.isTestEnvironment()) { - CACHE_SUFFIX = "_test"; + return "_test"; } else if (CoreConstants.isLocalTestEnvironment()) { - CACHE_SUFFIX = "_ltest"; + return "_ltest"; } else { - CACHE_SUFFIX = "_dev"; + return "_dev"; } } - public static final String SALESFORCE_USER_CACHE = "sf_user"; - - public static final Integer SALESFORCE_USER_CACHE_EXP = 30 * 24 * 60 * 60; // 30 - // days - - public static final String SALESFORCE_OAUTH_TOKEN_CACHE = "sf_oauth_token"; - - public static final Integer SALESFORCE_OAUTH_TOKEN_CACHE_EXP = 30 * 24 * 60 * 60; // 30 - // days - } diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceRequest.java b/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceRequest.java index 3f892dbb..72d5dda2 100644 --- a/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceRequest.java +++ b/src/main/java/com/salessparrow/api/lib/salesforce/helper/SalesforceRequest.java @@ -7,7 +7,6 @@ import com.salessparrow.api.domain.SalesforceOauthToken; import com.salessparrow.api.exception.CustomException; import com.salessparrow.api.lib.errorLib.ErrorObject; -import com.salessparrow.api.lib.httpLib.HttpClient; import com.salessparrow.api.repositories.SalesforceOauthTokenRepository; import org.slf4j.Logger; diff --git a/src/main/java/com/salessparrow/api/lib/salesforce/wrappers/SalesforceTokens.java b/src/main/java/com/salessparrow/api/lib/salesforce/wrappers/SalesforceTokens.java index a152e0f6..a1030a19 100644 --- a/src/main/java/com/salessparrow/api/lib/salesforce/wrappers/SalesforceTokens.java +++ b/src/main/java/com/salessparrow/api/lib/salesforce/wrappers/SalesforceTokens.java @@ -38,15 +38,16 @@ public HttpResponse getTokens(String code, String redirectUri, Boolean isTestUse String requestBody; if (!isTestUser) { - requestBody = "grant_type=" + salesforceConstants.authorizationCodeGrantType() + "&client_id=" - + CoreConstants.salesforceClientId() + "&client_secret=" + CoreConstants.salesforceClientSecret() - + "&code=" + code + "&redirect_uri=" + redirectUri; + requestBody = String.format("grant_type=%s&client_id=%s&client_secret=%s&code=%s&redirect_uri=%s", + salesforceConstants.authorizationCodeGrantType(), CoreConstants.salesforceClientId(), + CoreConstants.salesforceClientSecret(), code, redirectUri); } else { - requestBody = "grant_type=" + salesforceConstants.passwordGrantType() + "&client_id=" - + CoreConstants.salesforceClientId() + "&client_secret=" + CoreConstants.salesforceClientSecret() - + "&username=" + CoreConstants.defaultTestUser() + "&password=" - + CoreConstants.defaultTestUserPassword() + "&redirect_uri=" + redirectUri; + requestBody = String.format( + "grant_type=%s&client_id=%s&client_secret=%s&username=%s&password=%s&redirect_uri=%s", + salesforceConstants.passwordGrantType(), CoreConstants.salesforceClientId(), + CoreConstants.salesforceClientSecret(), CoreConstants.defaultTestUser(), + CoreConstants.defaultTestUserPassword(), redirectUri); } Map headers = new HashMap<>(); diff --git a/src/main/java/com/salessparrow/api/services/salesforce/AuthService.java b/src/main/java/com/salessparrow/api/services/salesforce/AuthService.java index 92b32978..6a7d6a87 100644 --- a/src/main/java/com/salessparrow/api/services/salesforce/AuthService.java +++ b/src/main/java/com/salessparrow/api/services/salesforce/AuthService.java @@ -30,7 +30,6 @@ import com.salessparrow.api.repositories.SalesforceOrganizationRepository; import com.salessparrow.api.repositories.SalesforceUserRepository; import jakarta.servlet.http.HttpServletRequest; -import software.amazon.awssdk.services.secretsmanager.endpoints.internal.Value.Bool; @Service public class AuthService { @@ -94,7 +93,7 @@ public AuthServiceDto connectToSalesforce(SalesforceConnectDto params, HttpServl this.isNewUser = true; // setting default value true to this variable, this will // be updated based on conditions in further processing - String testUserCode = "test_12341234"; + String testUserCode = CoreConstants.defaultTestUserCode(); Boolean isTestUser = false; code = params.getCode();