@Override public void stop() { if (this.running) { try { server.stop(true); } catch (Exception e) { throw new IllegalStateException(e); } finally { this.running = false; } } }
public void stopServer() { if (started.getAndSet(false)) { try { server.stop(true); } catch (IOException e) { throw new RuntimeException(e); } } }
public void stopServer() throws IOException { if(sshd == null) return; sshd.stop(true); //Delete Virtual File System folder Path dir = Paths.get(getVirtualFileSystemPath()); FileUtils.deleteDirectory(dir.toFile()); } }
@AfterClass public static void stopServer() throws Exception { server.stop(); File hostKey = new File("hostkey.ser"); if (hostKey.exists()) { hostKey.delete(); } }
@Test public void testCustomUserInfoFalse() throws Exception { SshServer server = SshServer.setUpDefaultServer(); try { DefaultSftpSessionFactory f = createServerAndClient(server); UserInfo userInfo = mock(UserInfo.class); when(userInfo.promptYesNo(anyString())).thenReturn(false); f.setUserInfo(userInfo); expectReject(f); } finally { server.stop(true); } }
@Test public void testCustomUserInfoTrue() throws Exception { SshServer server = SshServer.setUpDefaultServer(); try { DefaultSftpSessionFactory f = createServerAndClient(server); UserInfo userInfo = mock(UserInfo.class); when(userInfo.promptYesNo(anyString())).thenReturn(true); f.setUserInfo(userInfo); f.getSession().close(); } finally { server.stop(true); } }
@Test public void testDefaultUserInfoFalse() throws Exception { SshServer server = SshServer.setUpDefaultServer(); try { DefaultSftpSessionFactory f = createServerAndClient(server); expectReject(f); } finally { server.stop(true); } }
/** * Stop the SSH server. This method will block until all resources are actually disposed. * @throws IOException if stopping failed somehow */ public void stop() throws IOException { stop(false); }
public void run() { try { sshd.stop(true); } catch (IOException ignored) { } sshd=null; } }.start();
server.stop(true);
@Test public void testDefaultUserInfoTrue() throws Exception { SshServer server = SshServer.setUpDefaultServer(); try { DefaultSftpSessionFactory f = createServerAndClient(server); f.setAllowUnknownKeys(true); f.getSession().close(); } finally { server.stop(true); } }
@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); } }
/** * Stop ssh server * * @throws IOException in case of error */ @PreDestroy public void stopServer() throws IOException { sshServer().stop(); }
@After public void tearDown() throws Exception { if (sshd != null) { sshd.stop(true); } }
@After public void tearDown() throws Exception { if (sshd != null) { sshd.stop(true); } }
@After public void tearDown() throws Exception { if (sshd != null) { sshd.stop(true); } }
@After public void tearDown() throws Exception { if (sshd != null) { sshd.stop(true); } }
@After public void tearDown() throws Exception { if (sshd != null) { sshd.stop(true); } }
@After public void tearDown() throws Exception { if (sshd != null) { sshd.stop(true); } if (acceptor != null) { acceptor.dispose(true); } if (client != null) { client.stop(); } }