Skip to content

Commit 92a5efb

Browse files
API Key change behaviour (AST-104763) (#220)
* Credentials change behaviour of plugin * Code changes for triage Notes area * Disable missing server url test case
1 parent cac206a commit 92a5efb

4 files changed

Lines changed: 46 additions & 10 deletions

File tree

checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/TestUI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
1919
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
2020
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton;
21+
import org.junit.Ignore;
2122
import org.junit.Test;
2223
import org.junit.runner.RunWith;
2324

@@ -68,6 +69,7 @@ public void testAddCheckmarxASTPlugin() throws TimeoutException {
6869
}
6970

7071
@Test
72+
@Ignore("Disabled due we changed behaviour of credeantials to show Open Setting window on clearing credentials")
7173
public void testMissingSetCheckmarxServerUrl() throws TimeoutException {
7274
// Test Connection
7375
testSuccessfulConnection(false);

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/utils/PluginConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class PluginConstants {
1515
public static final String NO_CHANGES = "No changes...";
1616
public static final String BTN_UPDATE = "Update";
1717
public static final String BTN_LOADING = "Loading";
18-
public static final String DEFAULT_COMMENT_TXT = "Notes";
18+
public static final String DEFAULT_COMMENT_TXT = "Notes (Optional or required based on tenant configuration)";
1919
public static final String LOADING_BFL = "Loading BFL";
2020
public static final String BFL_FOUND = "Indicates the Best Fix Location. Speed up your remediation by fixing multiple vulnerabilities at once";
2121
public static final String BFL_NOT_FOUND = "Best fix Location not available for given results";

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
import com.checkmarx.eclipse.Activator;
8989
import com.checkmarx.eclipse.enums.ActionName;
9090
import com.checkmarx.eclipse.enums.Severity;
91+
import com.checkmarx.eclipse.properties.Preferences;
9192
import com.checkmarx.eclipse.utils.CxLogger;
9293
import com.checkmarx.eclipse.utils.NotificationPopUpUI;
9394
import com.checkmarx.eclipse.utils.PluginConstants;
@@ -160,6 +161,7 @@ public class CheckmarxView extends ViewPart implements EventHandler {
160161
private Button triageButton;
161162
private SelectionAdapter triageButtonAdapter, codeBashingAdapter;
162163
private Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
164+
private String lastApiKey;
163165

164166
private boolean alreadyRunning = false;
165167
private static List<LearnMore> learnMoreData;
@@ -207,6 +209,7 @@ public class CheckmarxView extends ViewPart implements EventHandler {
207209
public CheckmarxView() {
208210
super();
209211
sync = new UISynchronizeImpl(PlatformUI.getWorkbench().getDisplay());
212+
lastApiKey = Preferences.STORE.getString(Preferences.API_KEY);
210213
rootModel = new DisplayModel.DisplayModelBuilder(PluginConstants.EMPTY_STRING).build();
211214
globalSettings.loadSettings();
212215
currentProjectId = globalSettings.getProjectId();
@@ -714,9 +717,17 @@ private void drawAttackVectorSeparator(Composite parent) {
714717
* Draw panel when Checkmarx credentials are not defined
715718
*/
716719
private void drawMissingCredentialsPanel() {
720+
721+
// Dispose all children to remove any previous panels
722+
for (Control child : parent.getChildren()) {
723+
child.dispose();
724+
}
717725
openSettingsComposite = new Composite(parent, SWT.NONE);
718726

719727
openSettingsComposite.setLayout(new GridLayout(1, true));
728+
729+
// This is the key line: center horizontally and vertically, and expand to fill
730+
openSettingsComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
720731

721732
final Label hidden = new Label(openSettingsComposite, SWT.NONE);
722733
hidden.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
@@ -742,6 +753,7 @@ public void handleEvent(Event arg0) {
742753
}
743754
}
744755
});
756+
parent.layout(true, true);
745757
}
746758

747759
private void createProjectListComboBox(Composite parent) {
@@ -779,7 +791,6 @@ public void selectionChanged(SelectionChangedEvent event) {
779791
updateStartScanButton(false);
780792
return;
781793
}
782-
783794
// Avoid non-sense trigger changed when opening the combo
784795
if (selectedProject.getId().equals(currentProjectId)) {
785796
CxLogger.info(PluginConstants.INFO_CHANGE_PROJECT_EVENT_NOT_TRIGGERED);
@@ -1153,6 +1164,7 @@ private String formatScanLabel(Scan scan) {
11531164
*/
11541165

11551166
private Scan getLatestScanFromScanList(List<Scan> scanList) {
1167+
11561168
return scanList.get(0);
11571169
}
11581170

@@ -1425,7 +1437,7 @@ public void widgetSelected(SelectionEvent event) {
14251437

14261438
Job job = new Job("Checkmarx: Updating triage information...") {
14271439
String comment = commentText.getText() != null
1428-
&& !commentText.getText().equalsIgnoreCase("Notes") ? commentText.getText()
1440+
&& !commentText.getText().equalsIgnoreCase("Notes (Optional or required based on tenant configuration)") ? commentText.getText()
14291441
: "";
14301442

14311443
@Override
@@ -2686,16 +2698,32 @@ private void enablePluginFields(boolean enableBranchCombobox) {
26862698
*/
26872699
@Override
26882700
public void handleEvent(org.osgi.service.event.Event arg0) {
2689-
if (!isPluginDraw) {
2701+
String currentApiKey = Preferences.STORE.getString(Preferences.API_KEY);
2702+
if (!currentApiKey.isEmpty() && !isPluginDraw) {
26902703
drawPluginPanel();
26912704
} else {
2692-
// If authenticated successfully and the projects are empty try to get them again
2693-
if (projectComboViewer.getCombo().getItemCount() == 0) {
2694-
clearAndRefreshPlugin();
2705+
// If credentials changed reload projects, branches and scans from new tenant
2706+
if (currentApiKey.isEmpty()) {
2707+
updateStartScanButton(false);
2708+
drawMissingCredentialsPanel();
2709+
//Dispose toolbar
2710+
if (toolBarActions != null) {
2711+
toolBarActions.disposeToolbar();
2712+
toolBarActions = null;
2713+
}
2714+
isPluginDraw = false;
2715+
} else if (lastApiKey.equalsIgnoreCase(currentApiKey)) {
2716+
return;
2717+
} else {
2718+
// clear result section
2719+
PluginUtils.clearMessage(rootModel, resultsTree);
2720+
// Reset state variables
2721+
currentProjectId = PluginConstants.EMPTY_STRING;
2722+
currentBranch = PluginConstants.EMPTY_STRING;
2723+
currentScanId = PluginConstants.EMPTY_STRING;
2724+
loadComboboxes();
26952725
}
2696-
2697-
toolBarActions.refreshToolbar();
2698-
updateStartScanButton(true);
2726+
lastApiKey=currentApiKey;
26992727
}
27002728
}
27012729

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ToolBarActions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ public void run() {
129129
};
130130
job.schedule();
131131
}
132+
133+
public void disposeToolbar() {
134+
IToolBarManager toolBarManager = actionBars.getToolBarManager();
135+
toolBarManager.removeAll();
136+
actionBars.getMenuManager().removeAll();
137+
}
132138

133139
public void refreshToolbar() {
134140
IToolBarManager toolBarManager = actionBars.getToolBarManager();

0 commit comments

Comments
 (0)