From 46cd633735bd673e333825d1598b1c048d1b4e9c Mon Sep 17 00:00:00 2001 From: jacobtr Date: Wed, 1 Mar 2023 14:27:27 +0100 Subject: [PATCH 1/4] (feat) Makes sure password is never stored in preferences Instead asks user for the password at the start of the program if they have enabled proxy with password. --- src/main/java/org/jabref/gui/JabRefGUI.java | 10 ++++++++++ .../jabref/gui/preferences/PreferencesDialogView.java | 2 ++ .../java/org/jabref/preferences/JabRefPreferences.java | 3 +-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index 4f5963945ea..57cdf7f8307 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.stream.Collectors; +import com.airhacks.afterburner.injection.Injector; import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.input.KeyEvent; @@ -17,6 +18,7 @@ import org.jabref.gui.importer.ParserResultWarningDialog; import org.jabref.gui.importer.actions.OpenDatabaseAction; import org.jabref.gui.keyboard.TextInputKeyBindings; +import org.jabref.gui.preferences.PreferencesDialogView; import org.jabref.gui.shared.SharedDatabaseUIManager; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; @@ -26,6 +28,7 @@ import org.jabref.logic.util.WebViewStore; import org.jabref.preferences.GuiPreferences; import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.JabRefPreferences; import impl.org.controlsfx.skin.DecorationPane; import org.slf4j.Logger; @@ -61,6 +64,13 @@ public JabRefGUI(Stage mainStage, List databases, boolean isBlank, Globals.TASK_EXECUTOR, preferencesService.getInternalPreferences()) .checkForNewVersionDelayed(); + + if (JabRefPreferences.getInstance().getProxyPreferences().shouldUseAuthentication()){ + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + PreferencesDialogView preferencesDialogView = new PreferencesDialogView(this.mainFrame); + preferencesDialogView.getPreferenceTabList().getSelectionModel().select(20); + dialogService.showCustomDialog(preferencesDialogView); + } } private void openWindow(Stage mainStage) { diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java index f3a5c245913..089b09f693a 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java @@ -67,6 +67,8 @@ public PreferencesDialogViewModel getViewModel() { return viewModel; } + public ListView getPreferenceTabList() {return preferenceTabList;} + @FXML private void initialize() { viewModel = new PreferencesDialogViewModel(dialogService, preferencesService, frame); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 3ea8f83a45b..c5104e3ad41 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -1552,14 +1552,13 @@ public ProxyPreferences getProxyPreferences() { get(PROXY_PORT), getBoolean(PROXY_USE_AUTHENTICATION), get(PROXY_USERNAME), - get(PROXY_PASSWORD)); + (String) defaults.get(PROXY_PASSWORD)); EasyBind.listen(proxyPreferences.useProxyProperty(), (obs, oldValue, newValue) -> putBoolean(PROXY_USE, newValue)); EasyBind.listen(proxyPreferences.hostnameProperty(), (obs, oldValue, newValue) -> put(PROXY_HOSTNAME, newValue)); EasyBind.listen(proxyPreferences.portProperty(), (obs, oldValue, newValue) -> put(PROXY_PORT, newValue)); EasyBind.listen(proxyPreferences.useAuthenticationProperty(), (obs, oldValue, newValue) -> putBoolean(PROXY_USE_AUTHENTICATION, newValue)); EasyBind.listen(proxyPreferences.usernameProperty(), (obs, oldValue, newValue) -> put(PROXY_USERNAME, newValue)); - EasyBind.listen(proxyPreferences.passwordProperty(), (obs, oldValue, newValue) -> put(PROXY_PASSWORD, newValue)); return proxyPreferences; } From 01c529c3593ed80ab8b44b19b125458ae56ee255 Mon Sep 17 00:00:00 2001 From: Jakob Ewaldsson Date: Fri, 3 Mar 2023 12:54:45 +0100 Subject: [PATCH 2/4] (feat) #2 Added password dialog --- .../java/org/jabref/gui/DialogService.java | 9 +++++++ .../org/jabref/gui/JabRefDialogService.java | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/main/java/org/jabref/gui/DialogService.java b/src/main/java/org/jabref/gui/DialogService.java index 26cf46c00a1..3be1432d54e 100644 --- a/src/main/java/org/jabref/gui/DialogService.java +++ b/src/main/java/org/jabref/gui/DialogService.java @@ -14,6 +14,7 @@ import javafx.scene.control.ChoiceDialog; import javafx.scene.control.DialogPane; import javafx.scene.control.TextInputDialog; +import org.controlsfx.control.textfield.CustomPasswordField; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.DirectoryDialogConfiguration; @@ -161,6 +162,14 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content, String okButtonLabel, String cancelButtonLabel, String optOutMessage, Consumer optOutAction); + /** + * This will create and display new {@link CustomPasswordField} that doesn't show the text, and two buttons + * one cancel and one ok. + * + * @return the entered password if pressed "OK", null otherwise + */ + Optional showPasswordDialogAndWait(String title, String header, String content); + /** * Shows a custom dialog without returning any results. * diff --git a/src/main/java/org/jabref/gui/JabRefDialogService.java b/src/main/java/org/jabref/gui/JabRefDialogService.java index d21e0b3b9d9..9709223cc2b 100644 --- a/src/main/java/org/jabref/gui/JabRefDialogService.java +++ b/src/main/java/org/jabref/gui/JabRefDialogService.java @@ -26,6 +26,7 @@ import javafx.scene.control.DialogPane; import javafx.scene.control.Label; import javafx.scene.control.TextInputDialog; +import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; @@ -49,6 +50,7 @@ import com.tobiasdiez.easybind.EasyBind; import org.controlsfx.control.Notifications; import org.controlsfx.control.TaskProgressView; +import org.controlsfx.control.textfield.CustomPasswordField; import org.controlsfx.dialog.ExceptionDialog; import org.controlsfx.dialog.ProgressDialog; import org.slf4j.Logger; @@ -270,6 +272,30 @@ public Optional showCustomDialogAndWait(javafx.scene.control.Dialog di return dialog.showAndWait(); } + @Override + public Optional showPasswordDialogAndWait(String title, String header, String content) { + javafx.scene.control.Dialog dialog = new javafx.scene.control.Dialog<>(); + dialog.setTitle(title); + dialog.setHeaderText(header); + + CustomPasswordField passwordField = new CustomPasswordField(); + + HBox box = new HBox(); + box.setSpacing(10); + box.getChildren().addAll(new Label(content), passwordField); + dialog.setTitle(title); + dialog.getDialogPane().setContent(box); + + dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK); + dialog.setResultConverter(dialogButton -> { + if (dialogButton == ButtonType.OK) { + return passwordField.getText(); + } + return null; + }); + return dialog.showAndWait(); + } + @Override public void showProgressDialog(String title, String content, Task task) { ProgressDialog progressDialog = new ProgressDialog(task); From 828110f3d3ff71e438bc7023aa52c84c3b7c6d0b Mon Sep 17 00:00:00 2001 From: Jakob Ewaldsson Date: Fri, 3 Mar 2023 14:09:15 +0100 Subject: [PATCH 3/4] (feat) #2 Added functionality for password dialog pop up. It is triggered from JabRefGUI if proxy requires password --- src/main/java/org/jabref/gui/JabRefGUI.java | 13 +++++++------ .../gui/preferences/PreferencesDialogView.java | 2 -- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index 57cdf7f8307..1ee881737c9 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -18,17 +18,16 @@ import org.jabref.gui.importer.ParserResultWarningDialog; import org.jabref.gui.importer.actions.OpenDatabaseAction; import org.jabref.gui.keyboard.TextInputKeyBindings; -import org.jabref.gui.preferences.PreferencesDialogView; import org.jabref.gui.shared.SharedDatabaseUIManager; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.net.ProxyRegisterer; import org.jabref.logic.shared.DatabaseNotSupportedException; import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.logic.shared.exception.NotASharedDatabaseException; import org.jabref.logic.util.WebViewStore; import org.jabref.preferences.GuiPreferences; import org.jabref.preferences.PreferencesService; -import org.jabref.preferences.JabRefPreferences; import impl.org.controlsfx.skin.DecorationPane; import org.slf4j.Logger; @@ -65,11 +64,13 @@ public JabRefGUI(Stage mainStage, List databases, boolean isBlank, preferencesService.getInternalPreferences()) .checkForNewVersionDelayed(); - if (JabRefPreferences.getInstance().getProxyPreferences().shouldUseAuthentication()){ + if (preferencesService.getProxyPreferences().shouldUseAuthentication()){ DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - PreferencesDialogView preferencesDialogView = new PreferencesDialogView(this.mainFrame); - preferencesDialogView.getPreferenceTabList().getSelectionModel().select(20); - dialogService.showCustomDialog(preferencesDialogView); + dialogService.showPasswordDialogAndWait("Proxy configuration", "Proxy requires password","Password") + .ifPresent(newPassword -> { + preferencesService.getProxyPreferences().setPassword(newPassword); + ProxyRegisterer.register(preferencesService.getProxyPreferences()); + }); } } diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java index 089b09f693a..f3a5c245913 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java @@ -67,8 +67,6 @@ public PreferencesDialogViewModel getViewModel() { return viewModel; } - public ListView getPreferenceTabList() {return preferenceTabList;} - @FXML private void initialize() { viewModel = new PreferencesDialogViewModel(dialogService, preferencesService, frame); From cb3cac3f3e07ef02f291d87b7f4dcdd735f2ebd1 Mon Sep 17 00:00:00 2001 From: Jakob Ewaldsson Date: Mon, 6 Mar 2023 09:37:38 +0100 Subject: [PATCH 4/4] (fix) #2 proxy-password popup now only triggers if both proxy and authentication are enabled, before only auth was checked --- src/main/java/org/jabref/gui/JabRefGUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index 1ee881737c9..5dda14310aa 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -64,7 +64,7 @@ public JabRefGUI(Stage mainStage, List databases, boolean isBlank, preferencesService.getInternalPreferences()) .checkForNewVersionDelayed(); - if (preferencesService.getProxyPreferences().shouldUseAuthentication()){ + if (preferencesService.getProxyPreferences().shouldUseProxy() && preferencesService.getProxyPreferences().shouldUseAuthentication()){ DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); dialogService.showPasswordDialogAndWait("Proxy configuration", "Proxy requires password","Password") .ifPresent(newPassword -> {