From f1d125bf8d076de13fbc0d52ff1f8cb4b3ea9286 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Sun, 22 Feb 2015 14:06:52 +0100 Subject: [PATCH] reduced public interface complexity of Vault --- .../main/java/org/cryptomator/ui/MainModule.java | 4 ++-- .../java/org/cryptomator/ui/UnlockController.java | 14 +++----------- .../main/java/org/cryptomator/ui/model/Vault.java | 11 ++++++++--- .../org/cryptomator/ui/model/VaultFactory.java | 10 ++++++++-- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/MainModule.java b/main/ui/src/main/java/org/cryptomator/ui/MainModule.java index 3db7e07f4..5614f8a5f 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/MainModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/MainModule.java @@ -68,8 +68,8 @@ public class MainModule extends AbstractModule { } @Provides - VaultFactory getVaultFactory(Cryptor cryptor, WebDavMounter mounter) { - return new VaultFactory(cryptor, mounter); + VaultFactory getVaultFactory(WebDavServer server, Cryptor cryptor, WebDavMounter mounter, DeferredCloser closer) { + return new VaultFactory(server, cryptor, mounter, closer); } @Provides diff --git a/main/ui/src/main/java/org/cryptomator/ui/UnlockController.java b/main/ui/src/main/java/org/cryptomator/ui/UnlockController.java index 0c44636e1..cdc935e5f 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/UnlockController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/UnlockController.java @@ -39,10 +39,8 @@ import org.cryptomator.crypto.exceptions.UnsupportedKeyLengthException; import org.cryptomator.crypto.exceptions.WrongPasswordException; import org.cryptomator.ui.controls.SecPasswordField; import org.cryptomator.ui.model.Vault; -import org.cryptomator.ui.util.DeferredCloser; import org.cryptomator.ui.util.FXThreads; import org.cryptomator.ui.util.MasterKeyFilter; -import org.cryptomator.webdav.WebDavServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,18 +72,12 @@ public class UnlockController implements Initializable { @FXML private Label messageLabel; - private final WebDavServer server; - private final ExecutorService exec; - private final DeferredCloser closer; - @Inject - public UnlockController(WebDavServer server, ExecutorService exec, DeferredCloser closer) { + public UnlockController(ExecutorService exec) { super(); - this.server = server; this.exec = exec; - this.closer = closer; } @Override @@ -124,7 +116,7 @@ public class UnlockController implements Initializable { progressIndicator.setVisible(true); masterKeyInputStream = Files.newInputStream(masterKeyPath, StandardOpenOption.READ); directory.getCryptor().decryptMasterKey(masterKeyInputStream, password); - if (!directory.startServer(server, closer)) { + if (!directory.startServer()) { messageLabel.setText(rb.getString("unlock.messageLabel.startServerFailed")); directory.getCryptor().swipeSensitiveData(); return; @@ -132,7 +124,7 @@ public class UnlockController implements Initializable { // at this point we know for sure, that the masterkey can be decrypted, so lets make a backup: Files.copy(masterKeyPath, masterKeyBackupPath, StandardCopyOption.REPLACE_EXISTING); directory.setUnlocked(true); - final Future futureMount = exec.submit(() -> directory.mount(closer)); + final Future futureMount = exec.submit(() -> directory.mount()); FXThreads.runOnMainThreadWhenFinished(exec, futureMount, this::didUnlockAndMount); FXThreads.runOnMainThreadWhenFinished(exec, futureMount, (result) -> { setControlsDisabled(false); diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java index bc4caefdc..286376b2f 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java @@ -32,9 +32,12 @@ public class Vault implements Serializable { public static final String VAULT_FILE_EXTENSION = ".cryptomator"; private final Path path; + private final WebDavServer server; private final Cryptor cryptor; private final WebDavMounter mounter; + private final DeferredCloser closer; private final ObjectProperty unlocked = new SimpleObjectProperty(this, "unlocked", Boolean.FALSE); + private String mountName; private DeferredClosable webDavServlet = DeferredClosable.empty(); private DeferredClosable webDavMount = DeferredClosable.empty(); @@ -42,13 +45,15 @@ public class Vault implements Serializable { /** * Package private constructor, use {@link VaultFactory}. */ - Vault(final Path vaultDirectoryPath, final Cryptor cryptor, final WebDavMounter mounter) { + Vault(final Path vaultDirectoryPath, final WebDavServer server, final Cryptor cryptor, final WebDavMounter mounter, final DeferredCloser closer) { if (!Files.isDirectory(vaultDirectoryPath) || !vaultDirectoryPath.getFileName().toString().endsWith(VAULT_FILE_EXTENSION)) { throw new IllegalArgumentException("Not a valid vault directory: " + vaultDirectoryPath); } this.path = vaultDirectoryPath; + this.server = server; this.cryptor = cryptor; this.mounter = mounter; + this.closer = closer; try { setMountName(getName()); @@ -61,7 +66,7 @@ public class Vault implements Serializable { return MasterKeyFilter.filteredDirectory(path).iterator().hasNext(); } - public synchronized boolean startServer(WebDavServer server, DeferredCloser closer) { + public synchronized boolean startServer() { Optional o = webDavServlet.get(); if (o.isPresent() && o.get().isRunning()) { return false; @@ -80,7 +85,7 @@ public class Vault implements Serializable { cryptor.swipeSensitiveData(); } - public boolean mount(DeferredCloser closer) { + public boolean mount() { Optional o = webDavServlet.get(); if (!o.isPresent() || !o.get().isRunning()) { return false; diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/VaultFactory.java b/main/ui/src/main/java/org/cryptomator/ui/model/VaultFactory.java index 7deb37a94..fb83d7cff 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/VaultFactory.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/VaultFactory.java @@ -3,23 +3,29 @@ package org.cryptomator.ui.model; import java.nio.file.Path; import org.cryptomator.crypto.Cryptor; +import org.cryptomator.ui.util.DeferredCloser; import org.cryptomator.ui.util.mount.WebDavMounter; +import org.cryptomator.webdav.WebDavServer; import com.google.inject.Inject; public class VaultFactory { + private final WebDavServer server; private final Cryptor cryptor; private final WebDavMounter mounter; + private final DeferredCloser closer; @Inject - public VaultFactory(Cryptor cryptor, WebDavMounter mounter) { + public VaultFactory(WebDavServer server, Cryptor cryptor, WebDavMounter mounter, DeferredCloser closer) { + this.server = server; this.cryptor = cryptor; this.mounter = mounter; + this.closer = closer; } public Vault createVault(Path path) { - return new Vault(path, cryptor, mounter); + return new Vault(path, server, cryptor, mounter, closer); } }