use of org.apache.sshd.server.command.CommandFactory in project testcases by coheigea.
the class SSHTest method setup.
@Before
public void setup() throws Exception {
int port = AvailablePortFinder.getNextAvailable(10000);
// Write port number to configuration file in target
String basedir = System.getProperty("basedir");
if (basedir == null) {
basedir = new File(".").getCanonicalPath();
}
// Read in camel configuration file and substitute in the correct port
File f = new File(basedir + "/src/test/resources/camel-ssh.xml");
FileInputStream inputStream = new FileInputStream(f);
String content = IOUtils.toString(inputStream, "UTF-8");
inputStream.close();
content = content.replaceAll("portno", "" + port);
File f2 = new File(basedir + "/target/test-classes/camel-ssh.xml");
FileOutputStream outputStream = new FileOutputStream(f2);
IOUtils.write(content, outputStream, "UTF-8");
outputStream.close();
sshServer = SshServer.setUpDefaultServer();
sshServer.setPort(port);
// Generate a key
sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get("target/generatedkey.pem")));
// Simple CommandFactory to run commands in a process
sshServer.setCommandFactory(new CommandFactory() {
public Command createCommand(String command) {
return new ProcessShellFactory(command.split(";")).create();
}
});
// sshServer.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" }));
sshServer.setPasswordAuthenticator(new CamelPasswordAuthenticator());
sshServer.setPublickeyAuthenticator(new CamelPublicKeyAuthenticator());
sshServer.start();
}
Aggregations