Use shell command access control lists during command completion
@@ -35,6 +35,7 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.apache.felix.gogo.jline.ParsedLineImpl;
import org.apache.felix.gogo.jline.Shell;
@@ -71,6 +72,8 @@ import org.jline.terminal.impl.DumbTerminal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.felix.gogo.jline.Shell.VAR_SCOPE;
+
public class ConsoleSessionImpl implements Session {
private static final String SUPPRESS_WELCOME = "karaf.shell.suppress.welcome";
@@ -221,11 +224,28 @@ public class ConsoleSessionImpl implements Session {
}
@Override
public Set<String> getCommands() {
- return Shell.getCommands(session);
+ return factory.getRegistry().getCommands().stream()
+ .map(c -> c.getScope() + ":" + c.getName())
+ .collect(Collectors.toSet());
}
@Override
public String resolveCommand(String command) {
- return Shell.resolve(session, command);
+ String resolved = command;
+ if (command.indexOf(':') < 0) {
+ Set<String> commands = getCommands();
+ Object path = session.get(VAR_SCOPE);
+ String scopePath = (null == path ? "*" : path.toString());
+ for (String scope : scopePath.split(":")) {
+ for (String entry : commands) {
+ if ("*".equals(scope) && entry.endsWith(":" + command)
+ || entry.equals(scope + ":" + command)) {
+ resolved = entry;
+ break;
+ }
+ }
+ }
+ }
+ return resolved;
}
@Override
public String commandName(String command) {
