Skip to content

Commit

Permalink
ASA 8404 (#163)
Browse files Browse the repository at this point in the history
* ASA 8404 (#158)

* include SCA implementation
* copyright changes

* review comments (#160)

* include SCA implementation
* review changes

* Update ASoCScan.java

* white space handling

* Update SAClient.java

* Update CoreConstants.java

* Include SCA

* removed the OSO option

* Include SCA

* ASA-8404

* include SCA implementation

* updated console logs

* Update SAClient.java

* copyright changes

* review changes

* indentation

* Update CoreConstants.java

* indentation

* ASA 8404 (#158)

* include SCA implementation
* copyright changes

* Update SAClient.java

* review comments (#160)

* include SCA implementation
* review changes

* Update ASoCScan.java

* white space handling

* Update SAClient.java

* Update CoreConstants.java

* Update SAClient.java

* active subscription check

* Matt's commit
  • Loading branch information
vishalhcl-5960 authored Jun 24, 2024
1 parent 590c60a commit 5bbf794
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/hcl/appscan/sdk/CoreConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public interface CoreConstants {
String API_REGIONS = API_ENV_LATEST + "/Utils/Regions"; //$NON-NLS-1$
String API_IS_VALID_URL = API_ENV_LATEST + "/Scans/IsValidUrl"; //$NON-NLS-1$
String API_AUTHENTICATION = API_ENV_LATEST + "/Account/IsAuthenticated"; //$NON-NLS-1$
String API_TENANT_INFO = API_ENV_LATEST + "/Account/TenantInfo"; //$NON-NLS-1$

String DEFAULT_RESULT_NAME = "asoc_results"; //$NON-NLS-1$
String SACLIENT_INSTALL_DIR = "SAClientInstall"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,23 @@ public String createAndExecuteScan(String type, Map<String, String> params) {
return null;
}

m_progress.setStatus(new Message(Message.INFO, Messages.getMessage(EXECUTING_SCAN, params.get(CoreConstants.SCANNER_TYPE))));
Map<String, String> 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);
request_headers.put("Content-Type", "application/json");
request_headers.put("accept", "application/json");
String request_url;

if(type.equals(SASTConstants.STATIC_ANALYZER) && !params.containsKey(UPLOAD_DIRECT) && params.containsKey(OPEN_SOURCE_ONLY)) {
m_progress.setStatus(new Message(Message.INFO, Messages.getMessage(EXECUTING_SCAN, CoreConstants.SOFTWARE_COMPOSITION_ANALYZER)));
request_url = m_authProvider.getServer() + String.format(API_SCANNER, SCA);
} else {
m_progress.setStatus(new Message(Message.INFO, Messages.getMessage(EXECUTING_SCAN, params.get(CoreConstants.SCANNER_TYPE))));
request_url = m_authProvider.getServer() + String.format(API_SCANNER, type);
}

response = client.post(request_url,request_headers,params);

int status = response.getResponseCode();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/hcl/appscan/sdk/scanners/sast/SAClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ private List<String> getClientArgs(Map<String, String> properties) {
if(properties.containsKey(THIRD_PARTY) || System.getProperty(THIRD_PARTY) != null) {
args.add(OPT_THIRD_PARTY);
}
if (properties.containsKey(OPEN_SOURCE_ONLY) || System.getProperty(OPEN_SOURCE_ONLY) != null) {
if (properties.containsKey(OPEN_SOURCE_ONLY) || System.getProperty(OPEN_SOURCE_ONLY) != null || properties.getOrDefault(CoreConstants.SCANNER_TYPE, "").equals(CoreConstants.SOFTWARE_COMPOSITION_ANALYZER)) {
args.add(OPT_OPEN_SOURCE_ONLY);
}
if (properties.containsKey(SOURCE_CODE_ONLY) || System.getProperty(SOURCE_CODE_ONLY) != null) {
args.add(OPT_SOURCE_CODE_ONLY);
}
if (!properties.containsKey(CoreConstants.INCLUDE_SCA) && properties.get(CoreConstants.SCANNER_TYPE).equals(SAST)) {
if (!properties.containsKey(CoreConstants.INCLUDE_SCA) && !properties.containsKey(OPEN_SOURCE_ONLY) && properties.get(CoreConstants.SCANNER_TYPE).equals(SAST)) {
args.add(OPT_STATIC_ANALYSIS_ONLY);
}
if (properties.get(CoreConstants.SCANNER_TYPE).equals(CoreConstants.SOFTWARE_COMPOSITION_ANALYZER)) {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/hcl/appscan/sdk/utils/ServiceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,33 @@ public static boolean isValidUrl(String url, IAuthenticationProvider provider, P

return false;
}

public static boolean activeSubscriptionsCheck(String scanType, IAuthenticationProvider provider) {
if(provider.isTokenExpired()) {
return true;
}

String request_url = provider.getServer() + API_TENANT_INFO;

try {
HttpClient client = new HttpClient(provider.getProxy(), false);
Map<String,String> requestHeaders= provider.getAuthorizationHeader(false);
requestHeaders.put("Content-Type", "application/json");
requestHeaders.put("accept", "application/json");
HttpResponse response = client.get(request_url, requestHeaders, null);

if (response.isSuccess()) {
JSONArtifact responseContent = response.getResponseBodyAsJSON();
if (responseContent != null) {
JSONObject object = (JSONObject) responseContent;
String activeTechnologies = object.getString("ActiveTechnologies");
return activeTechnologies.contains(scanType);
}
}
} catch (IOException | JSONException e) {
// Ignore and return false.
}

return false;
}
}

0 comments on commit 5bbf794

Please sign in to comment.