mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-29 22:02:40 -04:00
reduced public interface complexity of Vault
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<Boolean> futureMount = exec.submit(() -> directory.mount(closer));
|
||||
final Future<Boolean> futureMount = exec.submit(() -> directory.mount());
|
||||
FXThreads.runOnMainThreadWhenFinished(exec, futureMount, this::didUnlockAndMount);
|
||||
FXThreads.runOnMainThreadWhenFinished(exec, futureMount, (result) -> {
|
||||
setControlsDisabled(false);
|
||||
|
||||
@@ -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<Boolean> unlocked = new SimpleObjectProperty<Boolean>(this, "unlocked", Boolean.FALSE);
|
||||
|
||||
private String mountName;
|
||||
private DeferredClosable<ServletLifeCycleAdapter> webDavServlet = DeferredClosable.empty();
|
||||
private DeferredClosable<WebDavMount> 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<ServletLifeCycleAdapter> 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<ServletLifeCycleAdapter> o = webDavServlet.get();
|
||||
if (!o.isPresent() || !o.get().isRunning()) {
|
||||
return false;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user