【问题标题】:Apache Mina Sshd SetPasswordAuthenticator Does not ExecuteApache Mina Sshd SetPasswordAuthenticator 不执行
【发布时间】:2015-07-01 05:04:18
【问题描述】:

我已经设置了 Apache Mina Sshd SFTP 服务器,并在其中添加了一些用户权限。为了测试我使用 Winscp 但我可以在不输入正确密码和用户名的情况下连接服务器。看起来像 SetPasswordAuthenticator 方法从未调用。所以我想知道如何为我的 apache mina sshd SFTP 服务器设置用户名和密码以启动安全服务器。

我的服务器代码,

sshd = SshServer.setUpDefaultServer();
    sshd.setPort(2525);
    sshd.setHost("172.xx.xx.xx");
    sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>> asList(new SftpSubsystem.Factory()));

    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
    userAuthFactories.add(new UserAuthNone.Factory());
    sshd.setUserAuthFactories(userAuthFactories);

    sshd.setCommandFactory(new ScpCommandFactory());

    sshd.setKeyExchangeFactories(Arrays
            .<NamedFactory<KeyExchange>> asList(new DHG1.Factory()));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setFileSystemFactory(new VirtualFileSystemFactory("C:/root"));

MyPasswordAuthenticator 代码,

public class MyPasswordAuthenticator implements PasswordAuthenticator {

public boolean authenticate(String username, String password, ServerSession session) {
    boolean retour = false;

    if ("user".equals(username) && "123".equals(password)) {
        retour = true;
    }

    return retour;
}

}

Maven 依赖,

<dependency>
        <groupId>org.apache.mina</groupId>
        <artifactId>mina-core</artifactId>
        <version>2.0.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.sshd</groupId>
        <artifactId>sshd-sftp</artifactId>
        <version>0.11.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.sshd</groupId>
        <artifactId>sshd-core</artifactId>
        <version>0.14.0</version>
    </dependency>

我是 Apache Mina Sshd 的新手。感谢任何帮助。

【问题讨论】:

    标签: java sftp winscp apache-mina sshd


    【解决方案1】:

    我终于找到了问题所在。通过删除下面的代码 sn-p 你可以在服务器上执行 sshd.setPasswordAuthenticator

    List<NamedFactory<UserAuth>> userAuthFactories = new  ArrayList<NamedFactory<UserAuth>>();
    userAuthFactories.add(new UserAuthNone.Factory());
    sshd.setUserAuthFactories(userAuthFactories);
    

    注意:如果您需要更高的安全性,您可以使用上面的代码 sn-p 并正确实现,但只需添加 sshd.setPasswordAuthenticator(new MyPasswordAuthenticator()); 即可为您的服务器设置基本密码验证。

    【讨论】:

      猜你喜欢
      • 2015-09-02
      • 2020-11-14
      • 1970-01-01
      • 2016-04-11
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-10
      相关资源
      最近更新 更多