From 42ae65e48c4242b8edf5a631a5599e091bf594b6 Mon Sep 17 00:00:00 2001 From: Vishal Chaudhary Date: Thu, 16 Jan 2025 14:59:00 +0530 Subject: [PATCH] copyright year updates --- .../com/hcl/appscan/sdk/CoreConstants.java | 2 +- .../sdk/results/ASEResultsProvider.java | 2 +- .../results/CloudCombinedResultsProvider.java | 2 +- .../sdk/results/CloudResultsProvider.java | 2 +- .../appscan/sdk/results/IResultsProvider.java | 2 +- .../hcl/appscan/sdk/utils/ServiceUtil.java | 43 ++++++++++++++++++- 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hcl/appscan/sdk/CoreConstants.java b/src/main/java/com/hcl/appscan/sdk/CoreConstants.java index 99bc168..80e2c34 100644 --- a/src/main/java/com/hcl/appscan/sdk/CoreConstants.java +++ b/src/main/java/com/hcl/appscan/sdk/CoreConstants.java @@ -1,6 +1,6 @@ /** * © Copyright IBM Corporation 2016. - * © Copyright HCL Technologies Ltd. 2017, 2024. + * © Copyright HCL Technologies Ltd. 2017, 2024, 2025. * LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 */ diff --git a/src/main/java/com/hcl/appscan/sdk/results/ASEResultsProvider.java b/src/main/java/com/hcl/appscan/sdk/results/ASEResultsProvider.java index 6d8ff7d..bd8fce6 100644 --- a/src/main/java/com/hcl/appscan/sdk/results/ASEResultsProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/results/ASEResultsProvider.java @@ -1,5 +1,5 @@ /** - * © Copyright HCL Technologies Ltd. 2019, 2020, 2024. + * © Copyright HCL Technologies Ltd. 2019, 2020, 2024, 2025. * LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 */ diff --git a/src/main/java/com/hcl/appscan/sdk/results/CloudCombinedResultsProvider.java b/src/main/java/com/hcl/appscan/sdk/results/CloudCombinedResultsProvider.java index 99df39b..9d49dea 100644 --- a/src/main/java/com/hcl/appscan/sdk/results/CloudCombinedResultsProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/results/CloudCombinedResultsProvider.java @@ -1,5 +1,5 @@ /** - * © Copyright HCL Technologies Ltd. 2024. + * © Copyright HCL Technologies Ltd. 2024, 2025. * LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 */ diff --git a/src/main/java/com/hcl/appscan/sdk/results/CloudResultsProvider.java b/src/main/java/com/hcl/appscan/sdk/results/CloudResultsProvider.java index 9bca3d0..c0be1f8 100644 --- a/src/main/java/com/hcl/appscan/sdk/results/CloudResultsProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/results/CloudResultsProvider.java @@ -1,6 +1,6 @@ /** * © Copyright IBM Corporation 2016. - * © Copyright HCL Technologies Ltd. 2017, 2024. + * © Copyright HCL Technologies Ltd. 2017, 2024, 2025. * LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 */ diff --git a/src/main/java/com/hcl/appscan/sdk/results/IResultsProvider.java b/src/main/java/com/hcl/appscan/sdk/results/IResultsProvider.java index de71b89..267b182 100644 --- a/src/main/java/com/hcl/appscan/sdk/results/IResultsProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/results/IResultsProvider.java @@ -1,6 +1,6 @@ /** * © Copyright IBM Corporation 2016. - * © Copyright HCL Technologies Ltd. 2017, 2024. + * © Copyright HCL Technologies Ltd. 2017, 2024, 2025. * LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 */ diff --git a/src/main/java/com/hcl/appscan/sdk/utils/ServiceUtil.java b/src/main/java/com/hcl/appscan/sdk/utils/ServiceUtil.java index 3f58b30..bd4dca4 100644 --- a/src/main/java/com/hcl/appscan/sdk/utils/ServiceUtil.java +++ b/src/main/java/com/hcl/appscan/sdk/utils/ServiceUtil.java @@ -1,6 +1,6 @@ /** * © Copyright IBM Corporation 2016. - * © Copyright HCL Technologies Ltd. 2017, 2024. + * © Copyright HCL Technologies Ltd. 2017, 2024, 2025. * LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0 */ @@ -223,6 +223,47 @@ private static boolean hasEntitlement(String scanType, IAuthenticationProvider p return false; } + /** + * Checks if the given scanId is valid for scanning. + * + * @param scanId The scanId to test. + * @param applicationId The applicationId to verify. + * @param type The scanType to verify. + * @param provider The IAuthenticationProvider for authentication. + * @return True if the scanId is valid. False is returned if the scanId is not valid, the request fails, or an exception occurs. + */ + public static boolean isScanId(String scanId, String applicationId, String type, IAuthenticationProvider provider) { + if (provider.isTokenExpired()) { + return true; + } + + String request_url = provider.getServer() + API_BASIC_DETAILS; + request_url += "?$filter=Id%20eq%20" + scanId + "&%24select=AppId%2C%20Technology"; + Map request_headers = provider.getAuthorizationHeader(true); + + HttpClient client = new HttpClient(provider.getProxy(), provider.getacceptInvalidCerts()); + try { + HttpResponse response = client.get(request_url, request_headers, null); + + if (response.isSuccess()) { + JSONObject obj = (JSONObject) response.getResponseBodyAsJSON(); + JSONArray array = (JSONArray) obj.get(ITEMS); + if (array.isEmpty()) { + return false; + } else { + JSONObject body = (JSONObject) array.getJSONObject(0); + String appId = body.getString(CoreConstants.APP_ID); + String technologyName = body.getString("Technology"); + return appId.equals(applicationId) && technologyName.equals(updatedScanType(type)); + } + } + } catch (IOException | JSONException e) { + // Ignore and return false. + } + + return false; + } + public static String updatedScanType(String type) { switch (type) { case "Static Analyzer":