@@ -28,9 +28,13 @@ public KeePassXCAccess() {
2828 @ Override
2929 public boolean isLocked () { return proxy .getDatabasehash ().isEmpty (); }
3030
31- private boolean needsAssociation () { return !proxy .connectionAvailable (); }
32-
33- private boolean associate () { return proxy .associate (); }
31+ private void ensureAssociation () throws KeychainAccessException {
32+ if (!proxy .connectionAvailable ()) { // Proxy needs association
33+ if (!proxy .associate ()) {
34+ throw new KeychainAccessException ("Association with KeePassXC database failed" );
35+ }
36+ }
37+ }
3438
3539 public String unlock () { return proxy .getDatabasehash (true ); }
3640
@@ -40,6 +44,7 @@ public void storePassphrase(String vault, CharSequence password) throws Keychain
4044 if (isLocked ()) {
4145 throw new KeychainAccessException ("Failed to store password. KeePassXC database is locked. Needs to be unlocked first" );
4246 }
47+ ensureAssociation ();
4348 if (!proxy .loginExists (vault , null , false , List .of (proxy .exportConnection ()), password .toString ())
4449 && !proxy .setLogin (vault , null , null , "Vault" , password .toString (), "default" , "default" , "default" )) {
4550 throw new KeychainAccessException ("Storing of the password failed" );
@@ -51,6 +56,7 @@ public char[] loadPassphrase(String vault) throws KeychainAccessException {
5156 if (isLocked ()) {
5257 throw new KeychainAccessException ("Failed to load password. KeePassXC database is locked. Needs to be unlocked first" );
5358 }
59+ ensureAssociation ();
5460 vault = URL_SCHEME + vault ;
5561 var answer = proxy .getLogins (vault , null , false , List .of (proxy .exportConnection ()));
5662 if (answer .isEmpty () || null == answer .get ("entries" )) {
0 commit comments