diff --git a/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java b/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java index 42841a72f..5db312905 100644 --- a/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java +++ b/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java @@ -5,21 +5,25 @@ import dagger.Module; import dagger.Provides; import dagger.multibindings.IntoMap; import org.cryptomator.common.vaults.Vault; +import org.cryptomator.ui.changepassword.NewPasswordController; +import org.cryptomator.ui.changepassword.PasswordStrengthUtil; import org.cryptomator.ui.common.DefaultSceneFactory; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxControllerKey; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlLoaderFactory; import org.cryptomator.ui.common.FxmlScene; -import org.cryptomator.ui.changepassword.NewPasswordController; -import org.cryptomator.ui.changepassword.PasswordStrengthUtil; import org.cryptomator.ui.common.StageFactory; import org.cryptomator.ui.fxapp.PrimaryStage; import org.cryptomator.ui.recoverykey.RecoveryKeyDisplayController; import javax.inject.Named; import javax.inject.Provider; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; @@ -68,8 +72,14 @@ public abstract class AddVaultModule { @Provides @Named("shorteningThreshold") @AddVaultWizardScoped - static StringProperty provideShorteningThreshold() { - return new SimpleStringProperty(); + static IntegerProperty provideShorteningThreshold() { + return new SimpleIntegerProperty(CreateNewVaultAdvancedSettingsController.DEFAULT_SHORTENING_THRESHOLD); + } + + @Provides + @AddVaultWizardScoped + static BooleanProperty provideAdvancedSettingsEnabled() { + return new SimpleBooleanProperty(); } @Provides diff --git a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultAdvancedSettingsController.java b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultAdvancedSettingsController.java index a18b9e70d..f1c49289e 100644 --- a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultAdvancedSettingsController.java +++ b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultAdvancedSettingsController.java @@ -11,25 +11,21 @@ import javax.inject.Named; import javafx.application.Application; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.IntegerProperty; import javafx.fxml.FXML; import javafx.scene.Scene; import javafx.stage.Stage; -import java.nio.file.Path; -import java.util.ResourceBundle; @AddVaultWizardScoped public class CreateNewVaultAdvancedSettingsController implements FxController { + public static final int DEFAULT_SHORTENING_THRESHOLD = 220; + public static final int MIN_SHORTENING_THRESHOLD = 36; private static final String DOCS_MOUNTING_URL = "https://docs.cryptomator.org/en/1.7/security/architecture/#name-shortening"; private final Stage window; private final Lazy chooseLocationScene; private final Lazy choosePasswordScene; - private final ObjectProperty vaultPath; - private final StringProperty vaultName; - private final ResourceBundle resourceBundle; - private final StringProperty shorteningThreshold; + private IntegerProperty shorteningThreshold; public NumericTextField shorteningThresholdTextField; private final BooleanBinding validShorteningThreshold; private final Lazy application; @@ -39,24 +35,25 @@ public class CreateNewVaultAdvancedSettingsController implements FxController { Lazy application, // @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy chooseLocationScene, // @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy choosePasswordScene, // - ObjectProperty vaultPath, // - @Named("vaultName") StringProperty vaultName, // - ResourceBundle resourceBundle, // - @Named("shorteningThreshold") StringProperty shorteningThreshold) { + @Named("shorteningThreshold") IntegerProperty shorteningThreshold) { this.window = window; this.application = application; this.chooseLocationScene = chooseLocationScene; this.choosePasswordScene = choosePasswordScene; - this.vaultPath = vaultPath; - this.vaultName = vaultName; - this.resourceBundle = resourceBundle; this.shorteningThreshold = shorteningThreshold; this.validShorteningThreshold = Bindings.createBooleanBinding(this::isValidShorteningThreshold, shorteningThreshold); } @FXML public void initialize() { - shorteningThreshold.bindBidirectional(shorteningThresholdTextField.textProperty()); + shorteningThresholdTextField.textProperty().addListener((observable, oldValue, newValue) -> { + try { + int intValue = Integer.parseInt(newValue); + shorteningThreshold.set(intValue); + } catch (NumberFormatException e) { + shorteningThreshold.set(0); + } + }); } @FXML @@ -72,20 +69,14 @@ public class CreateNewVaultAdvancedSettingsController implements FxController { } public boolean isValidShorteningThreshold() { - if(shorteningThresholdTextField != null){ - try { - var value = Integer.parseInt(shorteningThresholdTextField.getText()); - if (value < 36 || value > 220) { - return false; - } - else{ - return true; - } - } catch (NumberFormatException e) { + try { + var value = shorteningThreshold.get(); + if (value < MIN_SHORTENING_THRESHOLD || value > DEFAULT_SHORTENING_THRESHOLD) { return false; + } else { + return true; } - } - else { + } catch (NumberFormatException e) { return false; } } diff --git a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java index 7e62f4aab..d9f54beea 100644 --- a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java +++ b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java @@ -8,14 +8,11 @@ import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.controls.FontAwesome5IconView; -import org.cryptomator.ui.controls.NumericTextField; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.inject.Named; -import javafx.beans.Observable; -import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; @@ -72,6 +69,7 @@ public class CreateNewVaultLocationController implements FxController { public FontAwesome5IconView goodLocation; public FontAwesome5IconView badLocation; public CheckBox advancedSettingsCheckBox; + private final BooleanProperty advancedSettingsEnabled; @Inject CreateNewVaultLocationController(@AddVaultWizardWindow Stage window, // @@ -80,7 +78,8 @@ public class CreateNewVaultLocationController implements FxController { @FxmlScene(FxmlFile.ADDVAULT_NEW_ADVANCED_SETTINGS) Lazy chooseAdvancedSettingsScene, // ObjectProperty vaultPath, // @Named("vaultName") StringProperty vaultName, // - ResourceBundle resourceBundle) { + ResourceBundle resourceBundle, // + BooleanProperty advancedSettingsEnabled) { this.window = window; this.chooseNameScene = chooseNameScene; this.choosePasswordScene = choosePasswordScene; @@ -88,6 +87,7 @@ public class CreateNewVaultLocationController implements FxController { this.vaultPath = vaultPath; this.vaultName = vaultName; this.resourceBundle = resourceBundle; + this.advancedSettingsEnabled = advancedSettingsEnabled; this.vaultPathStatus = ObservableUtil.mapWithDefault(vaultPath, this::validatePath, new VaultPathStatus(false, "error.message")); this.validVaultPath = ObservableUtil.mapWithDefault(vaultPathStatus, VaultPathStatus::valid, false); this.vaultPathStatus.addListener(this::updateStatusLabel); @@ -149,6 +149,7 @@ public class CreateNewVaultLocationController implements FxController { locationPresetsToggler.getToggles().addAll(locationPresetBtns); locationPresetsToggler.selectedToggleProperty().addListener(this::togglePredefinedLocation); usePresetPath.bind(locationPresetsToggler.selectedToggleProperty().isNotEqualTo(customRadioButton)); + advancedSettingsEnabled.bind(advancedSettingsCheckBox.selectedProperty()); } private void togglePredefinedLocation(@SuppressWarnings("unused") ObservableValue observable, @SuppressWarnings("unused") Toggle oldValue, Toggle newValue) { @@ -164,10 +165,9 @@ public class CreateNewVaultLocationController implements FxController { @FXML public void next() { if (validVaultPath.getValue()) { - if(advancedSettingsCheckBox.isSelected()){ + if (advancedSettingsEnabled.get()) { window.setScene(chooseAdvancedSettingsScene.get()); - } - else { + } else { window.setScene(choosePasswordScene.get()); } } diff --git a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java index 9adfc3569..0cda31f45 100644 --- a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java +++ b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java @@ -10,10 +10,10 @@ import org.cryptomator.cryptolib.api.CryptorProvider; import org.cryptomator.cryptolib.api.Masterkey; import org.cryptomator.cryptolib.api.MasterkeyLoader; import org.cryptomator.cryptolib.common.MasterkeyFileAccess; +import org.cryptomator.ui.changepassword.NewPasswordController; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; -import org.cryptomator.ui.changepassword.NewPasswordController; import org.cryptomator.ui.common.Tasks; import org.cryptomator.ui.fxapp.FxApplicationWindows; import org.cryptomator.ui.recoverykey.RecoveryKeyFactory; @@ -25,6 +25,7 @@ import javax.inject.Named; import javafx.beans.binding.Bindings; import javafx.beans.binding.ObjectBinding; import javafx.beans.property.BooleanProperty; +import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.StringProperty; @@ -56,6 +57,7 @@ public class CreateNewVaultPasswordController implements FxController { private final Stage window; private final Lazy chooseLocationScene; + private final Lazy chooseAdvancedSettingsScene; private final Lazy recoveryKeyScene; private final Lazy successScene; private final FxApplicationWindows appWindows; @@ -73,6 +75,8 @@ public class CreateNewVaultPasswordController implements FxController { private final BooleanProperty processing; private final BooleanProperty readyToCreateVault; private final ObjectBinding createVaultButtonState; + private final IntegerProperty shorteningThreshold; + private final BooleanProperty advancedSettingsEnabled; /* FXML */ public ToggleGroup recoveryKeyChoice; @@ -80,11 +84,10 @@ public class CreateNewVaultPasswordController implements FxController { public Toggle skipRecoveryKey; public NewPasswordController newPasswordSceneController; - private final StringProperty shorteningThreshold; - @Inject CreateNewVaultPasswordController(@AddVaultWizardWindow Stage window, // @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy chooseLocationScene, // + @FxmlScene(FxmlFile.ADDVAULT_NEW_ADVANCED_SETTINGS) Lazy chooseAdvancedSettingsScene, // @FxmlScene(FxmlFile.ADDVAULT_NEW_RECOVERYKEY) Lazy recoveryKeyScene, // @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, // FxApplicationWindows appWindows, // @@ -96,12 +99,14 @@ public class CreateNewVaultPasswordController implements FxController { @Named("recoveryKey") StringProperty recoveryKey, // VaultListManager vaultListManager, // ResourceBundle resourceBundle, // - @Named("shorteningThreshold") StringProperty shorteningThreshold, // + @Named("shorteningThreshold") IntegerProperty shorteningThreshold, // ReadmeGenerator readmeGenerator, // SecureRandom csprng, // - MasterkeyFileAccess masterkeyFileAccess) { + MasterkeyFileAccess masterkeyFileAccess, // + BooleanProperty advancedSettingsEnabled) { this.window = window; this.chooseLocationScene = chooseLocationScene; + this.chooseAdvancedSettingsScene = chooseAdvancedSettingsScene; this.recoveryKeyScene = recoveryKeyScene; this.successScene = successScene; this.appWindows = appWindows; @@ -120,10 +125,7 @@ public class CreateNewVaultPasswordController implements FxController { this.readyToCreateVault = new SimpleBooleanProperty(); this.createVaultButtonState = Bindings.when(processing).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY); this.shorteningThreshold = shorteningThreshold; - if(this.shorteningThreshold.isNull().get()) - { - this.shorteningThreshold.set("220"); - } + this.advancedSettingsEnabled = advancedSettingsEnabled; } @FXML @@ -137,7 +139,11 @@ public class CreateNewVaultPasswordController implements FxController { @FXML public void back() { - window.setScene(chooseLocationScene.get()); + if (advancedSettingsEnabled.getValue()) { + window.setScene(chooseAdvancedSettingsScene.get()); + } else { + window.setScene(chooseLocationScene.get()); + } } @FXML @@ -200,7 +206,7 @@ public class CreateNewVaultPasswordController implements FxController { CryptoFileSystemProperties fsProps = CryptoFileSystemProperties.cryptoFileSystemProperties() // .withCipherCombo(CryptorProvider.Scheme.SIV_GCM) // .withKeyLoader(loader) // - .withShorteningThreshold(Integer.parseInt(shorteningThreshold.getValue())) + .withShorteningThreshold(shorteningThreshold.get()) // .build(); CryptoFileSystemProvider.initialize(path, fsProps, DEFAULT_KEY_ID); diff --git a/src/main/resources/fxml/addvault_new_advanced_settings.fxml b/src/main/resources/fxml/addvault_new_advanced_settings.fxml index a30586ef8..afecde747 100644 --- a/src/main/resources/fxml/addvault_new_advanced_settings.fxml +++ b/src/main/resources/fxml/addvault_new_advanced_settings.fxml @@ -35,7 +35,7 @@ - + @@ -56,12 +56,12 @@ - +