public void setupSftpServer(){ SshServer sshd = SshServer.setUpDefaultServer(); sshd.setPort(22); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser")); List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>(); userAuthFactories.add(new UserAuthNone.Factory()); sshd.setUserAuthFactories(userAuthFactories); sshd.setCommandFactory(new ScpCommandFactory()); List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>(); namedFactoryList.add(new SftpSubsystem.Factory()); sshd.setSubsystemFactories(namedFactoryList); try { sshd.start(); } catch (Exception e) { e.printStackTrace(); } }
public void destroy() { if (server != null) { try { server.stop(); } catch (InterruptedException e) { log.log(Level.FINE, "Got an interruption when stopping server", e); } } }
SshServer server = SshServer.setUpDefaultServer(); server.setPort(port); server.getProperties().put(ServerFactoryManager.IDLE_TIMEOUT, String.valueOf(this.idleTimeout)); server.getProperties().put(ServerFactoryManager.AUTH_TIMEOUT, String.valueOf(this.authTimeout)); server.setShellFactory(new CRaSHCommandFactory(factory, encoding)); server.setCommandFactory(new SCPCommandFactory(context)); server.setKeyPairProvider(keyPairProvider); namedFactoryList.add(plugin.getFactory()); server.setSubsystemFactories(namedFactoryList); if (server.getPasswordAuthenticator() == null && authenticationPlugin.getCredentialType().equals(String.class)) { server.setPasswordAuthenticator(new PasswordAuthenticator() { public boolean authenticate(String _username, String _password, ServerSession session) { if (genericAuthenticate(String.class, _username, _password)) { if (server.getPublickeyAuthenticator() == null && authenticationPlugin.getCredentialType().equals(PublicKey.class)) { server.setPublickeyAuthenticator(new PublickeyAuthenticator() { public boolean authenticate(String username, PublicKey key, ServerSession session) { return genericAuthenticate(PublicKey.class, username, key); server.start(); localPort = server.getPort(); log.log(Level.INFO, "CRaSSHD started on port " + localPort);
public SSHClient connect() throws Exception { Map<PtyMode, Integer> tty = SttySupport.parsePtyModes(TTY); SshClient client = SshClient.setUpDefaultClient(); client.start(); ClientSession session = client.connect("localhost", port).await().getSession(); session.authPassword("root", ""); ChannelShell channel = (ChannelShell)session.createShellChannel(); channel.setPtyModes(tty); channel.setIn(channelIn); channel.setOut(channelOut); channel.setErr(new ByteArrayOutputStream()); channel.open();
@Override public AuthFuture authenticate(final ClientSession session) throws IOException { session.addPasswordIdentity(password); return session.auth(); } }
@Override public String[] interactive(ClientSession session, String name, String instruction, String lang, String[] prompt, boolean[] echo) { validateSession("interactive", session); return null; }
@Override public Command create() { return new TestEchoShell(); } }
@Override public Command create() { return new FloodingAsyncCommand(msg, BIG_MSG_SEND_COUNT, END_FILE); } });
/** * Stops the embedded Apache SSHd Server (MINA). * * @throws InterruptedException */ private static void tearDownClass() throws InterruptedException { if (Server != null) { Server.stop(); } }
@Override public AuthFuture authenticate(final ClientSession session) throws IOException { session.addPasswordIdentity(password); return session.auth(); } }
@Override public String[] interactive(ClientSession session, String name, String instruction, String lang, String[] prompt, boolean[] echo) { validateSession("interactive", session); return null; }
@Override public Command create() { return new TestEchoShell(); } }
@Override public Command create() { return new FloodingAsyncCommand(msg, BIG_MSG_SEND_COUNT, END_FILE); } });
/** * Stops the embedded Apache SSHd Server (MINA). * * @throws InterruptedException */ private static void tearDownClass() throws InterruptedException { if (Server != null) { Server.stop(); } }
@Override public String[] interactive(ClientSession session, String name, String instruction, String lang, String[] prompt, boolean[] echo) { validateSession("interactive", session); return null; }
@Override public Command create() { return new TestEchoShell(); } }
/** * Stops the embedded Apache SSHd Server (MINA). * * @throws InterruptedException */ private static void tearDownClass() throws InterruptedException { if (Server != null) { Server.stop(); } }
@Override public void serverVersionInfo(ClientSession session, List<String> lines) { validateSession("serverVersionInfo", session); }