From 0e6762416980c22016a05c86022c4ce4a743b450 Mon Sep 17 00:00:00 2001 From: Stefan Ranoszek Date: Wed, 7 Aug 2024 10:57:56 +0100 Subject: [PATCH 1/3] feat: concurrency hashmap & check token expiry --- pom.xml | 23 ++------ .../java/apiCalls/Utils/generic/BaseAPI.java | 56 +++++++++++++++--- .../java/apiCalls/Utils/generic/Headers.java | 13 +++-- .../apiCalls/actions/CreateApplication.java | 29 +++++++--- .../java/apiCalls/actions/GrantLicence.java | 2 +- .../apiCalls/actions/InternalDetails.java | 2 +- src/main/java/apiCalls/actions/Token.java | 58 +++++++++++++------ .../java/apiCalls/actions/UpdateLicence.java | 2 +- .../java/apiCalls/actions/UserDetails.java | 12 ++-- .../internal/IrhpPermitWindowAPI.java | 2 +- 10 files changed, 132 insertions(+), 67 deletions(-) diff --git a/pom.xml b/pom.xml index 97681d6..44154ce 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ - 2.4.1 + 2.4.2-SNAPSHOT 2.22.0 2.22.0 3.14.0 @@ -105,24 +105,9 @@ ${apache-http.version} - org.yaml - snakeyaml - ${snakeyamal.version} - - - com.amazonaws - aws-java-sdk-secretsmanager - ${aws-secrets-manager.version} - - - com.amazonaws - aws-java-sdk - ${aws-java-sdk-s3.version} - - - com.amazon.ion - 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 bdfa207..9dc84da 100644 --- a/src/main/java/apiCalls/Utils/generic/BaseAPI.java +++ b/src/main/java/apiCalls/Utils/generic/BaseAPI.java @@ -3,47 +3,87 @@ import activesupport.http.RestUtils; import activesupport.system.Properties; import apiCalls.actions.Token; +import com.auth0.jwt.JWT; +import com.auth0.jwt.exceptions.JWTDecodeException; +import com.auth0.jwt.interfaces.DecodedJWT; import io.restassured.response.ValidatableResponse; import org.apache.hc.core5.http.HttpException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.dvsa.testing.lib.url.api.URL; import org.dvsa.testing.lib.url.utils.EnvironmentType; +import java.util.Date; +import java.util.HashMap; +import java.util.UUID; public class BaseAPI extends Token { + protected static final Logger LOGGER = LogManager.getLogger(BaseAPI.class); + protected static EnvironmentType env = EnvironmentType.getEnum(Properties.get("env", true)); - + static Headers headers = new Headers(); public synchronized String adminJWT() throws HttpException { - String adminUser =SecretsManager.getSecret("adminUser"); + String adminUser = SecretsManager.getSecret("adminUser"); String adminPassword = SecretsManager.getSecret("adminPassword"); - if(getAdminToken() == null){ + + if (getAdminToken() == null || isTokenExpired(getAdminToken())) { + LOGGER.info("Generating new admin token"); generateAdminToken(adminUser, adminPassword); + } else { + LOGGER.info("Using existing admin token"); } + return getAdminToken(); } + private boolean isTokenExpired(String token) { + try { + DecodedJWT decodedJWT = JWT.decode(token); + return decodedJWT.getExpiresAt().before(new Date()); + } catch (JWTDecodeException e) { + LOGGER.error("Error decoding token: " + e.getMessage()); + return true; + } + } + + protected void logApiCall(String requestId, String methodName, String message) { + LOGGER.info("RequestID: {}, Method: {}, Message: {}", requestId, methodName, message); + } + + public synchronized HashMap header(String requestId) throws HttpException { + headers.getApiHeader().put("Authorization", "Bearer " + adminJWT()); + logApiCall(requestId, "header", "Authorization header set."); + return (HashMap) headers.getApiHeader(); + } + public synchronized String fetchApplicationInformation(String applicationNumber, String jsonPath, String defaultReturn) throws HttpException { + String requestId = UUID.randomUUID().toString(); String url = URL.build(env, String.format("application/%s/overview/", applicationNumber)).toString(); - return retrieveAPIData(url, jsonPath, defaultReturn); + return retrieveAPIData(url, jsonPath, defaultReturn, requestId); } public synchronized String fetchTMApplicationInformation(String applicationNumber, String jsonPath, String defaultReturn) throws HttpException { + String requestId = UUID.randomUUID().toString(); String url = URL.build(env, String.format("transport-manager-application/%s", applicationNumber)).toString(); - return retrieveAPIData(url, jsonPath, defaultReturn); + return retrieveAPIData(url, jsonPath, defaultReturn, requestId); } public synchronized String fetchInternalUserInformation(String userId, String jsonPath, String defaultReturn) throws HttpException { + String requestId = UUID.randomUUID().toString(); String url = URL.build(env, String.format("user/internal/%s", userId)).toString(); - return retrieveAPIData(url, jsonPath, defaultReturn); + return retrieveAPIData(url, jsonPath, defaultReturn, requestId); } - public synchronized String retrieveAPIData(String url, String jsonPath, String defaultReturn) throws HttpException { - headers.apiHeader.put("Authorization", "Bearer " + adminJWT()); + public synchronized String retrieveAPIData(String url, String jsonPath, String defaultReturn, String requestId) throws HttpException { + headers.getApiHeader().put("Authorization", "Bearer " + adminJWT()); ValidatableResponse response = RestUtils.get(url, headers.getApiHeader()); + try { return response.extract().response().jsonPath().getString(jsonPath); } catch (NullPointerException ne) { + LOGGER.error("RequestID: {}, NullPointerException when extracting JSON path: {}", requestId, jsonPath, ne); return defaultReturn; } } diff --git a/src/main/java/apiCalls/Utils/generic/Headers.java b/src/main/java/apiCalls/Utils/generic/Headers.java index 7e4b980..e45c323 100644 --- a/src/main/java/apiCalls/Utils/generic/Headers.java +++ b/src/main/java/apiCalls/Utils/generic/Headers.java @@ -1,15 +1,16 @@ package apiCalls.Utils.generic; import java.util.HashMap; +import java.util.Map; public class Headers { - private static String API_HEADER; + private static final ThreadLocal> apiHeaderThreadLocal = ThreadLocal.withInitial(HashMap::new); - public HashMap apiHeader = new HashMap<>(); + private static String API_HEADER; - public HashMap getApiHeader() { - return apiHeader; + public Map getApiHeader() { + return apiHeaderThreadLocal.get(); } public static String getAPI_HEADER() { @@ -19,4 +20,8 @@ public static String getAPI_HEADER() { public static void setAPI_HEADER(String api_header) { API_HEADER = api_header; } + + public static void clear() { + apiHeaderThreadLocal.remove(); + } } \ No newline at end of file diff --git a/src/main/java/apiCalls/actions/CreateApplication.java b/src/main/java/apiCalls/actions/CreateApplication.java index 7fc7daf..e2630f9 100644 --- a/src/main/java/apiCalls/actions/CreateApplication.java +++ b/src/main/java/apiCalls/actions/CreateApplication.java @@ -1083,16 +1083,27 @@ public CreateApplication(RegisterUser registerUser, UserDetails getUserDetails) public synchronized ValidatableResponse startApplication() throws HttpException { String createApplicationResource = URL.build(env, "application").toString(); - apiHeaders.apiHeader.put("Authorization", "Bearer " + getUserDetails().getJwtToken()); - ApplicationBuilder applicationBuilder = new ApplicationBuilder().withOperatorType(getOperatorType()) - .withLicenceType(getLicenceType()).withNiFlag(getNiFlag()).withOrganisation(getUserDetails().getOrganisationId()) - .withLgvDeclarationConfirmation("0"); - if (operatorType.equals(OperatorType.GOODS.asString()) && licenceType.equals(LicenceType.STANDARD_INTERNATIONAL.asString())) { - applicationBuilder.withVehicleType(getVehicleType()); - if (VehicleType.LGV_ONLY_FLEET.asString().equals(getVehicleType())) - applicationBuilder.withLgvDeclarationConfirmation("1"); + + synchronized (this) { + apiHeaders.getApiHeader().put("Authorization", "Bearer " + getUserDetails().getJwtToken()); + + ApplicationBuilder applicationBuilder = new ApplicationBuilder() + .withOperatorType(getOperatorType()) + .withLicenceType(getLicenceType()) + .withNiFlag(getNiFlag()) + .withOrganisation(getUserDetails().getOrganisationId()) + .withLgvDeclarationConfirmation("0"); + + if (operatorType.equals(OperatorType.GOODS.asString()) && licenceType.equals(LicenceType.STANDARD_INTERNATIONAL.asString())) { + applicationBuilder.withVehicleType(getVehicleType()); + if (VehicleType.LGV_ONLY_FLEET.asString().equals(getVehicleType())) { + applicationBuilder.withLgvDeclarationConfirmation("1"); + } + } + + apiResponse = RestUtils.post(applicationBuilder, createApplicationResource, apiHeaders.getApiHeader()); } - apiResponse = RestUtils.post(applicationBuilder, createApplicationResource, apiHeaders.getApiHeader()); + setApplicationId(apiResponse.extract().jsonPath().getString("id.application")); setLicenceId(apiResponse.extract().jsonPath().getString("id.licence")); diff --git a/src/main/java/apiCalls/actions/GrantLicence.java b/src/main/java/apiCalls/actions/GrantLicence.java index 019ec28..3e1d710 100644 --- a/src/main/java/apiCalls/actions/GrantLicence.java +++ b/src/main/java/apiCalls/actions/GrantLicence.java @@ -52,7 +52,7 @@ public GrantLicence(CreateApplication application) { public HashMap header() throws HttpException { apiHeaders.getApiHeader().put("Authorization", "Bearer " + adminJWT()); - return apiHeaders.apiHeader; + return (HashMap) apiHeaders.getApiHeader(); } public synchronized ValidatableResponse grantLicence() throws HttpException { diff --git a/src/main/java/apiCalls/actions/InternalDetails.java b/src/main/java/apiCalls/actions/InternalDetails.java index 66fec4a..a6aab51 100644 --- a/src/main/java/apiCalls/actions/InternalDetails.java +++ b/src/main/java/apiCalls/actions/InternalDetails.java @@ -20,7 +20,7 @@ public class InternalDetails extends BaseAPI { EnvironmentType env = EnvironmentType.getEnum(Properties.get("env", true)); public HashMap header() throws HttpException { apiHeaders.getApiHeader().put("Authorization", "Bearer " + adminJWT()); - return apiHeaders.apiHeader; + return (HashMap) apiHeaders.getApiHeader(); } public synchronized ValidatableResponse getFinancialStandingRates () throws HttpException { diff --git a/src/main/java/apiCalls/actions/Token.java b/src/main/java/apiCalls/actions/Token.java index 7072ad2..067185a 100644 --- a/src/main/java/apiCalls/actions/Token.java +++ b/src/main/java/apiCalls/actions/Token.java @@ -11,44 +11,66 @@ import org.dvsa.testing.lib.url.api.URL; import org.dvsa.testing.lib.url.utils.EnvironmentType; -import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Logger; public class Token { + private static final Logger LOGGER = Logger.getLogger(Token.class.getName()); private String adminToken; - - EnvironmentType env = EnvironmentType.getEnum(Properties.get("env", true)); - HashMap header = new HashMap<>(); - TokenRequestBuilder tokenBody = new TokenRequestBuilder(); - + private final EnvironmentType env; + private final ConcurrentHashMap header; + private final TokenRequestBuilder tokenBody; + + public Token() { + this.env = EnvironmentType.getEnum(Properties.get("env", true)); + this.header = new ConcurrentHashMap<>(); + this.tokenBody = new TokenRequestBuilder(); + } public synchronized String generateAdminToken(String adminUser, String adminPassword) throws HttpException { - String adminToken = null; - if (getAdminToken() == null) { + if (adminToken == null) { + LOGGER.info("Admin token is null, generating a new token."); adminToken = getToken(adminUser, adminPassword, UserType.INTERNAL.asString()); setToken(adminToken); + } else { + LOGGER.info("Admin token already exists, returning the existing token."); } return adminToken; } public synchronized String getToken(String username, String password, String realm) throws HttpException { - String jwtTokenResource; - ValidatableResponse tokenResponse; - jwtTokenResource = URL.build(env).toString().concat("auth/login"); + String jwtTokenResource = URL.build(env).toString().concat("auth/login"); tokenBody.withUsername(username).withPassword(password).withRealm(realm); - tokenResponse = RestUtils.post(tokenBody, jwtTokenResource, header); - try { - Utils.checkHTTPStatusCode(tokenResponse, HttpStatus.SC_CREATED); - } catch (Exception e) { - tokenResponse = RestUtils.post(tokenBody, jwtTokenResource, header); + + LOGGER.info("Requesting token from URL: " + jwtTokenResource); + + int retryCount = 0; + int maxRetries = 3; + while (retryCount < maxRetries) { + try { + ValidatableResponse tokenResponse = RestUtils.post(tokenBody, jwtTokenResource, header); + Utils.checkHTTPStatusCode(tokenResponse, HttpStatus.SC_CREATED); + LOGGER.info("Token successfully created."); + return tokenResponse.extract().body().jsonPath().getString("flags.identity.Token.access_token"); + } catch (Exception e) { + LOGGER.warning("Token creation failed, retrying... " + e.getMessage()); + retryCount++; + try { + Thread.sleep((long) Math.pow(2, retryCount) * 1000); // Exponential backoff + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + } + } } - return tokenResponse.extract().body().jsonPath().getString("flags.identity.Token.access_token"); + throw new HttpException("Failed to create token after " + maxRetries + " retries."); } public String getAdminToken() { return adminToken; } - public void setToken(String adminToken) { + private synchronized void setToken(String adminToken) { this.adminToken = adminToken; + LOGGER.info("Admin token set."); } } \ No newline at end of file diff --git a/src/main/java/apiCalls/actions/UpdateLicence.java b/src/main/java/apiCalls/actions/UpdateLicence.java index 1f52315..6020f71 100644 --- a/src/main/java/apiCalls/actions/UpdateLicence.java +++ b/src/main/java/apiCalls/actions/UpdateLicence.java @@ -742,7 +742,7 @@ public UpdateLicence(CreateApplication application) { public synchronized HashMap header() throws HttpException { apiHeaders.getApiHeader().put("Authorization", "Bearer " + adminJWT()); - return apiHeaders.apiHeader; + return (HashMap) apiHeaders.getApiHeader(); } public synchronized void createVariation() throws HttpException { diff --git a/src/main/java/apiCalls/actions/UserDetails.java b/src/main/java/apiCalls/actions/UserDetails.java index fb2e68a..79d9be0 100644 --- a/src/main/java/apiCalls/actions/UserDetails.java +++ b/src/main/java/apiCalls/actions/UserDetails.java @@ -15,6 +15,7 @@ import org.dvsa.testing.lib.url.api.URL; import org.dvsa.testing.lib.url.utils.EnvironmentType; +import java.util.concurrent.ConcurrentHashMap; public class UserDetails extends BaseAPI { private Headers apiHeaders = new Headers(); @@ -22,16 +23,15 @@ public class UserDetails extends BaseAPI { private String organisationId; - EnvironmentType env = EnvironmentType.getEnum(Properties.get("env", true)); - private ValidatableResponse apiResponse; + private EnvironmentType env = EnvironmentType.getEnum(Properties.get("env", true)); + + private static final ConcurrentHashMap userOrgMap = new ConcurrentHashMap<>(); public synchronized ValidatableResponse getUserDetails(String userType, String userId, String username, String password) throws HttpException { String userDetailsResource; - apiHeaders - .apiHeader - .put("Authorization", "Bearer " + adminJWT()); + apiHeaders.getApiHeader().put("Authorization", "Bearer " + adminJWT()); if (userType.equals(UserType.EXTERNAL.asString())) { String orgId; @@ -40,6 +40,8 @@ public synchronized ValidatableResponse getUserDetails(String userType, String u setJwtToken(getToken(username, password, Realm.SELF_SERVE.asString())); orgId = apiResponse.extract().jsonPath().prettyPeek().getString("organisationUsers.organisation.id"); setOrganisationId(orgId); + userOrgMap.put(userId, orgId); + } else if (userType.equals(UserType.INTERNAL.asString())) { userDetailsResource = URL.build(env, String.format("user/%s/%s", userType, userId)).toString(); apiResponse = RestUtils.get(userDetailsResource, apiHeaders.getApiHeader()); diff --git a/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java b/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java index 358e371..0795c6e 100644 --- a/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java +++ b/src/main/java/apiCalls/eupaActions/internal/IrhpPermitWindowAPI.java @@ -26,7 +26,7 @@ public class IrhpPermitWindowAPI { public static OpenByCountryModel openByCountry(String[] countryIds) throws HttpException { Token accessToken = new Token(); - apiHeaders.apiHeader.put( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecret("adminUser"), SecretsManager.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); + apiHeaders.getApiHeader().put( "Authorization", "Bearer " + accessToken.getToken(SecretsManager.getSecret("adminUser"), SecretsManager.getSecret("adminPassword"), UserRoles.INTERNAL.asString())); String openCountries = URL.build(env,"irhp-permit-window/open-by-country").toString(); Map map = new HashMap<>(); From 42314267028d5a6827bb342999dc5356fe932127 Mon Sep 17 00:00:00 2001 From: Stefan Ranoszek Date: Wed, 7 Aug 2024 10:59:14 +0100 Subject: [PATCH 2/3] chore: adjust pom --- pom.xml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 44154ce..197b403 100644 --- a/pom.xml +++ b/pom.xml @@ -105,9 +105,24 @@ ${apache-http.version} - com.auth0 - java-jwt - 4.4.0 + org.yaml + snakeyaml + ${snakeyamal.version} + + + com.amazonaws + aws-java-sdk-secretsmanager + ${aws-secrets-manager.version} + + + com.amazonaws + aws-java-sdk + ${aws-java-sdk-s3.version} + + + com.amazon.ion + ion-java + 1.11.9 From 8e46c537b153f8070b36e4a9bb6f316dc6673063 Mon Sep 17 00:00:00 2001 From: Stefan Ranoszek Date: Wed, 7 Aug 2024 15:08:10 +0100 Subject: [PATCH 3/3] chore:reference secrtsManager from active support --- pom.xml | 7 ++- .../java/apiCalls/Utils/generic/BaseAPI.java | 5 +- .../Utils/generic/SecretsManager.java | 55 ------------------- src/main/java/apiCalls/actions/Token.java | 2 +- .../java/apiCalls/eupaActions/BaseAPI.java | 5 +- .../eupaActions/external/UserAPI.java | 5 +- .../eupaActions/internal/CaseWorkerAPI.java | 6 +- .../internal/IrhpPermitStockAPI.java | 3 +- .../internal/IrhpPermitWindowAPI.java | 4 +- .../eupaActions/internal/LicenceAPI.java | 3 +- 10 files changed, 24 insertions(+), 71 deletions(-) delete mode 100644 src/main/java/apiCalls/Utils/generic/SecretsManager.java 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));