Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AuthenticatorIntegrationTest extends BaseIntegrationTest {

@Test
public void testSuccessfulAuthentication() {
authenticator = new Authenticator(LoggerFactory.getLogger(Authenticator.class));
authenticator = new Authenticator();
System.out.println("\n=== Starting Authentication Test ===");
System.out.println("Current directory: " + new File(".").getAbsolutePath());
System.out.println("API Key available: " + (VALID_API_KEY != null));
Expand All @@ -31,7 +31,7 @@ public void testSuccessfulAuthentication() {

@Test
public void testInvalidApiKeyAuthentication() {
authenticator = new Authenticator(LoggerFactory.getLogger(Authenticator.class));
authenticator = new Authenticator();
System.out.println("\n=== Starting Invalid API Key Test ===");
String invalidApiKey = "invalid-api-key";
String result = authenticator.doAuthentication(invalidApiKey, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class Authenticator {

private Authenticator() {
public Authenticator() {
// Private constructor to prevent instantiation
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.checkmarx.eclipse.devassist.backend;

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

import com.checkmarx.eclipse.common.preferences.Preferences;
import com.checkmarx.eclipse.common.listener.IWorkspaceScanService;
import com.checkmarx.eclipse.common.utils.CxLogger;
import com.checkmarx.eclipse.devassist.backend.ScannerRegistry.ScannerType;
import java.util.EnumSet;

/**
* Listens for authentication state changes (CREDENTIALS_VALIDATED flag) and triggers
* workspace scan when user logs in.
*
* Problem it solves:
* - When user logs in, no preferences change, so ScannerPreferencesListener doesn't trigger scan
* - But we still need to scan projects that were opened before authentication
*
* Solution:
* - Listen to CREDENTIALS_VALIDATED changes
* - When it becomes true (login), trigger workspace scan immediately
* - ScannerPreferencesListener handles preference changes separately
*/
public class AuthenticationStateListener implements IPropertyChangeListener {

private static final String LOG_TAG = "[AUTH-STATE-LISTENER]";

@Override
public void propertyChange(PropertyChangeEvent event) {
if (event == null || event.getProperty() == null) {
return;
}

// Only respond to authentication state changes
if (!Preferences.CREDENTIALS_VALIDATED.equals(event.getProperty())) {
return;
}

Object newValue = event.getNewValue();
boolean nowAuthenticated = newValue instanceof Boolean && (Boolean) newValue;

// Only trigger scan on login (true), not on logout (false)
if (nowAuthenticated) {
CxLogger.info(LOG_TAG + " User authenticated - clearing scan cache and triggering workspace scan...");

// CRITICAL: Clear scan state cache so files that were never scanned (before authentication)
// are not treated as "unchanged" and skipped. Without this, files show as "cached/unchanged"
// and the scan is skipped even though they were never actually scanned before.
try {
CxLogger.info(LOG_TAG + " Clearing scan state cache for all scanners...");
EnumSet<ScannerType> allScanners = EnumSet.allOf(ScannerType.class);
ScanStateCacheClearer.clearForScanners(allScanners);
CxLogger.info(LOG_TAG + " ✓ Scan cache cleared");
} catch (Exception e) {
CxLogger.warning(LOG_TAG + " Error clearing scan cache: " + e.getMessage());
}

// Now trigger workspace scan with cleared cache
IWorkspaceScanService scanService = Preferences.getWorkspaceScanService();
if (scanService != null) {
try {
scanService.scanWorkspace();
CxLogger.info(LOG_TAG + " ✓ Workspace scan triggered on login");
} catch (Exception e) {
CxLogger.error(LOG_TAG + " Error triggering workspace scan: " + e.getMessage(), e);
}
} else {
CxLogger.warning(LOG_TAG + " Workspace scan service not available");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ private static void registerAuthenticationHandlers() {
// Register listener for MCP auto-install on API key change
Preferences.STORE.addPropertyChangeListener(new AuthenticationListener());

// Register listener for workspace scan trigger on authentication state change
// (when user logs in, preferences may not change, but we still need to scan)
Preferences.STORE.addPropertyChangeListener(new com.checkmarx.eclipse.devassist.backend.AuthenticationStateListener());

// Register handler for post-authentication UI (welcome dialog, workspace scan)
Preferences.setAuthenticationSuccessHandler(new AuthenticationSuccessHandler());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,14 @@ private static ITheme getActiveTheme() {
* on the Display: approximate dark mode from the widget background luminance.
*/
private static boolean isDarkByBackgroundLuminance() {
Color background = Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
Display display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
if (display == null) {
return false;
}
Color background = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
double luminance = (0.299 * background.getRed() + 0.587 * background.getGreen() + 0.114 * background.getBlue())
/ 255.0;
return luminance < 0.5;
Expand Down
Loading