mardi 29 mars 2016

In memory/embedded SFTP server for test with private key authentication in Java

The scenario is that I need to write tests for an application that does SFTP file transfers and I need an in memory/embedded SFTP server with private key authentication implementation so that I can test that file transfers run okay with the embedded/ in memory server with private key (.pem) file authentication.

I have raked through the guts of internet the closest I came to was Apache Mina Server as discussed in this S.O. question

Currently I am using a username and password authentication as below:

SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(22999);

sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {

    public boolean authenticate(String username, String password,
                                ServerSession session) {
        // TODO Auto-generated method stub
        return true;
    }
});

I tried finding a way to implement private key authentication but it seems there is only one authenticator but that is a public key authenticator as below:

public void setPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator) {
    this.publickeyAuthenticator = publickeyAuthenticator;
}

Is there a way to implement private key authenticator with Apache Mina? or if it's impossible there is there any other mock SFTP server I could use for my testing scenario?

Aucun commentaire:

Enregistrer un commentaire