【发布时间】: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