diff --git a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/CodewindCorePlugin.java b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/CodewindCorePlugin.java index 753533247..7855b65b6 100644 --- a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/CodewindCorePlugin.java +++ b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/CodewindCorePlugin.java @@ -36,13 +36,14 @@ public class CodewindCorePlugin extends AbstractUIPlugin { public static final String DEFAULT_ICON_PATH = "icons/codewind.png"; //$NON-NLS-1$ - public static final String CW_INSTALL_TIMEOUT = "cwInstallTimeout"; - public static final String CW_START_TIMEOUT = "cwStartTimeout"; - public static final String CW_STOP_TIMEOUT = "cwStopTimeout"; - public static final String CW_UNINSTALL_TIMEOUT = "cwUninstallTimeout"; + public static final String CW_INSTALL_TIMEOUT = "cwInstallTimeout"; //$NON-NLS-1$ + public static final String CW_START_TIMEOUT = "cwStartTimeout"; //$NON-NLS-1$ + public static final String CW_STOP_TIMEOUT = "cwStopTimeout"; //$NON-NLS-1$ + public static final String CW_UNINSTALL_TIMEOUT = "cwUninstallTimeout"; //$NON-NLS-1$ - public static final String AUTO_OPEN_OVERVIEW_PAGE = "autoOpenOverviewPage"; - public static final String ENABLE_SUPPORT_FEATURES = "enableSupportFeatures"; + public static final String AUTO_OPEN_OVERVIEW_PAGE = "autoOpenOverviewPage"; //$NON-NLS-1$ + public static final String ENABLE_KEYRING_ACCESS = "enabledKeyringAccess"; //$NON-NLS-1$ + public static final String ENABLE_SUPPORT_FEATURES = "enableSupportFeatures"; //$NON-NLS-1$ public static final String // Int option for debug timeout in seconds @@ -83,6 +84,7 @@ public void start(BundleContext context) throws Exception { getPreferenceStore().setDefault(CW_START_TIMEOUT, InstallUtil.START_TIMEOUT_DEFAULT); getPreferenceStore().setDefault(CW_STOP_TIMEOUT, InstallUtil.STOP_TIMEOUT_DEFAULT); getPreferenceStore().setDefault(AUTO_OPEN_OVERVIEW_PAGE, true); + getPreferenceStore().setDefault(ENABLE_KEYRING_ACCESS, true); getPreferenceStore().setDefault(ENABLE_SUPPORT_FEATURES, false); } diff --git a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/cli/CLIUtil.java b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/cli/CLIUtil.java index c4072db29..405437733 100644 --- a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/cli/CLIUtil.java +++ b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/cli/CLIUtil.java @@ -32,9 +32,7 @@ import org.eclipse.codewind.core.internal.PlatformUtil; import org.eclipse.codewind.core.internal.PlatformUtil.OperatingSystem; import org.eclipse.codewind.core.internal.ProcessHelper.ProcessResult; -import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; import org.json.JSONException; import org.json.JSONObject; @@ -45,6 +43,7 @@ public class CLIUtil { // Global options public static final String JSON_OPTION = "--json"; public static final String INSECURE_OPTION = "--insecure"; + public static final String INSECURE_KEYRING_OPTION = "--insecureKeyring"; public static final String[] GLOBAL_JSON = new String[] {JSON_OPTION}; public static final String[] GLOBAL_INSECURE = new String[] {INSECURE_OPTION}; public static final String[] GLOBAL_JSON_INSECURE = new String[] {JSON_OPTION, INSECURE_OPTION}; @@ -91,6 +90,9 @@ public static Process runCWCTL(String[] globalOptions, String[] cmd, String[] op List cmdList = new ArrayList(); cmdList.add(codewindInfo.getInstallPath()); + if (!CodewindCorePlugin.getDefault().getPreferenceStore().getBoolean(CodewindCorePlugin.ENABLE_KEYRING_ACCESS)) { + cmdList.add(INSECURE_KEYRING_OPTION); + } addOptions(cmdList, globalOptions); addOptions(cmdList, cmd); addOptions(cmdList, options); @@ -222,4 +224,18 @@ public static void checkResult(String[] command, ProcessResult result, boolean c Logger.log(String.format("Result of the cwctl '%s' command: \n%s", CoreUtil.formatString(command, " "), Optional.ofNullable(result.getOutput()).orElse(""))); } + + public static String getErrorKey(ProcessResult result) { + try { + if (result.getOutput() != null && !result.getOutput().isEmpty()) { + JSONObject obj = new JSONObject(result.getOutput()); + if (obj.has(ERROR_KEY)) { + return obj.getString(ERROR_KEY); + } + } + } catch (JSONException e) { + // Ignore + } + return null; + } } diff --git a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/cli/InstallUtil.java b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/cli/InstallUtil.java index 4d1584494..fc4d81366 100644 --- a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/cli/InstallUtil.java +++ b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/cli/InstallUtil.java @@ -17,6 +17,7 @@ import org.eclipse.codewind.core.CodewindCorePlugin; import org.eclipse.codewind.core.internal.CodewindManager; import org.eclipse.codewind.core.internal.CodewindManager.InstallerStatus; +import org.eclipse.codewind.core.internal.CoreUtil; import org.eclipse.codewind.core.internal.Logger; import org.eclipse.codewind.core.internal.ProcessHelper; import org.eclipse.codewind.core.internal.ProcessHelper.ProcessResult; @@ -79,6 +80,23 @@ public static InstallStatus getInstallStatus(IProgressMonitor monitor) throws IO } public static ProcessResult startCodewind(String version, IProgressMonitor monitor) throws IOException, TimeoutException { + SubMonitor mon = SubMonitor.convert(monitor, 100); + ProcessResult result = doStartCodewind(version, mon.split(75)); + IPreferenceStore prefs = CodewindCorePlugin.getDefault().getPreferenceStore(); + if (prefs.getBoolean(CodewindCorePlugin.ENABLE_KEYRING_ACCESS) && result.getExitValue() != 0 + && "sec_keyring".equals(CLIUtil.getErrorKey(result))) { + // Ask the user if they want to disable keyring access and try again + if (CoreUtil.openConfirmDialog(Messages.StartFailForKeyringTitle, Messages.StartFailForKeyringMsg)) { + prefs.setValue(CodewindCorePlugin.ENABLE_KEYRING_ACCESS, false); + result = doStartCodewind(version, mon.split(25)); + } else { + mon.setCanceled(true); + } + } + return result; + } + + private static ProcessResult doStartCodewind(String version, IProgressMonitor monitor) throws IOException, TimeoutException { SubMonitor mon = SubMonitor.convert(monitor, Messages.StartCodewindJobLabel, 100); Process process = null; try { diff --git a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/messages/Messages.java b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/messages/Messages.java index a034203c4..24060e20d 100644 --- a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/messages/Messages.java +++ b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/messages/Messages.java @@ -105,6 +105,9 @@ public class Messages extends NLS { public static String DebugPortNotifyTitle; public static String DebugPortNotifyMsg; + + public static String StartFailForKeyringTitle; + public static String StartFailForKeyringMsg; static { // initialize resource bundle diff --git a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/messages/messages.properties b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/messages/messages.properties index c46fb798b..266ad7507 100644 --- a/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/messages/messages.properties +++ b/dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/messages/messages.properties @@ -98,3 +98,6 @@ UpgradeResultNotMigrated=Problems were encountered migrating these projects. Try DebugPortNotifyTitle=Debug port available for {0} DebugPortNotifyMsg=The debug port for {0} is now available: {1} + +StartFailForKeyringTitle=Keyring Not Available +StartFailForKeyringMsg=Codewind did not start because the keyring could not be accessed. Do you want to disable Codewind keyring access? Projects that require image registries may not work if access is disabled. You can change the setting at any time in the Codewind preferences. diff --git a/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/Messages.java b/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/Messages.java index a6138de15..9071b27b0 100644 --- a/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/Messages.java +++ b/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/Messages.java @@ -27,6 +27,7 @@ public class Messages extends NLS { public static String PrefsParentPage_GeneralGroup; public static String PrefsParentPage_AutoOpenOverviewButton; + public static String PrefsParentPage_EnableKeyring; public static String PrefsParentPage_EnableSupportFeatures; public static String PrefsParentPage_StartupShutdownGroup; public static String PrefsParentPage_InstallTimeout; diff --git a/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/messages.properties b/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/messages.properties index c8969d635..63ef2e2dc 100644 --- a/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/messages.properties +++ b/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/messages.properties @@ -20,6 +20,7 @@ ConnectionPrefsPage_URLColumn=URL PrefsParentPage_GeneralGroup=&General Settings PrefsParentPage_AutoOpenOverviewButton=&Open overview page on project create and add +PrefsParentPage_EnableKeyring=Enable Codewind &keyring access PrefsParentPage_EnableSupportFeatures=Enable support &features PrefsParentPage_StartupShutdownGroup=&Startup and Shutdown Settings PrefsParentPage_InstallTimeout=Codewind &install timeout (s): diff --git a/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/prefs/CodewindPrefsParentPage.java b/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/prefs/CodewindPrefsParentPage.java index d152f44b7..34ba52c72 100644 --- a/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/prefs/CodewindPrefsParentPage.java +++ b/dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/prefs/CodewindPrefsParentPage.java @@ -141,6 +141,18 @@ public void widgetSelected(SelectionEvent e) { } }); + Button enableKeyringButton = new Button(generalGroup, SWT.CHECK); + enableKeyringButton.setText(Messages.PrefsParentPage_EnableKeyring); + enableKeyringButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.FILL, false, false)); + enableKeyringButton.setSelection(prefs.getBoolean(CodewindCorePlugin.ENABLE_KEYRING_ACCESS)); + + enableKeyringButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + prefs.setValue(CodewindCorePlugin.ENABLE_KEYRING_ACCESS, enableKeyringButton.getSelection()); + } + }); + Button supportFeaturesButton = new Button(generalGroup, SWT.CHECK); supportFeaturesButton.setText(Messages.PrefsParentPage_EnableSupportFeatures); supportFeaturesButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.FILL, false, false));