PasswordAuthenticator idAuth = new PasswordAuthenticator(); Map<String, String> credentials = new HashMap<String, String>(); credentials.put(idAuth.USERNAME_KEY, userName);
private static Session createSession(String host, int port, boolean sslAuthenticationRequired, String userName, String password, boolean debug) { Properties properties = new Properties(); String mailSmtp = "mail.smtp"; if (sslAuthenticationRequired) { mailSmtp += "s"; properties.put(mailSmtp + ".socketFactory.port", Integer.toString(port)); properties.put(mailSmtp + ".socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.put(mailSmtp + ".socketFactory.fallback", "false"); } properties.put("mail.debug", debug ? "true" : "false"); properties.put(mailSmtp + ".host", host); properties.put(mailSmtp + ".user", userName); properties.put(mailSmtp + ".password", password); properties.put(mailSmtp + ".port", Integer.toString(port)); properties.put(mailSmtp + ".starttls.enable", "true"); properties.put(mailSmtp + ".auth", "true"); return Session.getDefaultInstance(properties, new PasswordAuthenticator(userName, password)); }
userAuthFactories.add(new UserAuthPassword.Factory()); sshServer.setUserAuthFactories(userAuthFactories); sshServer.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession session) {
sshd.setCommandFactory(new ScpCommandFactory()); sshd.setShellFactory(new ProcessShellFactory(new String[] { "/system/bin/sh", "-i", "-l" })); // necessary if you want to type commands over ssh sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
public void startSSHServer() { int port = 8888; SshServer sshd = SshServer.setUpDefaultServer(); sshd.setPort(port); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider( "src/test/resources/hostkey.ser")); sshd.setSubsystemFactories(Arrays .<NamedFactory<Command>> asList(new SftpSubsystem.Factory())); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setShellFactory(new ProcessShellFactory(new String[] { "/system/bin/sh", "-i", "-l" })); // necessary if you want to type commands over ssh sshd.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String u, String p, ServerSession s) { return ("sftptest".equals(u) && "sftptest".equals(p)); } }); try { sshd.start(); } catch (IOException e) { e.printStackTrace(); } }
sshd.setPasswordAuthenticator(new PasswordAuthenticator() { public boolean authenticate(String username, String password, ServerSession session) { boolean authentic = false;
result.setPort(22); result.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser")); result.setPasswordAuthenticator(new PasswordAuthenticator() { public boolean authenticate(String username, String password, ServerSession session) { return "assentisftp".equals(username);