sftp 服务器验证,sftp - 尝试使用Apache Mina为SFTP测试服务器实现PublicKey身份验证。 但是没有调用Authenticate方法 - 堆栈内存溢出...
我正在使用Apache Mina SSHD来实现测试SFTPServer。我已经能够为简单的密码验证工作,但是我无法为PublicKey身份验证配置东西。我有一个实现了PublickeyAuthenticator接口,如下所示,public class SimpleKeyAuthenticator implements PublickeyAuthenticator {@Overridepu...
我正在使用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;
}
}
我的服务器实现如下,
...
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> userAuthFactories = new ArrayList>();
userAuthFactories.add(new UserAuthNone.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
List> namedFactoryList = new ArrayList>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
sshd.setSessionFactory(new SimpleSessionFactory(handler));
try {
sshd.start();
} catch (Exception e) {
e.printStackTrace();
}
但是,当我尝试使用我的SFTP客户端获取文件时,一切正常。 我希望authenticate方法失败,因为它总是返回false。 我已经尝试将KeyPairProvider设置为使用PEMGeneratorHostKeyProvider和SimpleGeneratorHostKeyProvider。 我还设置了PublicKeyAuthenticator来使用我的SimpleKeyAuthenticator类。 注意,当我查看控制台输出时,我从未看到“In authenticate”,因此我知道Authenticate永远不会被调用。 有人可以指点我错过的东西吗? 任何帮助表示赞赏。
问候,马克
更多推荐
所有评论(0)