mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-06-22 06:19:02 -04:00
More polishing
This commit is contained in:
@@ -14,7 +14,6 @@ public class OpenFileSystemCache {
|
||||
private final OpenFileSystemModel model;
|
||||
private final Map<String, Boolean> installedApplications = new HashMap<>();
|
||||
private String username;
|
||||
private boolean canElevate;
|
||||
|
||||
public OpenFileSystemCache(OpenFileSystemModel model) {
|
||||
this.model = model;
|
||||
@@ -24,7 +23,6 @@ public class OpenFileSystemCache {
|
||||
ShellControl sc = model.getFileSystem().getShell().get();
|
||||
ShellDialect d = sc.getShellDialect();
|
||||
username = sc.executeSimpleStringCommand(d.getPrintVariableCommand(d.getUsernameVariableName()));
|
||||
canElevate = sc.checkCanElevate();
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
|
||||
@@ -8,7 +8,6 @@ import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -16,22 +15,16 @@ import java.util.UUID;
|
||||
public class AskpassAlert {
|
||||
|
||||
private static final Map<UUID, UUID> requestToId = new HashMap<>();
|
||||
private static final Map<UUID, SecretValue> passwords = new HashMap<>();
|
||||
|
||||
public static SecretValue query(String prompt, Object key) {
|
||||
var rid = UUID.randomUUID();
|
||||
var secretId = UUID.nameUUIDFromBytes(ByteBuffer.allocate(4).putInt(key.hashCode()).array());
|
||||
return query(prompt, rid, secretId);
|
||||
}
|
||||
|
||||
public static SecretValue query(String prompt, UUID requestId, UUID secretId) {
|
||||
if (requestToId.containsKey(requestId)) {
|
||||
var id = requestToId.remove(requestId);
|
||||
passwords.remove(id);
|
||||
SecretCache.clear(id);
|
||||
}
|
||||
|
||||
if (passwords.containsKey(secretId)) {
|
||||
return passwords.get(secretId);
|
||||
var found = SecretCache.get(secretId);
|
||||
if (found.isPresent()) {
|
||||
return found.get();
|
||||
}
|
||||
|
||||
var prop = new SimpleObjectProperty<SecretValue>();
|
||||
@@ -54,8 +47,8 @@ public class AskpassAlert {
|
||||
|
||||
// If the result is null, assume that the operation was aborted by the user
|
||||
if (r != null) {
|
||||
passwords.put(secretId, r);
|
||||
requestToId.put(requestId, secretId);
|
||||
SecretCache.set(secretId, r);
|
||||
}
|
||||
|
||||
return r;
|
||||
|
||||
41
app/src/main/java/io/xpipe/app/util/SecretCache.java
Normal file
41
app/src/main/java/io/xpipe/app/util/SecretCache.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package io.xpipe.app.util;
|
||||
|
||||
import io.xpipe.core.util.SecretValue;
|
||||
import io.xpipe.core.util.UuidHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SecretCache {
|
||||
|
||||
private static final Map<UUID, SecretValue> passwords = new HashMap<>();
|
||||
|
||||
public static SecretValue retrieve(SecretRetrievalStrategy strategy, String prompt, Object key) throws Exception {
|
||||
var id = UuidHelper.generateFromObject(key);
|
||||
if (passwords.containsKey(id)) {
|
||||
return passwords.get(id);
|
||||
}
|
||||
|
||||
if (strategy == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var pass = strategy.retrieve(prompt, id);
|
||||
passwords.put(id, pass);
|
||||
return pass;
|
||||
}
|
||||
|
||||
public static void clear(UUID id) {
|
||||
passwords.remove(id);
|
||||
}
|
||||
|
||||
public static void set(UUID id, SecretValue value) {
|
||||
passwords.put(id, value);
|
||||
}
|
||||
|
||||
public static Optional<SecretValue> get(UUID id) {
|
||||
return Optional.ofNullable(passwords.get(id));
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,13 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.core.impl.LocalStore;
|
||||
import io.xpipe.core.store.DataStore;
|
||||
import io.xpipe.core.util.SecretValue;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
@@ -26,20 +26,20 @@ import java.util.function.Supplier;
|
||||
})
|
||||
public interface SecretRetrievalStrategy {
|
||||
|
||||
SecretValue retrieve(String displayName, DataStore store) throws Exception;
|
||||
SecretValue retrieve(String displayName, UUID id) throws Exception;
|
||||
|
||||
boolean supportsLocalAskpass();
|
||||
boolean isLocalAskpassCompatible();
|
||||
|
||||
@JsonTypeName("none")
|
||||
public static class None implements SecretRetrievalStrategy {
|
||||
|
||||
@Override
|
||||
public SecretValue retrieve(String displayName, DataStore store) {
|
||||
public SecretValue retrieve(String displayName, UUID id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsLocalAskpass() {
|
||||
public boolean isLocalAskpassCompatible() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -55,12 +55,12 @@ public interface SecretRetrievalStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecretValue retrieve(String displayName, DataStore store) {
|
||||
public SecretValue retrieve(String displayName, UUID id) {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsLocalAskpass() {
|
||||
public boolean isLocalAskpassCompatible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -79,12 +79,12 @@ public interface SecretRetrievalStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecretValue retrieve(String displayName, DataStore store) {
|
||||
public SecretValue retrieve(String displayName, UUID id) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsLocalAskpass() {
|
||||
public boolean isLocalAskpassCompatible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -93,12 +93,12 @@ public interface SecretRetrievalStrategy {
|
||||
public static class Prompt implements SecretRetrievalStrategy {
|
||||
|
||||
@Override
|
||||
public SecretValue retrieve(String displayName, DataStore store) {
|
||||
return AskpassAlert.query(displayName, store);
|
||||
public SecretValue retrieve(String displayName, UUID id) {
|
||||
return AskpassAlert.query(displayName, UUID.randomUUID(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsLocalAskpass() {
|
||||
public boolean isLocalAskpassCompatible() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public interface SecretRetrievalStrategy {
|
||||
String key;
|
||||
|
||||
@Override
|
||||
public SecretValue retrieve(String displayName, DataStore store) throws Exception {
|
||||
public SecretValue retrieve(String displayName, UUID id) throws Exception {
|
||||
var cmd = AppPrefs.get().passwordManagerString(key);
|
||||
if (cmd == null) {
|
||||
return null;
|
||||
@@ -124,7 +124,7 @@ public interface SecretRetrievalStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsLocalAskpass() {
|
||||
public boolean isLocalAskpassCompatible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -138,14 +138,14 @@ public interface SecretRetrievalStrategy {
|
||||
String command;
|
||||
|
||||
@Override
|
||||
public SecretValue retrieve(String displayName, DataStore store) throws Exception {
|
||||
public SecretValue retrieve(String displayName, UUID id) throws Exception {
|
||||
try (var cc = new LocalStore().createBasicControl().command(command).start()) {
|
||||
return SecretHelper.encrypt(cc.readStdoutOrThrow());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsLocalAskpass() {
|
||||
public boolean isLocalAskpassCompatible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SecretRetrievalStrategyHelper {
|
||||
.grow(false, true)))
|
||||
.apply(struc -> struc.get().setSpacing(10));
|
||||
return new OptionsBuilder()
|
||||
.name("command")
|
||||
.name("passwordKey")
|
||||
.addComp(content, keyProperty)
|
||||
.bind(
|
||||
() -> {
|
||||
|
||||
Reference in New Issue
Block a user