作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经设置了 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/
我已经设置了 Apache Mina Sshd SFTP 服务器并向其中添加了一些用户权限。为了测试我使用 Winscp 但我可以连接服务器而无需输入正确的密码和用户名。看起来像 SetPasswor
我是一名优秀的程序员,十分优秀!