我正在使用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永远不会被调用。 有人可以指点我错过的东西吗? 任何帮助表示赞赏。

问候,马克

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐