Skip to content

Commit

Permalink
Merge pull request #10 from purejava/keychain-isLocked
Browse files Browse the repository at this point in the history
Widen integrations-api to check whether keychain is locked
  • Loading branch information
Armin Schrenk committed Feb 23, 2021
2 parents dfd81a0 + 62a94fe commit 6d9f914
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- runtime dependencies -->
<api.version>0.1.3</api.version>
<api.version>1.0.0-beta2</api.version>
<secret-service.version>1.5.0</secret-service.version>
<kdewallet.version>1.1.1</kdewallet.version>
<guava.version>30.0-jre</guava.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public boolean isSupported() {
return wallet.map(ConnectedWallet::isSupported).orElse(false);
}

@Override
public boolean isLocked() {
return wallet.map(ConnectedWallet::isLocked).orElse(false);
}

@Override
public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
Expand Down Expand Up @@ -84,6 +89,8 @@ public boolean isSupported() {
return wallet.isEnabled();
}

public boolean isLocked() { return !wallet.isOpen(Static.DEFAULT_WALLET); }

public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
try {
if (walletIsOpen() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public boolean isSupported() {
return SimpleCollection.isAvailable();
}

@Override
public boolean isLocked() {
try (@SuppressWarnings("unused") SimpleCollection keyring = new SimpleCollection()) {
// seems like we're able to access the keyring.
return keyring.isLocked();
} catch (IOException | ExceptionInInitializerError | RuntimeException e) {
return true;
}
}

@Override
public void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
try (SimpleCollection keyring = new SimpleCollection()) {
Expand Down

0 comments on commit 6d9f914

Please sign in to comment.