From 93f69e56417aab84fc97b053a8db0879e2e8ab5a Mon Sep 17 00:00:00 2001 From: hmmachadocx Date: Thu, 29 Aug 2024 16:24:26 +0100 Subject: [PATCH 1/3] Support Critical Severity --- checkmarx-ast-eclipse-plugin/icons/critical.png | Bin 0 -> 615 bytes .../com/checkmarx/eclipse/enums/ActionName.java | 1 + .../checkmarx/eclipse/views/CheckmarxView.java | 4 ++-- .../com/checkmarx/eclipse/views/DataProvider.java | 12 +++++++++++- .../eclipse/views/filters/ActionFilters.java | 6 +++++- .../eclipse/views/filters/FilterState.java | 8 ++++++++ 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 checkmarx-ast-eclipse-plugin/icons/critical.png diff --git a/checkmarx-ast-eclipse-plugin/icons/critical.png b/checkmarx-ast-eclipse-plugin/icons/critical.png new file mode 100644 index 0000000000000000000000000000000000000000..ad86fc35a29e9e3c1ba2c771dcade5c933c601a0 GIT binary patch literal 615 zcmV-t0+{`YP)KqTl=PIe6> zPlZrWPzzRK7#Ml!5QNmBQxJIwB0EJEu2zQ#q@Z0wox>&=MY-0Jp$NLW^L1Fq9e2n1 zPA}j0{?GrtKl~6-@uueXv8b7fN6oe%pYm(IjU0+Nn%*Z$&LU_)P835pa;M!+rZ$Dd zqvrh(YL_5~fpEaZGYa(?apo;M83WKgw2OjN2CcnTVL`$u&&Lqb%^pnw$#*MK72sMHUoR$HktPyIB@+MJFH{Ako7nMtFEp+X;EPq zeCh7x@5fKfy&Pfr`ww!9OWw0tKS SEVERITY_ORDER = Arrays.asList("CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"); + private static final String LIMIT_FILTER="limit=10000"; private static final String FILTER_SCANS_FOR_PROJECT = "project-id=%s,branch=%s,limit=10000,statuses=Completed"; @@ -418,7 +421,7 @@ private Map> filterResultsByScannerType(List> filteredResultsByScannerType) { filteredResultsByScannerType.entrySet().stream().forEach(entry -> { - Map> mapBySeverity = new HashMap<>(); + Map> mapBySeverity = new LinkedHashMap<>(); String scanner = entry.getKey(); List vulnerabilities = entry.getValue(); @@ -432,6 +435,13 @@ private void groupResultsBySeverity(Map> filteredResu } } + Map> sortedMapBySeverity = new LinkedHashMap<>(); + SEVERITY_ORDER.forEach(severity -> { + if (mapBySeverity.containsKey(severity)) { + sortedMapBySeverity.put(severity, mapBySeverity.get(severity)); + } + }); + List children = createParentNodeByScanner(mapBySeverity); filteredResultsByScannerType.put(scanner, children); diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java index f467475..49a6ee0 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java @@ -14,6 +14,9 @@ public class ActionFilters { + private static final String ACTION_FILTER_CRITICAL_TOOLTIP = "Critical"; + private static final String ACTION_FILTER_CRITICAL_ICON_PATH = "/icons/critical.png"; + private static final String ACTION_FILTER_HIGH_TOOLTIP = "High"; private static final String ACTION_FILTER_HIGH_ICON_PATH = "/icons/high_untoggle.png"; @@ -42,12 +45,13 @@ public ActionFilters(EventBus pluginEventBus) { public List createFilterActions(){ List filters = new ArrayList<>(); + Action filterCriticalAction = createFilterAction(ACTION_FILTER_CRITICAL_TOOLTIP, ACTION_FILTER_CRITICAL_ICON_PATH, Severity.CRITICAL, ActionName.CRITICAL); Action filterHighAction = createFilterAction(ACTION_FILTER_HIGH_TOOLTIP, ACTION_FILTER_HIGH_ICON_PATH, Severity.HIGH, ActionName.HIGH); Action filterMediumAction = createFilterAction(ACTION_FILTER_MEDIUM_TOOLTIP, ACTION_FILTER_MEDIUM_ICON_PATH, Severity.MEDIUM, ActionName.MEDIUM); Action filterLowAction = createFilterAction(ACTION_FILTER_LOW_TOOLTIP, ACTION_FILTER_LOW_ICON_PATH, Severity.LOW, ActionName.LOW); Action filterInfoAction = createFilterAction(ACTION_FILTER_INFO_TOOLTIP, ACTION_FILTER_INFO_ICON_PATH, Severity.INFO, ActionName.INFO); - + filters.add(filterCriticalAction); filters.add(filterHighAction); filters.add(filterMediumAction); filters.add(filterLowAction); diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java index b7c00c4..2ff44cc 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java @@ -7,6 +7,7 @@ public class FilterState { + public static boolean critical = true; public static boolean high = true; public static boolean medium = true; public static boolean low = false; @@ -30,6 +31,7 @@ public class FilterState { public static void loadFiltersFromSettings() { + critical = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.CRITICAL.name(), "true")); high = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.HIGH.name(), "true")); medium = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.MEDIUM.name(), "true")); low = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.LOW.name(), "false")); @@ -54,6 +56,10 @@ public static void loadFiltersFromSettings() { */ public static void setState(Severity severity) { switch(severity) { + case CRITICAL: + critical = !critical; + GlobalSettings.storeInPreferences(Severity.CRITICAL.name(), String.valueOf(critical)); + break; case HIGH: high = !high; GlobalSettings.storeInPreferences(Severity.HIGH.name(), String.valueOf(high)); @@ -147,6 +153,7 @@ public static boolean isFilterStateEnabled(String state) { */ public static boolean isSeverityEnabled(String severity) { switch(Severity.getSeverity(severity)) { + case CRITICAL: return critical; case HIGH: return high; case MEDIUM: return medium; case LOW: return low; @@ -165,6 +172,7 @@ public static boolean isSeverityEnabled(String severity) { * Reset filters state */ public static void resetFilters() { + critical = true; high = true; medium = true; low = false; From 6bc5eb2397d99bd2f15e0d845a971627cebde752 Mon Sep 17 00:00:00 2001 From: hmmachadocx Date: Thu, 29 Aug 2024 17:40:47 +0100 Subject: [PATCH 2/3] Display triage error message --- .../eclipse/views/CheckmarxView.java | 20 +++++++------------ .../checkmarx/eclipse/views/DataProvider.java | 8 ++++---- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java index ddc6f88..9c2a816 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java @@ -1303,9 +1303,9 @@ public void widgetSelected(SelectionEvent event) { @Override protected IStatus run(IProgressMonitor arg0) { - boolean successfullyUpdate = DataProvider.getInstance().triageUpdate(projectId, - similarityId, engineType, selectedState, comment, selectedSeverity); - if (successfullyUpdate) { + try { + DataProvider.getInstance().triageUpdate(projectId,similarityId, engineType, selectedState, comment, selectedSeverity); + sync.asyncExec(() -> { selectedItem.setSeverity(selectedSeverity); selectedItem.setState(selectedState); @@ -1321,16 +1321,10 @@ protected IStatus run(IProgressMonitor arg0) { commentText.setText(PluginConstants.DEFAULT_COMMENT_TXT); commentText.setEditable(true); }); - } else { - // TODO: inform the user that update failed? -// sync.asyncExec(() -> { -// MessageBox box = new MessageBox(parent.getDisplay().getActiveShell(), SWT.CANCEL | SWT.OK); -// box.setText("Triage failed"); -// // correct the message -// box.setMessage("Triage update failed. Check logs"); -// box.open(); -// }); - + } catch (Exception e) { + sync.asyncExec(() -> { + new NotificationPopUpUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay(), "Triage failed", e.getMessage(), null, null, null).open(); + }); } // reset the triageButton when triage update fails diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java index ff41f24..13f4b3e 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java @@ -669,8 +669,9 @@ public List getTriageShow(UUID projectID, String similarityID, String * @param state * @param comment * @param severity + * @throws Exception */ - public boolean triageUpdate(UUID projectId, String similarityId, String engineType, String state, String comment, String severity) { + public void triageUpdate(UUID projectId, String similarityId, String engineType, String state, String comment, String severity) throws Exception { try { CxWrapper cxWrapper = authenticateWithAST(); @@ -678,11 +679,10 @@ public boolean triageUpdate(UUID projectId, String similarityId, String engineTy if (cxWrapper != null) { cxWrapper.triageUpdate(projectId, similarityId, engineType, state, comment, severity); } - - return true; } catch (Exception e) { CxLogger.error(String.format(PluginConstants.ERROR_UPDATING_TRIAGE, e.getMessage()), e); - return false; + throw new Exception(e.getMessage()); + } } From 45328d5ea9d15140f230f7c0b4af2f51696449f9 Mon Sep 17 00:00:00 2001 From: hmmachadocx Date: Thu, 29 Aug 2024 17:59:00 +0100 Subject: [PATCH 3/3] Fix icons in second panel --- .../src/com/checkmarx/eclipse/views/CheckmarxView.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java index 9c2a816..dde4393 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java @@ -1213,14 +1213,10 @@ protected IStatus run(IProgressMonitor arg0) { } private void populateTitleLabel(DisplayModel selectedItem) { - ImageData titleImageData = findSeverityImage(selectedItem).getImageData() - .scaledTo(PluginConstants.TITLE_LABEL_WIDTH, PluginConstants.TITLE_LABEL_HEIGHT); - Image titleImage = new Image(parent.getShell().getDisplay(), titleImageData); - titleLabel.setImage(titleImage); + titleLabel.setImage(findSeverityImage(selectedItem)); titleText.setText(selectedItem.getName()); titleLabel.layout(); titleText.requestLayout(); - } }); }