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().setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession session) {
private SshServer defaultSshServer() { SshServer sshServer = SshServer.setUpDefaultServer(); sshServer.setPort(randomPort()); ClassLoadableResourceKeyPairProvider fileKeyPairProvider = new ClassLoadableResourceKeyPairProvider(hostkey); sshServer.setKeyPairProvider(fileKeyPairProvider); sshServer.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession session) { return username.equals(password); } }); sshServer.setGSSAuthenticator(new BogusGSSAuthenticator()); sshServer.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); ScpCommandFactory commandFactory = new ScpCommandFactory(); commandFactory.setDelegateCommandFactory(new CommandFactory() { @Override public Command createCommand(String command) { return new ProcessShellFactory(command.split(" ")).create(); } }); sshServer.setCommandFactory(commandFactory); sshServer.setShellFactory(new ProcessShellFactory("ls")); return sshServer; }
@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(); }
SshServer server = SshServer.setUpDefaultServer(); try { server.setPasswordAuthenticator((arg0, arg1, arg2) -> true); server.setPort(0); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath()));
@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); } }
public void setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator) { sshdServer.setPasswordAuthenticator(passwordAuthenticator); }
protected void setupAuth() { sshd.setPasswordAuthenticator(this); sshd.setPublickeyAuthenticator(this); sshd.setGSSAuthenticator(null); }
private void configureAuthentication(SshServer sshd) { NamedFactory<UserAuth> auth; if (this.passwordAuthenticator != null) { sshd.setPasswordAuthenticator(this.passwordAuthenticator); auth = new UserAuthPasswordFactory(); } else { auth = new UserAuthNoneFactory(); } sshd.setUserAuthFactories(Collections.singletonList(auth)); }
public void setPasswordAuthenticator() { sshdServer.setPasswordAuthenticator(passwordAuthenticator()); }
private void configureAuthenticationPolicies(SshServer server, Shell props) { server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get(props.getHostKeyFile()))); server.setPublickeyAuthenticator(Objects.isNull(props.getPublicKeyFile()) ? RejectAllPublickeyAuthenticator.INSTANCE : new SshdAuthorizedKeysAuthenticator(Paths.get(props.getPublicKeyFile()))); server.setPasswordAuthenticator(passwordAuthenticator(props)); }
protected SshServer initSshServer(int port) { final SshServer sshd = SshServer.setUpDefaultServer(); sshd.setPort(port); sshd.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession session) { return USERNAME.equals(username) && PASSWORD.equals(password); } }); sshd.setPublickeyAuthenticator(new KeySetPublickeyAuthenticator(this.keys)); return sshd; }
public EmbeddedSSHServer(Path homeDir, int port) { this.sshServer = SshServer.setUpDefaultServer(); this.sshServer.setPort(port); this.sshServer.setCommandFactory(new EchoCommandFactory()); this.sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); this.sshServer.setPasswordAuthenticator((username, password, serverSession) -> username.equals("admin") && password.equals("admin")); this.sshServer.setPublickeyAuthenticator((s, publicKey, serverSession) -> true); this.homeDir = homeDir; if (EnvironmentUtils.isWindows()) { sshServer.setShellFactory(new ProcessShellFactory(new String[] { "cmd.exe " })); } else { sshServer.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-s" })); } }
public EmbeddedSSHServer(Path homeDir, int port) { this.sshServer = SshServer.setUpDefaultServer(); this.sshServer.setPort(port); this.sshServer.setCommandFactory(new EchoCommandFactory()); this.sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); this.sshServer.setPasswordAuthenticator((username, password, serverSession) -> username.equals("admin") && password.equals("admin")); this.sshServer.setPublickeyAuthenticator((s, publicKey, serverSession) -> true); this.homeDir = homeDir; if (EnvironmentUtils.isWindows()) { sshServer.setShellFactory(new ProcessShellFactory(new String[] { "cmd.exe " })); } else { sshServer.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-s" })); } }
public void setUser(String user, String password, PublicKey key) { sshd.setPasswordAuthenticator(new MyPasswordAuthenticator(user, password)); sshd.setPublickeyAuthenticator(new MyPublickeyAuthenticator(user, key)); }
public void startServer(Integer timeout) throws Exception { if (server != null) { throw failure("Server already started"); } server = SshServer.setUpDefaultServer(); if (timeout != null) { server.getProperties().put(FactoryManager.AUTH_TIMEOUT, timeout.toString()); } server.setPort(5000); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); server.setPasswordAuthenticator((username, password, sess) -> authenticator.authenticate(username, password, sess)); server.setShellFactory(new EchoShellFactory()); server.setServiceFactories(Arrays.asList(ServerConnectionServiceFactory.INSTANCE, AsyncUserAuthServiceFactory.INSTANCE)); server.start(); }
@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(); }
public static SshServer setupTestServer(Class<?> anchor) { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setKeyPairProvider(createTestHostKeyProvider(anchor)); sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setShellFactory(EchoShellFactory.INSTANCE); sshd.setCommandFactory(UnknownCommandFactory.INSTANCE); return sshd; }
public static SshServer setupTestServer(Class<?> anchor) { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setKeyPairProvider(createTestHostKeyProvider(anchor)); sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setShellFactory(EchoShellFactory.INSTANCE); sshd.setCommandFactory(UnknownCommandFactory.INSTANCE); return sshd; }
public static SshServer setupTestServer(Class<?> anchor) { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setKeyPairProvider(createTestHostKeyProvider(anchor)); sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE); sshd.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE); sshd.setShellFactory(EchoShellFactory.INSTANCE); sshd.setCommandFactory(UnknownCommandFactory.INSTANCE); return sshd; }