Search in sources :

Example 1 with UserAuth

use of org.apache.sshd.server.UserAuth in project hadoop by apache.

the class TestSFTPFileSystem method startSshdServer.

private static void startSshdServer() throws IOException {
    sshd = SshServer.setUpDefaultServer();
    // ask OS to assign a port
    sshd.setPort(0);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
    userAuthFactories.add(new UserAuthPassword.Factory());
    sshd.setUserAuthFactories(userAuthFactories);
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {

        @Override
        public boolean authenticate(String username, String password, ServerSession session) {
            if (username.equals("user") && password.equals("password")) {
                return true;
            }
            return false;
        }
    });
    sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
    sshd.start();
    port = sshd.getPort();
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) ServerSession(org.apache.sshd.server.session.ServerSession) ArrayList(java.util.ArrayList) NamedFactory(org.apache.sshd.common.NamedFactory) PasswordAuthenticator(org.apache.sshd.server.PasswordAuthenticator) Command(org.apache.sshd.server.Command) NamedFactory(org.apache.sshd.common.NamedFactory) UserAuth(org.apache.sshd.server.UserAuth) UserAuthPassword(org.apache.sshd.server.auth.UserAuthPassword)

Aggregations

ArrayList (java.util.ArrayList)1 NamedFactory (org.apache.sshd.common.NamedFactory)1 Command (org.apache.sshd.server.Command)1 PasswordAuthenticator (org.apache.sshd.server.PasswordAuthenticator)1 UserAuth (org.apache.sshd.server.UserAuth)1 UserAuthPassword (org.apache.sshd.server.auth.UserAuthPassword)1 SimpleGeneratorHostKeyProvider (org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider)1 ServerSession (org.apache.sshd.server.session.ServerSession)1