diff --git a/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/FreedesktopKeyringBackend.java b/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/FreedesktopKeyringBackend.java index d205391..4b5b0d8 100755 --- a/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/FreedesktopKeyringBackend.java +++ b/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/FreedesktopKeyringBackend.java @@ -52,6 +52,9 @@ public class FreedesktopKeyringBackend implements KeyringBackend { public FreedesktopKeyringBackend() throws BackendNotSupportedException { try { collection = new SimpleCollection(); + if (!collection.isConnected()) { + throw new BackendNotSupportedException("Error connecting to dbus"); + } } catch (IOException ex) { throw new BackendNotSupportedException("Error connecting to dbus", ex); } diff --git a/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/SimpleCollection.java b/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/SimpleCollection.java index 8efebb8..57f0c2b 100755 --- a/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/SimpleCollection.java +++ b/java-keyring/src/main/java/com/github/javakeyring/internal/freedesktop/SimpleCollection.java @@ -82,6 +82,10 @@ public SimpleCollection() throws IOException { unlock(); } + public boolean isConnected() { + return this.session.getConnection().isConnected(); + } + /* * A user specified collection. * diff --git a/java-keyring/src/test/java/com/github/javakeyring/kde/KWalletBackendTest.java b/java-keyring/src/test/java/com/github/javakeyring/kde/KWalletBackendTest.java index 2411320..a68b460 100644 --- a/java-keyring/src/test/java/com/github/javakeyring/kde/KWalletBackendTest.java +++ b/java-keyring/src/test/java/com/github/javakeyring/kde/KWalletBackendTest.java @@ -27,8 +27,6 @@ package com.github.javakeyring.kde; import com.github.javakeyring.BackendNotSupportedException; -import com.github.javakeyring.Keyring; -import com.github.javakeyring.KeyringStorageType; import com.github.javakeyring.PasswordAccessException; import com.github.javakeyring.internal.KeyringBackend; import com.github.javakeyring.internal.freedesktop.FreedesktopKeyringBackend; @@ -64,7 +62,12 @@ public void testSetup() throws Exception { */ @Test public void testPasswordFlow() throws Exception { - assumeTrue(Platform.isLinux() && Keyring.create().getKeyringStorageType() == KeyringStorageType.KWALLET); + assumeTrue(Platform.isLinux()); + //try (KeyringBackend be = new FreedesktopKeyringBackend()) { + // fail("Should throw a BackendNotSupportedException"); + //} catch (BackendNotSupportedException ex) { + // assumeTrue(ex != null); + //} KeyringBackend backend = new KWalletBackend(); catchThrowable(() -> backend.deletePassword(SERVICE, ACCOUNT)); checkExistenceOfPasswordEntry(backend);