use of org.apache.sshd.server.Command in project hadoop by apache.
the class TestSFTPFileSystem method startSshdServer.
private static void startSshdServer() throws IOException {
sshd = SshServer.setUpDefaultServer();
// ask OS to assign a port
sshd.setPort(0);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
if (username.equals("user") && password.equals("password")) {
return true;
}
return false;
}
});
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.start();
port = sshd.getPort();
}
use of org.apache.sshd.server.Command in project gerrit by GerritCodeReview.
the class DispatchCommand method start.
@Override
public void start(final Environment env) throws IOException {
try {
parseCommandLine();
if (Strings.isNullOrEmpty(commandName)) {
StringWriter msg = new StringWriter();
msg.write(usage());
throw die(msg.toString());
}
final CommandProvider p = commands.get(commandName);
if (p == null) {
String msg = (getName().isEmpty() ? "Gerrit Code Review" : getName()) + ": " + commandName + ": not found";
throw die(msg);
}
final Command cmd = p.getProvider().get();
checkRequiresCapability(cmd);
if (cmd instanceof BaseCommand) {
final BaseCommand bc = (BaseCommand) cmd;
if (getName().isEmpty()) {
bc.setName(commandName);
} else {
bc.setName(getName() + " " + commandName);
}
bc.setArguments(args.toArray(new String[args.size()]));
} else if (!args.isEmpty()) {
throw die(commandName + " does not take arguments");
}
provideStateTo(cmd);
atomicCmd.set(cmd);
cmd.start(env);
} catch (UnloggedFailure e) {
String msg = e.getMessage();
if (!msg.endsWith("\n")) {
msg += "\n";
}
err.write(msg.getBytes(ENC));
err.flush();
onExit(e.exitCode);
}
}
use of org.apache.sshd.server.Command in project gerrit by GerritCodeReview.
the class AliasCommand method begin.
private void begin(Environment env) throws IOException, Failure {
Map<String, CommandProvider> map = root.getMap();
for (String name : chain(command)) {
CommandProvider p = map.get(name);
if (p == null) {
throw die(getName() + ": not found");
}
Command cmd = p.getProvider().get();
if (!(cmd instanceof DispatchCommand)) {
throw die(getName() + ": not found");
}
map = ((DispatchCommand) cmd).getMap();
}
CommandProvider p = map.get(command.value());
if (p == null) {
throw die(getName() + ": not found");
}
Command cmd = p.getProvider().get();
checkRequiresCapability(cmd);
if (cmd instanceof BaseCommand) {
BaseCommand bc = (BaseCommand) cmd;
bc.setName(getName());
bc.setArguments(getArguments());
}
provideStateTo(cmd);
atomicCmd.set(cmd);
cmd.start(env);
}
use of org.apache.sshd.server.Command in project camel by apache.
the class SftpServerTestSupport method setUpServer.
protected void setUpServer() throws Exception {
canTest = true;
try {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(getPort());
sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem" }));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
PublickeyAuthenticator publickeyAuthenticator = new PublickeyAuthenticator() {
// consider all keys as authorized for all users
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return true;
}
};
sshd.setPublickeyAuthenticator(publickeyAuthenticator);
sshd.start();
} catch (Exception e) {
// ignore if algorithm is not on the OS
NoSuchAlgorithmException nsae = ObjectHelper.getException(NoSuchAlgorithmException.class, e);
if (nsae != null) {
canTest = false;
String name = System.getProperty("os.name");
String message = nsae.getMessage();
log.warn("SunX509 is not avail on this platform [{}] Testing is skipped! Real cause: {}", name, message);
} else {
// some other error then throw it so the test can fail
throw e;
}
}
}
use of org.apache.sshd.server.Command in project felix by apache.
the class Ssh method start.
private void start() throws IOException {
server = ServerBuilder.builder().build();
server.setPort(port);
server.setHost(ip);
server.setShellFactory(new ShellFactoryImpl(processor));
server.setCommandFactory(new ScpCommandFactory.Builder().withDelegate(new ShellCommandFactory(processor)).build());
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory.Builder().build()));
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
server.start();
}
Aggregations