我正在使用Apache Mina SSHD来实现测试SFTPServer.我已经能够为简单的密码验证工作,但是我无法为PublicKey身份验证配置东西.我有一个实现了PublickeyAuthenticator接口,如下所示,
public class SimpleKeyAuthenticator implements PublickeyAuthenticator {
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
System.out.println("In authenticate");
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我的服务器实现如下,
...
sshd = SshServer.setUpDefaultServer();
sshd.setPort(2222);
//sshd.setPort(config.getSFTPPort());
//sshd.setKeyPairProvider(new
sshd.setKeyPairProvider(new PEMGeneratorHostKeyProvider("hostkey.pem"));
//sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.setPublickeyAuthenticator(new SimpleKeyAuthenticator());
sshd.setFileSystemFactory(new SimpleFileSystemFactory());
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthNone.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
sshd.setSessionFactory(new SimpleSessionFactory(handler));
try {
sshd.start();
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用我的SFTP客户端获取文件时,一切正常.我希望authenticate方法失败,因为它总是返回false.我已经尝试将KeyPairProvider设置为使用PEMGeneratorHostKeyProvider和SimpleGeneratorHostKeyProvider.我还设置了PublicKeyAuthenticator来使用我的SimpleKeyAuthenticator类.注意,当我查看控制台输出时,我从未看到"In authenticate",因此我知道Authenticate永远不会被调用.有人可以指点我错过的东西吗?任何帮助表示赞赏.
问候,马克