public int getSSHPort(){ return sshd.getPort(); }
@Override public void start() { try { this.server.start(); this.defaultSftpSessionFactory.setPort(this.server.getPort()); this.running = true; } catch (IOException e) { throw new IllegalStateException(e); } }
public SSHClient connectClient(SSHClient client) throws IOException { client.connect(server.getHost(), server.getPort()); return client; }
@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").toPath())); server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); server.setFileSystemFactory(new VirtualFileSystemFactory(remoteTemporaryFolder.getRoot().toPath())); server.start(); port = server.getPort(); }
/** * The port the server is running on. * * @return The port the server is running on. */ public int getPort() { return sshd.getPort(); }
private DefaultSftpSessionFactory createServerAndClient(SshServer server) throws IOException { server.setPublickeyAuthenticator((username, key, session) -> true); server.setPort(0); server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); 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; }
f.setPort(server.getPort()); f.setUser("user"); f.setPassword("pass");
@Test public void testUcPw() throws Exception { SshServer server = SshServer.setUpDefaultServer(); try { server.setPasswordAuthenticator((arg0, arg1, arg2) -> true); server.setPort(0); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); final String pathname = System.getProperty("java.io.tmpdir") + File.separator + "sftptest" + File.separator; new File(pathname).mkdirs(); server.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(pathname))); server.start(); DefaultSftpSessionFactory f = new DefaultSftpSessionFactory(); f.setHost("localhost"); f.setPort(server.getPort()); f.setUser("user"); f.setPassword("pass"); f.setAllowUnknownKeys(true); Session<LsEntry> session = f.getSession(); doTest(server, session); } finally { server.stop(true); } }
private void testKeyExchange(String pubKey, String privKey, String passphrase) throws Exception { SshServer server = SshServer.setUpDefaultServer(); final PublicKey allowedKey = decodePublicKey(pubKey); try { server.setPublickeyAuthenticator((username, key, session) -> key.equals(allowedKey)); server.setPort(0); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); final String pathname = System.getProperty("java.io.tmpdir") + File.separator + "sftptest" + File.separator; new File(pathname).mkdirs(); server.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(pathname))); server.start(); DefaultSftpSessionFactory f = new DefaultSftpSessionFactory(); f.setHost("localhost"); f.setPort(server.getPort()); f.setUser("user"); f.setAllowUnknownKeys(true); InputStream stream = new ClassPathResource(privKey).getInputStream(); f.setPrivateKey(new ByteArrayResource(FileCopyUtils.copyToByteArray(stream))); f.setPrivateKeyPassphrase(passphrase); Session<LsEntry> session = f.getSession(); doTest(server, session); } finally { server.stop(true); } }
@Override public String toString() { return getClass().getSimpleName() + "[" + Integer.toHexString(hashCode()) + "]" + "(port=" + getPort() + ")"; }
/** * Returns the port that the SSH server is bind to. */ public int getPort() { return sshd.getPort(); } }
@Before public void setUp() throws Exception { sshd = setupTestServer(); sshd.start(); port = sshd.getPort(); }
@Before public void setUp() throws Exception { sshd = setupTestServer(); sshd.start(); port = sshd.getPort(); }
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, ServerFactoryManager.WELCOME_BANNER, WELCOME); sshd.start(); port = sshd.getPort(); }
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, ServerFactoryManager.WELCOME_BANNER, WELCOME); sshd.start(); port = sshd.getPort(); }
@Before public void setUp() throws Exception { sshd = setupTestServer(); sshd.setSessionFactory(new SessionFactory(sshd) { @Override protected ServerSessionImpl doCreateSession(IoSession ioSession) throws Exception { return new TestSession(getServer(), ioSession); } }); sshd.start(); port = sshd.getPort(); }
@Before public void setUp() throws Exception { sshd = setupTestServer(); sshd.setSessionFactory(new SessionFactory(sshd) { @Override protected ServerSessionImpl doCreateSession(IoSession ioSession) throws Exception { return new TestSession(getServer(), ioSession); } }); sshd.start(); port = sshd.getPort(); }
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, TIMEOUT); sshd.setShellFactory(new TestEchoShellFactory()); sshd.start(); port = sshd.getPort(); }
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, TIMEOUT); sshd.setShellFactory(new TestEchoShellFactory()); sshd.start(); port = sshd.getPort(); }
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, TIMEOUT); sshd.setShellFactory(new TestEchoShellFactory()); sshd.start(); port = sshd.getPort(); }