public void start() throws IOException { if (!started.getAndSet(true)) { server.start(); } }
@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 void startServer() throws IOException { sshd = SshServer.setUpDefaultServer(); sshd.setHost("localhost"); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); //Accept all keys for authentication sshd.setPublickeyAuthenticator((s, publicKey, serverSession) -> true); //Allow username/password authentication using pre-defined credentials sshd.setPasswordAuthenticator((username, password, serverSession) -> this.username.equals(username) && this.password.equals(password)); //Setup Virtual File System (VFS) //Ensure VFS folder exists Path dir = Paths.get(getVirtualFileSystemPath()); Files.createDirectories(dir); sshd.setFileSystemFactory(new VirtualFileSystemFactory(dir.toAbsolutePath())); //Add SFTP support List<NamedFactory<Command>> sftpCommandFactory = new ArrayList<>(); sftpCommandFactory.add(new SftpSubsystemFactory()); sshd.setSubsystemFactories(sftpCommandFactory); sshd.start(); }
fixture.getServer().start();
@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(); }
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; }
server.setPort(0); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); server.start();
@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); } }
private void createAndRunSshServer() { server = createSshServer(sessionFactory); this.bundleContext.registerService(SshServer.class, server, null); if (server == null) { return; // can result from bad specification. } try { server.start(); } catch (IOException e) { LOGGER.warn("Exception caught while starting SSH server", e); } }
private void createAndRunSshServer() { server = createSshServer(sessionFactory); this.bundleContext.registerService(SshServer.class, server, null); if (server == null) { return; // can result from bad specification. } try { server.start(); } catch (IOException e) { LOGGER.warn("Exception caught while starting SSH server", e); } }
/** * Starts Groovysh * * @throws IOException thrown if socket cannot be opened */ public synchronized void start() throws IOException { sshd = buildSshServer(); sshd.start(); }
/** * Start ssh server * * @throws IOException in case of error */ @PostConstruct public void startServer() throws IOException { sshServer().start(); LOGGER.info("Ssh server started [{}:{}]", properties.getHost(), properties.getPort()); }
public void start() throws IOException { AbstractClassLoadableResourceKeyPairProvider keyPairProvider = SecurityUtils.createClassLoadableResourceKeyPairProvider(); keyPairProvider.setResources(Arrays.asList("keys/sham-ssh-id-dsa")); sshServer.setKeyPairProvider(keyPairProvider); sshServer.start(); }
@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(); 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(); }
@Override public void afterPropertiesSet() throws Exception { this.sftpFolder.create(); this.localFolder.create(); this.server.setPasswordAuthenticator((username, password, session) -> true); this.server.setPort(this.port); this.server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser"))); this.server.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); this.server.setFileSystemFactory(new VirtualFileSystemFactory(sftpRootFolder.toPath())); this.server.start(); }
@Before public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, TIMEOUT); sshd.setShellFactory(new TestEchoShellFactory()); sshd.start(); port = sshd.getPort(); }