Search in sources :

Example 11 with Command

use of org.apache.sshd.server.Command in project pentaho-kettle by pentaho.

the class SftpServer method createSshServer.

private SshServer createSshServer(int port, String homeDir, String hostKeyPath) {
    SshServer server = SshServer.setUpDefaultServer();
    server.setHost("localhost");
    server.setPort(port);
    server.setFileSystemFactory(new VirtualFileSystemFactory(homeDir));
    server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystem.Factory()));
    server.setCommandFactory(new ScpCommandFactory());
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKeyPath));
    server.setPasswordAuthenticator(this);
    return server;
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) Command(org.apache.sshd.server.Command) VirtualFileSystemFactory(org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory) VirtualFileSystemFactory(org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) NamedFactory(org.apache.sshd.common.NamedFactory) SshServer(org.apache.sshd.SshServer)

Example 12 with Command

use of org.apache.sshd.server.Command in project camel by apache.

the class ScpServerTestSupport method startSshd.

protected boolean startSshd() {
    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 PasswordAuthenticator() {

        @Override
        public boolean authenticate(String username, String password, ServerSession session) {
            // dummy authentication: allow any user whose password is the same as the username
            return username != null && username.equals(password);
        }
    });
    sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {

        @Override
        public boolean authenticate(String username, PublicKey key, ServerSession session) {
            return true;
        }
    });
    try {
        sshd.start();
        return true;
    } catch (IOException e) {
        LOG.info("Failed to start ssh server.", e);
    }
    return false;
}
Also used : ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) FileKeyPairProvider(org.apache.sshd.common.keyprovider.FileKeyPairProvider) ServerSession(org.apache.sshd.server.session.ServerSession) PasswordAuthenticator(org.apache.sshd.server.PasswordAuthenticator) PublickeyAuthenticator(org.apache.sshd.server.PublickeyAuthenticator) Command(org.apache.sshd.server.Command) PublicKey(java.security.PublicKey) LoggerFactory(org.slf4j.LoggerFactory) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) NamedFactory(org.apache.sshd.common.NamedFactory) IOException(java.io.IOException)

Example 13 with Command

use of org.apache.sshd.server.Command in project spring-integration by spring-projects.

the class SftpSessionFactoryTests method createServerAndClient.

private DefaultSftpSessionFactory createServerAndClient(SshServer server) throws IOException {
    server.setPublickeyAuthenticator((username, key, session) -> true);
    server.setPort(0);
    server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory()));
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser")));
    server.start();
    DefaultSftpSessionFactory f = new DefaultSftpSessionFactory();
    f.setHost("localhost");
    f.setPort(server.getPort());
    f.setUser("user");
    Resource privateKey = new ClassPathResource("id_rsa");
    f.setPrivateKey(privateKey);
    return f;
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) SftpSubsystemFactory(org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory) Command(org.apache.sshd.server.Command) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 14 with Command

use of org.apache.sshd.server.Command in project spring-integration by spring-projects.

the class SftpTestSupport method createServer.

@BeforeClass
public static void createServer() throws Exception {
    server = SshServer.setUpDefaultServer();
    server.setPasswordAuthenticator((username, password, session) -> true);
    server.setPort(0);
    server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser")));
    server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory()));
    server.setFileSystemFactory(new VirtualFileSystemFactory(remoteTemporaryFolder.getRoot().toPath()));
    server.start();
    port = server.getPort();
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) SftpSubsystemFactory(org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory) Command(org.apache.sshd.server.Command) VirtualFileSystemFactory(org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Aggregations

Command (org.apache.sshd.server.Command)14 SimpleGeneratorHostKeyProvider (org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider)9 File (java.io.File)7 NamedFactory (org.apache.sshd.common.NamedFactory)6 SftpSubsystemFactory (org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory)6 VirtualFileSystemFactory (org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory)4 ScpCommandFactory (org.apache.sshd.server.command.ScpCommandFactory)4 ServerSession (org.apache.sshd.server.session.ServerSession)4 PublicKey (java.security.PublicKey)3 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 SshServer (org.apache.sshd.SshServer)2 FileKeyPairProvider (org.apache.sshd.common.keyprovider.FileKeyPairProvider)2 PasswordAuthenticator (org.apache.sshd.server.PasswordAuthenticator)2 PublickeyAuthenticator (org.apache.sshd.server.PublickeyAuthenticator)2 SshServer (org.apache.sshd.server.SshServer)2 ScpCommandFactory (org.apache.sshd.server.scp.ScpCommandFactory)2