gpt4 book ai didi

java - Apache Mina Sshd SetPasswordAuthenticator 不执行

转载 作者:行者123 更新时间:2023-11-30 07:01:28 26 4
gpt4 key购买 nike

我已经设置了 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 的新手。感谢任何帮助。

最佳答案

最后我发现哪里出了问题。通过删除下面的代码片段,您可以在服务器上执行 sshd.setPasswordAuthenticator

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

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

关于java - Apache Mina Sshd SetPasswordAuthenticator 不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29816206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com