Package org.apache.sshd

Examples of org.apache.sshd.SshServer


        c.put(new ByteArrayInputStream(data.getBytes()), path);
        c.disconnect();
    }

    public static void main(String[] args) throws Exception {
        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setPort(8001);
        sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
        sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
        sshd.setShellFactory(new EchoShellFactory());
        sshd.setCommandFactory(new ScpCommandFactory());
        sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
        sshd.start();
        Thread.sleep(100000);
    }
View Full Code Here


        //
        // TODO: the GitpgmCommandFactory is kept in the test tree
        // TODO: because it's quite limited for now
        //

        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setPort(8001);
        sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
        sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
        sshd.setShellFactory(new EchoShellFactory());
        sshd.setCommandFactory(new GitPgmCommandFactory("target/git/pgm"));
        sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
        sshd.start();

        File serverDir = new File("target/git/pgm");
        Utils.deleteRecursive(serverDir);

        File repo = new File(serverDir, "test");

        SshClient client = SshClient.setUpDefaultClient();
        client.start();

        ClientSession session = client.connect("sshd", "localhost", 8001).await().getSession();
        session.addPasswordIdentity("sshd");
        session.auth().verify();

        Git.init().setDirectory(repo).call();
        Git git = Git.open(repo);
        git.commit().setMessage("First Commit").setCommitter("sshd", "sshd@apache.org").call();

        new File("target/git/pgm/test/readme.txt").createNewFile();
        execute(session, "git --git-dir test add readme.txt");

        execute(session, "git --git-dir test commit -m \"readme\"");

        client.stop();
        sshd.stop();
    }
View Full Code Here

*/
public class GitPackCommandTest {

    @Test
    public void testGitPack() throws Exception {
        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setPort(8001);
        sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
        sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
        sshd.setShellFactory(new EchoShellFactory());
        sshd.setCommandFactory(new GitPackCommandFactory("target/git/server"));
        sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
        sshd.start();

        File serverDir = new File("target/git/server/test.git");
        Utils.deleteRecursive(serverDir);
        Git.init().setBare(true).setDirectory(serverDir).call();

        JSch.setConfig("StrictHostKeyChecking", "no");
        CredentialsProvider.setDefault(new UsernamePasswordCredentialsProvider("sshd", "sshd"));
        GitSshdSessionFactory.setInstance(new GitSshdSessionFactory());

        File dir = new File("target/git/local/test.git");
        Utils.deleteRecursive(dir);
        Git.cloneRepository()
                .setURI("ssh://sshd@localhost:8001/test.git")
                .setDirectory(dir)
                .call();

        Git git = Git.open(dir);
        git.commit().setMessage("First Commit").setCommitter("sshd", "sshd@apache.org").call();
        git.push().call();

        new File("target/git/local/test.git/readme.txt").createNewFile();
        git.add().addFilepattern("readme.txt").call();
        git.commit().setMessage("readme").setCommitter("sshd", "sshd@apache.org").call();
        git.push().call();

        git.pull().setRebase(true).call();

        sshd.stop();
    }
View Full Code Here

    public void setSshServerId(String sshServerId) {
        this.sshServerId = sshServerId;
    }

    protected Object doExecute() throws Exception {
        SshServer server = (SshServer) container.getComponentInstance(sshServerId);

        log.debug("Created server: {}", server);

        // port number
        server.setPort(port);

        // idle timeout
        server.getProperties().put(SshServer.IDLE_TIMEOUT, new Long(idleTimeout).toString());

        // starting the SSHd server
        server.start();

        System.out.println("SSH server listening on port " + port + " (idle timeout " + idleTimeout + "ms)");

        if (!background) {
            synchronized (this) {
                log.debug("Waiting for server to shutdown");

                wait();
            }

            server.stop();
        }

        return null;
    }
View Full Code Here

    public void setSshServerId(String sshServerId) {
        this.sshServerId = sshServerId;
    }

    protected Object doExecute() throws Exception {
        SshServer server = (SshServer) container.getComponentInstance(sshServerId);

        log.debug("Created server: {}", server);

        // port number
        server.setPort(port);

        // idle timeout
        server.getProperties().put(SshServer.IDLE_TIMEOUT, new Long(idleTimeout).toString());

        // starting the SSHd server
        server.start();

        System.out.println("SSH server listening on port " + port + " (idle timeout " + idleTimeout + "ms)");

        if (!background) {
            synchronized (this) {
                log.debug("Waiting for server to shutdown");

                wait();
            }

            server.stop();
        }

        return null;
    }
View Full Code Here

    public void setSshServerId(String sshServerId) {
        this.sshServerId = sshServerId;
    }

    protected Object doExecute() throws Exception {
        SshServer server = (SshServer) container.getComponentInstance(sshServerId);

        log.debug("Created server: {}", server);

        // port number
        server.setPort(port);

        // idle timeout
        server.getProperties().put(SshServer.IDLE_TIMEOUT, new Long(idleTimeout).toString());

        // welcome banner
        if (welcomeBanner != null) {
            server.getProperties().put(SshServer.WELCOME_BANNER, welcomeBanner);
        }

        // starting the SSHd server
        server.start();

        System.out.println("SSH server listening on port " + port + " (idle timeout " + idleTimeout + "ms)");

        if (!background) {
            synchronized (this) {
                log.debug("Waiting for server to shutdown");

                wait();
            }

            server.stop();
        }

        return null;
    }
View Full Code Here

    public void setSshServerId(String sshServerId) {
        this.sshServerId = sshServerId;
    }

    protected Object doExecute() throws Exception {
        SshServer server = (SshServer) container.getComponentInstance(sshServerId);

        log.debug("Created server: {}", server);

        server.setPort(port);

        server.start();

        System.out.println("SSH server listening on port " + port);

        if (!background) {
            synchronized (this) {
                log.debug("Waiting for server to shutdown");

                wait();
            }

            server.stop();
        }

        return null;
    }
View Full Code Here

    public void testGit() {

    }

    public static void main(String[] args) throws Exception {
        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.getProperties().put(SshServer.IDLE_TIMEOUT, "10000");
        sshd.setPort(8001);
        sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
        sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
        sshd.setShellFactory(new EchoShellFactory());
//        sshd.setCommandFactory(new ScpCommandFactory());
        sshd.setCommandFactory(new CommandFactory() {
            public Command createCommand(String command) {
                if (command.startsWith("git-")) {
                    return new GitCommand(command.substring("git-".length()));
                } else {
                    return new UnknownCommand(command);
                }
            }
        });
        sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
        sshd.start();
        Thread.sleep(100000);
    }
View Full Code Here

    public void setSshServerId(String sshServerId) {
        this.sshServerId = sshServerId;
    }

    protected Object doExecute() throws Exception {
        SshServer server = (SshServer) container.getComponentInstance(sshServerId);

        log.debug("Created server: {}", server);

        // port number
        server.setPort(port);

        // idle timeout
        server.getProperties().put(SshServer.IDLE_TIMEOUT, new Long(idleTimeout).toString());

        // starting the SSHd server
        server.start();

        System.out.println("SSH server listening on port " + port + " (idle timeout " + idleTimeout + "ms)");

        if (!background) {
            synchronized (this) {
                log.debug("Waiting for server to shutdown");

                wait();
            }

            server.stop();
        }

        return null;
    }
View Full Code Here

    public void setSshServerId(String sshServerId) {
        this.sshServerId = sshServerId;
    }

    protected Object doExecute() throws Exception {
        SshServer server = (SshServer) container.getComponentInstance(sshServerId);

        log.debug("Created server: {}", server);

        server.setPort(port);

        server.start();

        System.out.println("SSH server listening on port " + port);

        if (!background) {
            synchronized (this) {
                log.debug("Waiting for server to shutdown");

                wait();
            }

            server.stop();
        }

        return null;
    }
View Full Code Here

TOP

Related Classes of org.apache.sshd.SshServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.