diff --git a/pom.xml b/pom.xml index 197b403..553fc0c 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ - 2.4.2-SNAPSHOT + 2.4.1 2.22.0 2.22.0 3.14.0 @@ -124,5 +124,10 @@ ion-java 1.11.9 + + com.auth0 + java-jwt + 4.4.0 + diff --git a/src/main/java/apiCalls/Utils/generic/BaseAPI.java b/src/main/java/apiCalls/Utils/generic/BaseAPI.java index 9dc84da..ad65973 100644 --- a/src/main/java/apiCalls/Utils/generic/BaseAPI.java +++ b/src/main/java/apiCalls/Utils/generic/BaseAPI.java @@ -2,6 +2,7 @@ import activesupport.http.RestUtils; import activesupport.system.Properties; +import activesupport.aws.s3.SecretsManager; import apiCalls.actions.Token; import com.auth0.jwt.JWT; import com.auth0.jwt.exceptions.JWTDecodeException; @@ -25,8 +26,8 @@ public class BaseAPI extends Token { static Headers headers = new Headers(); public synchronized String adminJWT() throws HttpException { - String adminUser = SecretsManager.getSecret("adminUser"); - String adminPassword = SecretsManager.getSecret("adminPassword"); + String adminUser = SecretsManager.getSecretValue("adminUser"); + String adminPassword = SecretsManager.getSecretValue("adminPassword"); if (getAdminToken() == null || isTokenExpired(getAdminToken())) { LOGGER.info("Generating new admin token"); diff --git a/src/main/java/apiCalls/Utils/generic/SecretsManager.java b/src/main/java/apiCalls/Utils/generic/SecretsManager.java deleted file mode 100644 index 76df58b..0000000 --- a/src/main/java/apiCalls/Utils/generic/SecretsManager.java +++ /dev/null @@ -1,55 +0,0 @@ -package apiCalls.Utils.generic; - -import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.secretsmanager.AWSSecretsManager; -import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder; -import com.amazonaws.services.secretsmanager.model.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.json.JSONObject; - -public class SecretsManager { - - public static String secretsId = "OLCS-DEVAPPCI-DEVCI-BATCHTESTRUNNER-MAIN-APPLICATION"; - - private static final Logger LOGGER = LogManager.getLogger(SecretsManager.class); - - public static AWSSecretsManager awsClientSetup(){ - Regions region = Regions.EU_WEST_1; - return AWSSecretsManagerClientBuilder - .standard() - .withCredentials(new DefaultAWSCredentialsProviderChain()) - .withRegion(region) - .build(); - } - - public static String getSecret(String secretKey) { - String secret = null; - - GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest() - .withSecretId(secretsId); - GetSecretValueResult getSecretValueResult = null; - - try { - getSecretValueResult = awsClientSetup().getSecretValue(getSecretValueRequest); - - } catch (ResourceNotFoundException e) { - LOGGER.info("The requested secret " + secretKey + " was not found"); - } catch (InvalidRequestException e) { - LOGGER.info("The request was invalid due to: " + e.getMessage()); - } catch (InvalidParameterException e) { - LOGGER.info("The request had invalid params: " + e.getMessage()); - } - - assert getSecretValueResult != null; - - if (getSecretValueResult != null && getSecretValueResult.getSecretString() != null) { - secret = getSecretValueResult.getSecretString(); - JSONObject jsonObject = new JSONObject(secret); - secret = jsonObject.getString(secretKey); - } - return secret; - } - -} \ No newline at end of file diff --git a/src/main/java/apiCalls/actions/Token.java b/src/main/java/apiCalls/actions/Token.java index 067185a..79a24e5 100644 --- a/src/main/java/apiCalls/actions/Token.java +++ b/src/main/java/apiCalls/actions/Token.java @@ -56,7 +56,7 @@ public synchronized String getToken(String username, String password, String rea LOGGER.warning("Token creation failed, retrying... " + e.getMessage()); retryCount++; try { - Thread.sleep((long) Math.pow(2, retryCount) * 1000); // Exponential backoff + Thread.sleep((long) Math.pow(2, retryCount) * 1000); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } diff --git a/src/main/java/apiCalls/eupaActions/BaseAPI.java b/src/main/java/apiCalls/eupaActions/BaseAPI.java index f9b6778..af9d09e 100644 --- a/src/main/java/apiCalls/eupaActions/BaseAPI.java +++ b/src/main/java/apiCalls/eupaActions/BaseAPI.java @@ -1,8 +1,7 @@ package apiCalls.eupaActions; import activesupport.system.Properties; -import apiCalls.Utils.generic.SecretsManager; -import apiCalls.Utils.generic.Utils; +import activesupport.aws.s3.SecretsManager; import apiCalls.actions.Token; import apiCalls.enums.UserRoles; import com.google.gson.Gson; @@ -25,7 +24,7 @@ public abstract class BaseAPI { Token token = new Token(); URL.build(EnvironmentType.getEnum(Properties.get("env", true))); try { - setHeader( "Authorization", "Bearer " + token.getToken(SecretsManager.getSecret("adminUser"), SecretsManager.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + setHeader( "Authorization", "Bearer " + token.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString())); } catch (HttpException e) { throw new RuntimeException(e); } diff --git a/src/main/java/apiCalls/eupaActions/external/UserAPI.java b/src/main/java/apiCalls/eupaActions/external/UserAPI.java index 74f24c9..38322d6 100644 --- a/src/main/java/apiCalls/eupaActions/external/UserAPI.java +++ b/src/main/java/apiCalls/eupaActions/external/UserAPI.java @@ -1,5 +1,6 @@ package apiCalls.eupaActions.external; +import activesupport.aws.s3.SecretsManager; import activesupport.http.RestUtils; import activesupport.system.Properties; import apiCalls.Utils.eupaBuilders.external.PersonModel; @@ -31,7 +32,7 @@ public class UserAPI extends BaseAPI { */ public static PersonModel register(@NotNull UserRegistrationDetailsModel userRegistrationDetailsModel) throws HttpException { Token accessToken = new Token(); - BaseAPI.setHeader("Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + BaseAPI.setHeader("Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString())); URL.build(EnvironmentType.getEnum(Properties.get("env", true)), baseResource + "register"); int maxTries = 5; @@ -71,7 +72,7 @@ public static PersonModel register(@NotNull UserRegistrationDetailsModel userReg * @return the information associated with the person passed in as an argument. */ public static UserModel get(@NotNull PersonModel personModel) { - BaseAPI.getHeaders().put("x-pid", secrets.getSecret("apiHeader")); + BaseAPI.getHeaders().put("x-pid", SecretsManager.getSecretValue("apiHeader")); URL.build(EnvironmentType.getEnum(Properties.get("env", true)), baseResource + personModel.getUserId()); response = RestUtils.get(String.valueOf(URL.getURL()), getHeaders()); diff --git a/src/main/java/apiCalls/eupaActions/internal/CaseWorkerAPI.java b/src/main/java/apiCalls/eupaActions/internal/CaseWorkerAPI.java index b56c2b5..a738bf5 100644 --- a/src/main/java/apiCalls/eupaActions/internal/CaseWorkerAPI.java +++ b/src/main/java/apiCalls/eupaActions/internal/CaseWorkerAPI.java @@ -1,11 +1,11 @@ package apiCalls.eupaActions.internal; +import activesupport.aws.s3.SecretsManager; import activesupport.http.RestUtils; import activesupport.system.Properties; import apiCalls.Utils.eupaBuilders.external.StandardResponseModel; import apiCalls.Utils.eupaBuilders.internal.GrantApplicationModel; import apiCalls.Utils.eupaBuilders.internal.OverviewModel; -import apiCalls.Utils.generic.Utils; import apiCalls.actions.Token; import apiCalls.enums.UserRoles; import apiCalls.eupaActions.BaseAPI; @@ -22,7 +22,7 @@ public class CaseWorkerAPI extends BaseAPI { private static Token accessToken = new Token(); public static void overview(@NotNull OverviewModel overview) throws HttpException { - updateHeader("Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + updateHeader("Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString())); URL.build(EnvironmentType.getEnum(Properties.get("env", true)), String.format("application/%s/overview/", overview.getApplicationId())); int version = 1; @@ -43,7 +43,7 @@ public static void overview(@NotNull OverviewModel overview) throws HttpExceptio } public static StandardResponseModel grantApplication(@NotNull GrantApplicationModel grantApplication) throws HttpException { - updateHeader( "Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + updateHeader( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString())); URL.build(EnvironmentType.getEnum(Properties.get("env", true)), String.format("application/%s/grant/", grantApplication.getId())); response = RestUtils.put(grantApplication, String.valueOf(URL.getURL()), getHeaders()); diff --git a/src/main/java/apiCalls/eupaActions/internal/IrhpPermitStockAPI.java b/src/main/java/apiCalls/eupaActions/internal/IrhpPermitStockAPI.java index 4bbee9f..e481f55 100644 --- a/src/main/java/apiCalls/eupaActions/internal/IrhpPermitStockAPI.java +++ b/src/main/java/apiCalls/eupaActions/internal/IrhpPermitStockAPI.java @@ -1,5 +1,6 @@ package apiCalls.eupaActions.internal; +import activesupport.aws.s3.SecretsManager; import activesupport.http.RestUtils; import activesupport.system.Properties; import apiCalls.Utils.eupaBuilders.internal.irhp.permit.stock.AvailableCountriesModel; @@ -19,7 +20,7 @@ public class IrhpPermitStockAPI extends BaseAPI { public static AvailableCountriesModel availableCountries() throws HttpException { Token accessToken = new Token(); - updateHeader( "Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + updateHeader( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString())); URL.build(EnvironmentType.getEnum(Properties.get("env", true)), baseResource.concat("available-countries/?dto=Dvsa%5COlcs%5CTransfer%5CQuery%5CIrhpPermitStock%5CAvailableCountries")); diff --git a/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java b/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java index 0795c6e..5f1ad94 100644 --- a/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java +++ b/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java @@ -1,10 +1,10 @@ package apiCalls.eupaActions.internal; +import activesupport.aws.s3.SecretsManager; import activesupport.http.RestUtils; import activesupport.system.Properties; import apiCalls.Utils.eupaBuilders.internal.irhp.permit.stock.OpenByCountryModel; import apiCalls.Utils.generic.Headers; -import apiCalls.Utils.generic.SecretsManager; import apiCalls.Utils.generic.Utils; import apiCalls.actions.Token; import apiCalls.enums.UserRoles; @@ -26,7 +26,7 @@ public class IrhpPermitWindowAPI { public static OpenByCountryModel openByCountry(String[] countryIds) throws HttpException { Token accessToken = new Token(); - apiHeaders.getApiHeader().put( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecret("adminUser"), SecretsManager.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + apiHeaders.getApiHeader().put( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString())); String openCountries = URL.build(env,"irhp-permit-window/open-by-country").toString(); Map map = new HashMap<>(); diff --git a/src/main/java/apiCalls/eupaActions/internal/LicenceAPI.java b/src/main/java/apiCalls/eupaActions/internal/LicenceAPI.java index f49a766..b32a957 100644 --- a/src/main/java/apiCalls/eupaActions/internal/LicenceAPI.java +++ b/src/main/java/apiCalls/eupaActions/internal/LicenceAPI.java @@ -1,5 +1,6 @@ package apiCalls.eupaActions.internal; +import activesupport.aws.s3.SecretsManager; import activesupport.http.RestUtils; import activesupport.system.Properties; import apiCalls.Utils.generic.Utils; @@ -19,7 +20,7 @@ public class LicenceAPI extends BaseAPI { public static String licenceNumber(@NotNull String licenceId) throws HttpException { Token accessToken = new Token(); - updateHeader( "Authorization", "Bearer " + accessToken.getToken(secrets.getSecret("adminUser"), secrets.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + updateHeader( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecretValue("adminUser"), SecretsManager.getSecretValue("adminPassword"), UserRoles.INTERNAL.asString())); String env = Properties.get("env", true); URL.build(EnvironmentType.getEnum(env), baseResource.concat(licenceId));