More elevation fixes

This commit is contained in:
crschnick 2024-03-13 06:21:08 +00:00
parent 6f4712934e
commit 4320040c9a
9 changed files with 67 additions and 34 deletions

View file

@ -33,6 +33,7 @@ public class StandardStoreEntryComp extends StoreEntryComp {
var nameCC = new ColumnConstraints();
nameCC.setMinWidth(100);
nameCC.setHgrow(Priority.ALWAYS);
nameCC.setPrefWidth(100);
grid.getColumnConstraints().addAll(nameCC);
grid.add(createInformation(), 2, 0, 1, 2);

View file

@ -28,18 +28,6 @@ public class SecretManager {
.findFirst();
}
public static synchronized SecretQueryProgress expectElevationPrompt(
UUID request, UUID secretId, CountDown countDown, boolean askIfNeeded) {
var p = new SecretQueryProgress(
request,
secretId,
List.of(askIfNeeded ? SecretQuery.elevation(secretId) : SecretQuery.prompt(true)),
SecretQuery.prompt(false),
countDown);
progress.add(p);
return p;
}
public static synchronized SecretQueryProgress expectAskpass(
UUID request, UUID storeId, List<SecretQuery> suppliers, SecretQuery fallback, CountDown countDown) {
var p = new SecretQueryProgress(request, storeId, suppliers, fallback, countDown);

View file

@ -4,11 +4,18 @@ import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.core.util.SecretReference;
import java.util.Optional;
import java.util.UUID;
public interface SecretQuery {
static SecretQuery elevation(UUID secretId) {
static SecretQuery confirmElevationIfNeeded(SecretQuery original, boolean needed) {
if (!needed) {
return original;
}
return confirmElevation(original);
}
static SecretQuery confirmElevation(SecretQuery original) {
return new SecretQuery() {
@Override
@ -30,7 +37,13 @@ public interface SecretQuery {
@Override
public SecretQueryResult query(String prompt) {
return AskpassAlert.queryRaw(prompt, null);
var r = original.query(prompt);
if (r.isCancelled()) {
return r;
}
var inPlace = r.getSecret().inPlace();
return AskpassAlert.queryRaw(prompt, inPlace);
}
@Override

View file

@ -1,3 +0,0 @@
package io.xpipe.core.process;
public class AskpassSetup {}

View file

@ -0,0 +1,29 @@
package io.xpipe.core.process;
import io.xpipe.core.util.SecretReference;
import java.util.UUID;
public interface ElevationHandler {
default ElevationHandler orElse(ElevationHandler other) {
return new ElevationHandler() {
@Override
public boolean handleRequest(UUID requestId, CountDown countDown, boolean confirmIfNeeded) {
var r = ElevationHandler.this.handleRequest(requestId, countDown, confirmIfNeeded);
return r || other.handleRequest(requestId, countDown, confirmIfNeeded);
}
@Override
public SecretReference getSecretRef() {
var r = ElevationHandler.this.getSecretRef();
return r != null ? r : other.getSecretRef();
}
};
}
boolean handleRequest(UUID requestId, CountDown countDown, boolean confirmIfNeeded);
SecretReference getSecretRef();
}

View file

@ -1,9 +0,0 @@
package io.xpipe.core.process;
import lombok.Value;
@Value
public class ElevationResult {
String value;
boolean promptsUserInput;
}

View file

@ -4,6 +4,11 @@ public interface ParentSystemAccess {
static ParentSystemAccess none() {
return new ParentSystemAccess() {
@Override
public boolean supportsSameUsers() {
return false;
}
@Override
public boolean supportsFileSystemAccess() {
return false;
@ -33,6 +38,10 @@ public interface ParentSystemAccess {
static ParentSystemAccess identity() {
return new ParentSystemAccess() {
@Override
public boolean supportsSameUsers() {
return true;
}
@Override
public boolean supportsFileSystemAccess() {
@ -63,6 +72,10 @@ public interface ParentSystemAccess {
static ParentSystemAccess combine(ParentSystemAccess a1, ParentSystemAccess a2) {
return new ParentSystemAccess() {
@Override
public boolean supportsSameUsers() {
return a1.supportsSameUsers() && a2.supportsSameUsers();
}
@Override
public boolean supportsFileSystemAccess() {
@ -95,6 +108,8 @@ public interface ParentSystemAccess {
return supportsFileSystemAccess();
}
boolean supportsSameUsers();
boolean supportsFileSystemAccess();
boolean supportsExecutables();

View file

@ -16,7 +16,9 @@ import java.util.function.Function;
public interface ShellControl extends ProcessControl {
UUID getElevationSecretId();
ElevationHandler getElevationHandler();
void setElevationHandler(ElevationHandler ref);
List<UUID> getExitUuids();

View file

@ -10,13 +10,10 @@ public interface ShellDialectAskpass {
String prepareFixedContent(ShellControl sc, String fileName, List<String> s) throws Exception;
String elevateDumbCommand(
ShellControl shellControl,
CommandConfiguration command,
UUID requestId,
CountDown countDown,
String message)
ShellControl shellControl, UUID requestId, ElevationHandler handler, CountDown countDown, String message, CommandConfiguration command
)
throws Exception;
String elevateTerminalCommandWithPreparedAskpass(ShellControl shellControl, String command, String prefix)
String elevateTerminalCommandWithPreparedAskpass(ShellControl shellControl, ElevationHandler handler, String command, String prefix)
throws Exception;
}