diff --git a/src/main/java/com/hcl/appscan/sdk/CoreConstants.java b/src/main/java/com/hcl/appscan/sdk/CoreConstants.java index ee1b91b5..555d77b3 100644 --- a/src/main/java/com/hcl/appscan/sdk/CoreConstants.java +++ b/src/main/java/com/hcl/appscan/sdk/CoreConstants.java @@ -63,7 +63,7 @@ public interface CoreConstants { String API_PRESENCES = API_ENV_LATEST + "/Presences"; //$NON-NLS-1$ String API_PRESENCES_ID = API_ENV_LATEST + "/Presences/%s"; //$NON-NLS-1$ String API_PRESENCES_NEW_KEY = API_ENV_LATEST + "/Presences/%s/NewKey"; //$NON-NLS-1$ - String API_BASIC_DETAILS = API_ENV_LATEST + "/Scans/Executions/%s"; //$NON-NLS-1$ + String API_BASIC_DETAILS = API_ENV_LATEST + "/Scans"; //$NON-NLS-1$ String API_SCANNER_DETAILS = API_ENV + "/Scans/&s/&s"; //$NON-NLS-1$ String API_FILE_UPLOAD = API_ENV_LATEST + "/FileUpload"; //$NON-NLS-1$ String API_SCAN = API_ENV + "/%s"; //$NON-NLS-1$ 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 dc53fe6a..de471e1e 100644 --- a/src/main/java/com/hcl/appscan/sdk/results/CloudResultsProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/results/CloudResultsProvider.java @@ -161,7 +161,8 @@ public void setReportFormat(String format) { protected void loadResults() { try { - JSONObject obj = m_scanProvider.getScanDetails(m_scanId); + JSONObject items = m_scanProvider.getScanDetails(m_scanId); + JSONObject obj = items.getJSONObject(LATEST_EXECUTION); m_status = obj.getString(STATUS); if(m_status != null && !(m_status.equalsIgnoreCase(INQUEUE) || m_status.equalsIgnoreCase(RUNNING))) { m_totalFindings = obj.getInt(TOTAL_ISSUES); diff --git a/src/main/java/com/hcl/appscan/sdk/results/NonCompliantIssuesResultProvider.java b/src/main/java/com/hcl/appscan/sdk/results/NonCompliantIssuesResultProvider.java index 51f6dfed..f9fed89d 100644 --- a/src/main/java/com/hcl/appscan/sdk/results/NonCompliantIssuesResultProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/results/NonCompliantIssuesResultProvider.java @@ -36,11 +36,12 @@ public NonCompliantIssuesResultProvider(String scanId, String type, IScanService @Override protected void loadResults() { try { - JSONObject obj = m_scanProvider.getScanDetails(m_scanId); + JSONObject items = m_scanProvider.getScanDetails(m_scanId); + JSONObject obj = items.getJSONObject(LATEST_EXECUTION); if (obj == null) { m_status = FAILED; return; - } else if (obj.has(KEY) && obj.get(KEY).equals(UNAUTHORIZED_ACTION)) { + } else if (items.has(KEY) && items.get(KEY).equals(UNAUTHORIZED_ACTION)) { m_status = FAILED; return; } else if (obj.has(STATUS) && obj.get(STATUS).equals(UNKNOWN)) { @@ -218,13 +219,11 @@ private JSONObject getConfiguration(String format) throws JSONException { } private String getScanName() { - JSONObject obj; try { - obj = m_scanProvider.getScanDetails(m_scanId); - return obj.getString("Name"); + JSONObject items = m_scanProvider.getScanDetails(m_scanId); + return items.getString(NAME); } catch (IOException | JSONException e) { - m_progress.setStatus(new Message(Message.ERROR, Messages.getMessage(ERROR_GETTING_DETAILS, e.getMessage())), - e); + m_progress.setStatus(new Message(Message.ERROR, Messages.getMessage(ERROR_GETTING_DETAILS, e.getMessage())), e); return ""; } diff --git a/src/main/java/com/hcl/appscan/sdk/scan/CloudScanServiceProvider.java b/src/main/java/com/hcl/appscan/sdk/scan/CloudScanServiceProvider.java index 6386c2fc..58f05121 100644 --- a/src/main/java/com/hcl/appscan/sdk/scan/CloudScanServiceProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/scan/CloudScanServiceProvider.java @@ -179,7 +179,8 @@ public JSONObject getScanDetails(String scanId) throws IOException, JSONExceptio if(loginExpired()) return null; - String request_url = m_authProvider.getServer() + String.format(API_BASIC_DETAILS, scanId); + String request_url = m_authProvider.getServer() + API_BASIC_DETAILS; + request_url +=String.format("?$filter=Id eq %s",scanId); Map request_headers = m_authProvider.getAuthorizationHeader(true); HttpClient client = new HttpClient(m_authProvider.getProxy(), m_authProvider.getacceptInvalidCerts()); @@ -187,7 +188,8 @@ public JSONObject getScanDetails(String scanId) throws IOException, JSONExceptio HttpResponse response = client.get(request_url, request_headers, null); if (response.getResponseCode() == HttpsURLConnection.HTTP_OK || response.getResponseCode() == HttpsURLConnection.HTTP_CREATED){ - JSONArray array = (JSONArray) response.getResponseBodyAsJSON(); + JSONObject obj = (JSONObject) response.getResponseBodyAsJSON(); + JSONArray array = (JSONArray) obj.get(ITEMS); return (JSONObject) array.getJSONObject(0); } else if (response.getResponseCode() == -1) { return new JSONObject().put(STATUS,UNKNOWN); //If the server is not reachable Internet disconnect @@ -210,7 +212,7 @@ public JSONObject getScanDetails(String scanId) throws IOException, JSONExceptio return null; } - @Override + @Override public JSONArray getNonCompliantIssues(String scanId) throws IOException, JSONException { if(loginExpired()) return null; diff --git a/src/main/java/com/hcl/appscan/sdk/scanners/dynamic/DASTConstants.java b/src/main/java/com/hcl/appscan/sdk/scanners/dynamic/DASTConstants.java index 45ae11f5..18ed1571 100644 --- a/src/main/java/com/hcl/appscan/sdk/scanners/dynamic/DASTConstants.java +++ b/src/main/java/com/hcl/appscan/sdk/scanners/dynamic/DASTConstants.java @@ -31,6 +31,7 @@ public interface DASTConstants { String TEST_OPTIMIZATION_LEVEL = "TestOptimizationLevel"; //$NON-NLS-1$ String USER_NAME = "UserName"; //$NON-NLS-1$ String PASSWORD = "Password"; //$NON-NLS-1$ + String EXTRA_FIELD = "ExtraField"; //$NON-NLS-1$ //Errors String ERROR_SUBMITTING_SCAN = "error.submitting.scan"; //$NON-NLS-1$ } diff --git a/src/main/java/com/hcl/appscan/sdk/scanners/dynamic/DASTScan.java b/src/main/java/com/hcl/appscan/sdk/scanners/dynamic/DASTScan.java index b10178fe..a8e78cf4 100644 --- a/src/main/java/com/hcl/appscan/sdk/scanners/dynamic/DASTScan.java +++ b/src/main/java/com/hcl/appscan/sdk/scanners/dynamic/DASTScan.java @@ -91,16 +91,20 @@ public void run() throws ScannerException, InvalidTargetException, JSONException } } - JSONObject propertiesJSON = creatingJSONForProperties(params); + JSONObject propertiesJSON = createJSONForProperties(params); setScanId(getServiceProvider().createAndExecuteScanWithJSONParameter(type, propertiesJSON)); if(getScanId() == null) throw new ScannerException(Messages.getMessage(ERROR_CREATING_SCAN)); } - private JSONObject creatingJSONForProperties(Map params) throws JSONException { + private JSONObject createJSONForProperties(Map params) throws JSONException { JSONObject json = new JSONObject(params); - return json.put(SCAN_CONFIGURATION, createScanConfiguration(json)); + if(!params.containsKey(SCAN_FILE_ID)) { + return json.put(SCAN_CONFIGURATION, createScanConfiguration(json)); + } else { + return json; + } } private JSONObject createScanConfiguration(JSONObject json) throws JSONException { @@ -123,6 +127,9 @@ private JSONObject createLogin(JSONObject json) throws JSONException { login.put(USER_NAME, json.remove(LOGIN_USER)); login.put(PASSWORD, json.remove(LOGIN_PASSWORD)); } + if (json.containsKey(EXTRA_FIELD)) { + login.put(EXTRA_FIELD, json.remove(EXTRA_FIELD)); + } return login; }