浏览代码

Wire disable all keyrings setting checkbox to the KeychainManager

Ralph Plawetzki 2 年之前
父节点
当前提交
17d3d7307d

+ 5 - 2
src/main/java/org/cryptomator/common/keychain/KeychainManager.java

@@ -3,6 +3,7 @@ package org.cryptomator.common.keychain;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
+import org.cryptomator.common.settings.Settings;
 import org.cryptomator.integrations.keychain.KeychainAccessException;
 import org.cryptomator.integrations.keychain.KeychainAccessProvider;
 
@@ -20,10 +21,12 @@ public class KeychainManager implements KeychainAccessProvider {
 
 	private final ObjectExpression<KeychainAccessProvider> keychain;
 	private final LoadingCache<String, BooleanProperty> passphraseStoredProperties;
+	private final Settings settings;
 
 	@Inject
-	KeychainManager(ObjectExpression<KeychainAccessProvider> selectedKeychain) {
+	KeychainManager(ObjectExpression<KeychainAccessProvider> selectedKeychain, Settings settings) {
 		this.keychain = selectedKeychain;
+		this.settings = settings;
 		this.passphraseStoredProperties = CacheBuilder.newBuilder() //
 				.weakValues() //
 				.build(CacheLoader.from(this::createStoredPassphraseProperty));
@@ -72,7 +75,7 @@ public class KeychainManager implements KeychainAccessProvider {
 
 	@Override
 	public boolean isSupported() {
-		return keychain.getValue() != null;
+		return keychain.getValue() != null && !settings.disableAllKeyrings().get();
 	}
 
 	@Override

+ 1 - 0
src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java

@@ -66,6 +66,7 @@ public class GeneralPreferencesController implements FxController {
 		keychainBackendChoiceBox.setConverter(new KeychainProviderDisplayNameConverter());
 		Bindings.bindBidirectional(settings.keychainProvider(), keychainBackendChoiceBox.valueProperty(), keychainSettingsConverter);
 		disableAllKeyringsCheckbox.selectedProperty().bindBidirectional(settings.disableAllKeyrings());
+		keychainBackendChoiceBox.disableProperty().bindBidirectional(settings.disableAllKeyrings());
 	}
 
 	public boolean isAutoStartSupported() {

+ 5 - 2
src/test/java/org/cryptomator/common/keychain/KeychainManagerTest.java

@@ -1,12 +1,14 @@
 package org.cryptomator.common.keychain;
 
 
+import org.cryptomator.common.settings.Settings;
 import org.cryptomator.integrations.keychain.KeychainAccessException;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Assumptions;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
 
 import javafx.application.Platform;
 import javafx.beans.property.ReadOnlyBooleanProperty;
@@ -19,9 +21,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 public class KeychainManagerTest {
 
+	private static final Settings settings = Mockito.mock(Settings.class);
 	@Test
 	public void testStoreAndLoad() throws KeychainAccessException {
-		KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess()));
+		KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess()), settings);
 		keychainManager.storePassphrase("test", "Test", "asd");
 		Assertions.assertArrayEquals("asd".toCharArray(), keychainManager.loadPassphrase("test"));
 	}
@@ -39,7 +42,7 @@ public class KeychainManagerTest {
 
 		@Test
 		public void testPropertyChangesWhenStoringPassword() throws KeychainAccessException, InterruptedException {
-			KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess()));
+			KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess()), settings);
 			ReadOnlyBooleanProperty property = keychainManager.getPassphraseStoredProperty("test");
 			Assertions.assertFalse(property.get());