diff --git a/src/main/java/com/hcl/appscan/sdk/http/HttpClient.java b/src/main/java/com/hcl/appscan/sdk/http/HttpClient.java index ac2d4ba3..79e49756 100644 --- a/src/main/java/com/hcl/appscan/sdk/http/HttpClient.java +++ b/src/main/java/com/hcl/appscan/sdk/http/HttpClient.java @@ -115,36 +115,13 @@ public HttpResponse post(String url, * * @param url The URL string. * @param headerProperties An optional Map of header properties. - * @param params An optional Map of properties. + * @param parameters An optional Map of properties. * @return The response as a byte array. * @throws IOException If an error occurs. */ - public HttpResponse post(String url, Map headerProperties, Map params) - throws IOException { - Map objectMap = new HashMap<>(); - for (String key : params.keySet()) { - String value = params.get(key); - if (value != null) { - if (value.equalsIgnoreCase("true")) { - objectMap.put(key, true); - } else if (value.equalsIgnoreCase("false")) { - objectMap.put(key, false); - } else { - // If the string is not "true" or "false," keep it as is - objectMap.put(key, value); - } - } else { - // If the value is not a string, keep it as is - objectMap.put(key, value); - } - } - JSONObject json = new JSONObject(objectMap); - String body = json.toString(); - return post(url, headerProperties, body); - } - - public HttpResponse posts(String url, Map headerProperties, JSONObject params) + public HttpResponse post(String url, Map headerProperties, Map parameters) throws IOException, JSONException { + JSONObject params = new JSONObject(parameters); JSONObject objectMap = new JSONObject(); for (Object key : params.keySet()) { if (params.get(key) != null){ 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 f25d9dfe..e5a028a3 100644 --- a/src/main/java/com/hcl/appscan/sdk/results/CloudResultsProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/results/CloudResultsProvider.java @@ -237,7 +237,7 @@ protected String getReportStatus(String reportId) throws IOException, JSONExcept } JSONObject obj = (JSONObject) response.getResponseBodyAsJSON(); - JSONArray array = obj.getJSONArray("Items"); + JSONArray array = obj.getJSONArray(ITEMS); JSONObject json= (JSONObject) array.get(0); return json.getString(STATUS); } diff --git a/src/main/java/com/hcl/appscan/sdk/scan/ASEScanServiceProvider.java b/src/main/java/com/hcl/appscan/sdk/scan/ASEScanServiceProvider.java index 2d89f17a..934158a4 100644 --- a/src/main/java/com/hcl/appscan/sdk/scan/ASEScanServiceProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/scan/ASEScanServiceProvider.java @@ -50,11 +50,6 @@ public String createAndExecuteScan(String type, Map params) { } return null; } - - @Override - public String createAndExecuteScanWithJSONParameter(String type, JSONObject params) { - return ""; - } private String createJob(Map params) { 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 58f05121..a4dc1715 100644 --- a/src/main/java/com/hcl/appscan/sdk/scan/CloudScanServiceProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/scan/CloudScanServiceProvider.java @@ -51,7 +51,7 @@ public CloudScanServiceProvider(IProgress progress, IAuthenticationProvider auth @Override public String createAndExecuteScan(String type, Map params) { - if(loginExpired() || !verifyApplication(params.get(APP_ID))) + if(loginExpired() || !verifyApplication(params.get(APP_ID).toString())) return null; m_progress.setStatus(new Message(Message.INFO, Messages.getMessage(EXECUTING_SCAN))); @@ -93,55 +93,6 @@ public String createAndExecuteScan(String type, Map params) { } return null; } - - @Override - public String createAndExecuteScanWithJSONParameter(String type, JSONObject params) { - try { - if(loginExpired() || !verifyApplication(params.get(APP_ID).toString())) - return null; - } catch (JSONException e) { - throw new RuntimeException(e); - } - - m_progress.setStatus(new Message(Message.INFO, Messages.getMessage(EXECUTING_SCAN))); - Map request_headers = m_authProvider.getAuthorizationHeader(true); - HttpClient client = new HttpClient(m_authProvider.getProxy(), m_authProvider.getacceptInvalidCerts()); - - try { - HttpResponse response; - request_headers.put("Content-Type", "application/json"); - request_headers.put("accept", "application/json"); - String request_url = m_authProvider.getServer() + String.format(API_SCANNER, type); - response = client.posts(request_url, request_headers, params); - - int status = response.getResponseCode(); - - JSONObject json = (JSONObject) response.getResponseBodyAsJSON(); - - if (status == HttpsURLConnection.HTTP_CREATED || status == HttpsURLConnection.HTTP_OK) { - m_progress.setStatus(new Message(Message.INFO, Messages.getMessage(CREATE_SCAN_SUCCESS))); - return json.getString(ID); - } else if (json != null && json.has(MESSAGE)) { - String errorResponse = json.getString(MESSAGE); - if(json.has(FORMAT_PARAMS) && !json.isNull(FORMAT_PARAMS)) { - JSONArray jsonArray = json.getJSONArray(FORMAT_PARAMS); - if(jsonArray != null){ - String[] messageParams = new String[jsonArray.size()]; - for (int i = 0; i < jsonArray.size(); i++) { - messageParams[i] = (String)jsonArray.get(i); - } - errorResponse = MessageFormat.format(errorResponse, (Object[]) messageParams); - } - } - m_progress.setStatus(new Message(Message.ERROR, errorResponse)); - } - else - m_progress.setStatus(new Message(Message.ERROR, Messages.getMessage(ERROR_SUBMITTING_SCAN, status))); - } catch(IOException | JSONException e) { - m_progress.setStatus(new Message(Message.ERROR, Messages.getMessage(ERROR_SUBMITTING_SCAN, e.getLocalizedMessage()))); - } - return null; - } @Override public String submitFile(File file) throws IOException { diff --git a/src/main/java/com/hcl/appscan/sdk/scan/IScan.java b/src/main/java/com/hcl/appscan/sdk/scan/IScan.java index 02b54dbf..1d3bf165 100644 --- a/src/main/java/com/hcl/appscan/sdk/scan/IScan.java +++ b/src/main/java/com/hcl/appscan/sdk/scan/IScan.java @@ -20,7 +20,7 @@ public interface IScan { * @throws ScannerException if a fatal error occurs in the scan. * @throws InvalidTargetException if the target is invalid. */ - public void run() throws ScannerException, InvalidTargetException, JSONException; + public void run() throws ScannerException, InvalidTargetException; /** * Gets the id of the scan. diff --git a/src/main/java/com/hcl/appscan/sdk/scan/IScanServiceProvider.java b/src/main/java/com/hcl/appscan/sdk/scan/IScanServiceProvider.java index 58851498..fb1764c3 100644 --- a/src/main/java/com/hcl/appscan/sdk/scan/IScanServiceProvider.java +++ b/src/main/java/com/hcl/appscan/sdk/scan/IScanServiceProvider.java @@ -32,15 +32,6 @@ public interface IScanServiceProvider { */ public String createAndExecuteScan(String type, Map params); - /** - * Creates and executes a scan. - * - * @param type The type of scan to execute. For example DynamicAnalyzer. - * @param params A JSON of scan parameters. - * @return The id of the submitted scan, if successful. Otherwise, null. - */ - public String createAndExecuteScanWithJSONParameter(String type, JSONObject params); - /** * Submits a file for scanning. * 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 a8e78cf4..6d357c01 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 @@ -18,6 +18,7 @@ import com.hcl.appscan.sdk.logging.DefaultProgress; import com.hcl.appscan.sdk.logging.IProgress; import com.hcl.appscan.sdk.scan.IScanServiceProvider; +import com.hcl.appscan.sdk.scan.CloudScanServiceProvider; import com.hcl.appscan.sdk.scanners.ASoCScan; import com.hcl.appscan.sdk.utils.ServiceUtil; import org.apache.wink.json4j.JSONException; @@ -37,7 +38,7 @@ public DASTScan(Map properties, IProgress progress, IScanService } @Override - public void run() throws ScannerException, InvalidTargetException, JSONException { + public void run() throws ScannerException, InvalidTargetException { String type = DYNAMIC_ANALYZER; String target = getTarget(); @@ -91,8 +92,12 @@ public void run() throws ScannerException, InvalidTargetException, JSONException } } - JSONObject propertiesJSON = createJSONForProperties(params); - setScanId(getServiceProvider().createAndExecuteScanWithJSONParameter(type, propertiesJSON)); + try { + JSONObject propertiesJSON = createJSONForProperties(params); + setScanId(getServiceProvider().createAndExecuteScan(type, propertiesJSON)); + } catch (JSONException e) { + throw new ScannerException(Messages.getMessage(ERROR_RUNNING_SCAN, e.getLocalizedMessage())); + } if(getScanId() == null) throw new ScannerException(Messages.getMessage(ERROR_CREATING_SCAN));