Bug 561862 - Update console.ssh should to use sshd.osgi 2.4.0
Change-Id: I443188250e377f3cf169a0974541d8106261c7bb
Signed-off-by: Mat Booth <mat.booth@redhat.com>
diff --git a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java
index 9534b03..8e3a84c 100755
--- a/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java
+++ b/bundles/org.eclipse.equinox.console.ssh.tests/src/org/eclipse/equinox/console/ssh/SshShellTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2018 SAP AG and others.
+ * Copyright (c) 2011, 2020 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -28,6 +28,7 @@
import org.apache.felix.service.command.CommandProcessor;
import org.apache.felix.service.command.CommandSession;
import org.apache.sshd.server.Environment;
+import org.apache.sshd.server.channel.ChannelSession;
import org.easymock.EasyMock;
import org.eclipse.equinox.console.common.ConsoleInputStream;
import org.eclipse.equinox.console.storage.DigestUtil;
@@ -94,7 +95,7 @@
shell = new SshShell(processors, context);
shell.setInputStream(socketServer.getInputStream());
shell.setOutputStream(socketServer.getOutputStream());
- shell.start(env);
+ shell.start(new ChannelSession(), env);
}
try (OutputStream outClient = socketClient.getOutputStream()) {
diff --git a/bundles/org.eclipse.equinox.console.ssh/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.console.ssh/META-INF/MANIFEST.MF
index 47d889a..e092a3d 100644
--- a/bundles/org.eclipse.equinox.console.ssh/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.console.ssh/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.equinox.console.ssh
-Bundle-Version: 1.2.500.qualifier
+Bundle-Version: 1.2.600.qualifier
Bundle-Activator: org.eclipse.equinox.console.ssh.Activator
Bundle-Vendor: %bundleVendor
Bundle-Localization: plugin
@@ -13,17 +13,19 @@
javax.security.auth.login;resolution:=optional,
javax.security.auth.spi;resolution:=optional,
org.apache.felix.service.command;status=provisional;version="0.8.0",
- org.apache.sshd.common;version="2.2.0";resolution:=optional,
- org.apache.sshd.common.kex;version="2.2.0";resolution:=optional,
- org.apache.sshd.common.keyprovider;version="2.2.0";resolution:=optional,
- org.apache.sshd.server;version="2.2.0";resolution:=optional,
- org.apache.sshd.server.auth;version="2.2.0";resolution:=optional,
- org.apache.sshd.server.auth.password;version="2.2.0";resolution:=optional,
- org.apache.sshd.server.auth.pubkey;version="2.2.0";resolution:=optional,
- org.apache.sshd.server.command;version="2.2.0";resolution:=optional,
- org.apache.sshd.server.jaas;version="2.2.0";resolution:=optional,
- org.apache.sshd.server.keyprovider;version="2.2.0";resolution:=optional,
- org.apache.sshd.server.session;version="2.2.0";resolution:=optional,
+ org.apache.sshd.common;version="2.4.0";resolution:=optional,
+ org.apache.sshd.common.kex;version="2.4.0";resolution:=optional,
+ org.apache.sshd.common.keyprovider;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server.auth;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server.auth.password;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server.auth.pubkey;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server.channel;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server.command;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server.jaas;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server.keyprovider;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server.session;version="2.4.0";resolution:=optional,
+ org.apache.sshd.server.shell;version="2.4.0";resolution:=optional,
org.eclipse.equinox.console.common,
org.eclipse.equinox.console.common.terminal,
org.osgi.framework,
diff --git a/bundles/org.eclipse.equinox.console.ssh/pom.xml b/bundles/org.eclipse.equinox.console.ssh/pom.xml
index 049d89b..511ad10 100644
--- a/bundles/org.eclipse.equinox.console.ssh/pom.xml
+++ b/bundles/org.eclipse.equinox.console.ssh/pom.xml
@@ -19,6 +19,6 @@
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.console.ssh</artifactId>
- <version>1.2.500-SNAPSHOT</version>
+ <version>1.2.600-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.equinox.console.ssh/src/org/eclipse/equinox/console/ssh/SshShell.java b/bundles/org.eclipse.equinox.console.ssh/src/org/eclipse/equinox/console/ssh/SshShell.java
index 4f0e9de..2d1a2c5 100755
--- a/bundles/org.eclipse.equinox.console.ssh/src/org/eclipse/equinox/console/ssh/SshShell.java
+++ b/bundles/org.eclipse.equinox.console.ssh/src/org/eclipse/equinox/console/ssh/SshShell.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG
+ * Copyright (c) 2011, 2020 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* Lazar Kirchev, SAP AG - initial API and implementation
*******************************************************************************/
@@ -23,9 +23,10 @@
import java.util.Map;
import org.apache.felix.service.command.CommandProcessor;
-import org.apache.sshd.server.command.Command;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
+import org.apache.sshd.server.channel.ChannelSession;
+import org.apache.sshd.server.command.Command;
import org.eclipse.equinox.console.common.KEYS;
import org.eclipse.equinox.console.common.terminal.ANSITerminalTypeMappings;
import org.eclipse.equinox.console.common.terminal.SCOTerminalTypeMappings;
@@ -36,25 +37,25 @@
import org.osgi.framework.BundleContext;
/**
- * This class manages a ssh connection. It is responsible for starting a sessions to execute commands
+ * This class manages a ssh connection. It is responsible for starting a sessions to execute commands
* from the ssh. If there are multiple CommandProcessors, a session is started for each of them.
*
*/
public class SshShell implements Command {
-
+
private List<CommandProcessor> processors;
private BundleContext context;
private InputStream in;
private OutputStream out;
private ExitCallback callback;
private Map<CommandProcessor, SshSession> commandProcessorToConsoleThreadMap = new HashMap<>();
-
+
private final Map<String, TerminalTypeMappings> supportedEscapeSequences;
private static final String DEFAULT_TTYPE = File.separatorChar == '/' ? "XTERM" : "ANSI";
private TerminalTypeMappings currentMappings;
private Map<String, KEYS> currentEscapesToKey;
private static final String TERMINAL_PROPERTY = "TERM";
-
+
public SshShell(List<CommandProcessor> processors, BundleContext context) {
this.processors = processors;
this.context = context;
@@ -67,7 +68,7 @@
supportedEscapeSequences.put("XTERM", vtMappings);
supportedEscapeSequences.put("VT320", new VT320TerminalTypeMappings());
supportedEscapeSequences.put("SCO", new SCOTerminalTypeMappings());
-
+
currentMappings = supportedEscapeSequences.get(DEFAULT_TTYPE);
currentEscapesToKey = currentMappings.getEscapesToKey();
}
@@ -93,40 +94,40 @@
}
@Override
- public synchronized void start(Environment env) throws IOException {
+ public synchronized void start(ChannelSession channel, Environment env) throws IOException {
String term = env.getEnv().get(TERMINAL_PROPERTY);
TerminalTypeMappings mapping = supportedEscapeSequences.get(term.toUpperCase());
if(mapping != null) {
currentMappings = mapping;
currentEscapesToKey = mapping.getEscapesToKey();
}
-
+
for (CommandProcessor processor : processors) {
createNewSession(processor);
}
}
-
+
public synchronized void addCommandProcessor(CommandProcessor processor) {
createNewSession(processor);
}
-
+
public synchronized void removeCommandProcessor(CommandProcessor processor) {
Thread consoleSession = commandProcessorToConsoleThreadMap.get(processor);
if (consoleSession != null) {
consoleSession.interrupt();
}
}
-
+
private void createNewSession(CommandProcessor processor) {
SshSession consoleSession = startNewConsoleSession(processor);
commandProcessorToConsoleThreadMap.put(processor, consoleSession);
}
@Override
- public void destroy() {
+ public void destroy(ChannelSession channel) {
return;
}
-
+
public void onExit() {
if (commandProcessorToConsoleThreadMap.values() != null) {
for (Thread consoleSession : commandProcessorToConsoleThreadMap.values()) {
@@ -135,26 +136,26 @@
}
callback.onExit(0);
}
-
+
public void removeSession(SshSession session) {
CommandProcessor processorToRemove = null;
for (java.util.Map.Entry<CommandProcessor, SshSession> entry : commandProcessorToConsoleThreadMap.entrySet()) {
- CommandProcessor processor = entry.getKey();
+ CommandProcessor processor = entry.getKey();
if (session.equals(entry.getValue())) {
processorToRemove = processor;
break;
}
}
-
+
if (processorToRemove != null) {
commandProcessorToConsoleThreadMap.remove(processorToRemove);
}
-
+
if (commandProcessorToConsoleThreadMap.size() == 0) {
onExit();
}
}
-
+
private SshSession startNewConsoleSession(CommandProcessor processor) {
SshSession consoleSession = new SshSession(processor, context, this, in, out, currentMappings, currentEscapesToKey);
consoleSession.start();
diff --git a/bundles/org.eclipse.equinox.console.ssh/src/org/eclipse/equinox/console/ssh/SshShellFactory.java b/bundles/org.eclipse.equinox.console.ssh/src/org/eclipse/equinox/console/ssh/SshShellFactory.java
index 5a9e31d..1fec800 100755
--- a/bundles/org.eclipse.equinox.console.ssh/src/org/eclipse/equinox/console/ssh/SshShellFactory.java
+++ b/bundles/org.eclipse.equinox.console.ssh/src/org/eclipse/equinox/console/ssh/SshShellFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG
+ * Copyright (c) 2011, 2020 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* Lazar Kirchev, SAP AG - initial API and implementation
*******************************************************************************/
@@ -19,46 +19,47 @@
import java.util.Set;
import org.apache.felix.service.command.CommandProcessor;
-import org.apache.sshd.common.Factory;
+import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.command.Command;
+import org.apache.sshd.server.shell.ShellFactory;
import org.osgi.framework.BundleContext;
/**
* Shell factory used by the SSH server to create a SSH shell
*
*/
-public class SshShellFactory implements Factory<Command> {
-
+public class SshShellFactory implements ShellFactory {
+
private List<CommandProcessor> processors;
private BundleContext context;
private Set<SshShell> shells = new HashSet<>();
-
+
public SshShellFactory(List<CommandProcessor> processors, BundleContext context) {
this.processors = processors;
this.context = context;
}
-
+
@Override
- public synchronized Command create() {
+ public synchronized Command createShell(ChannelSession channel) {
SshShell shell = new SshShell(processors, context);
shells.add(shell);
return shell;
}
-
+
public synchronized void addCommandProcessor (CommandProcessor processor) {
processors.add(processor);
for (SshShell shell : shells) {
shell.addCommandProcessor(processor);
}
}
-
+
public synchronized void removeCommandProcessor (CommandProcessor processor) {
processors.remove(processor);
for (SshShell shell : shells) {
shell.removeCommandProcessor(processor);
}
}
-
+
public void exit() {
for(SshShell shell : shells) {
shell.onExit();
diff --git a/pom.xml b/pom.xml
index c1338fa..0e64a42 100644
--- a/pom.xml
+++ b/pom.xml
@@ -70,11 +70,6 @@
<module>bundles/org.eclipse.equinox.cm.test</module>
<module>bundles/org.eclipse.equinox.common.tests</module>
-<!-- no longer built in M6
- <module>bundles/org.eclipse.equinox.console.ssh.tests</module>
- <module>bundles/org.eclipse.equinox.console.tests</module>
--->
-
<module>bundles/org.eclipse.equinox.ds.tests</module>
<module>bundles/org.eclipse.equinox.preferences.tests</module>
<!-- removed until the dependency on aspectj is removed. see bug 470000