2013-04-29 34 views
5

olarak adlandırılmıyor SFTPServer bir test uygulamak için Apache Mina SSHD kullanıyorum. Basit Parola kimlik doğrulaması için işleri halledebildim, ancak PublicKey Authentication için işleri yapılandıramıyorum. aşağıdaki gibi benim SFTP istemcisi her şey çalışıyor kullanarak bir dosya almak için denediğimde Ancak, aşağıdaki gibiApache Mina kullanarak SFTP sınama sunucusu için PublicKey Kimlik Doğrulaması'nı uygulamaya çalışıyorum. Ancak Kimlik Doğrulama yöntemi

public class SimpleKeyAuthenticator implements PublickeyAuthenticator { 

    @Override 
    public boolean authenticate(String username, PublicKey key, ServerSession session) { 
     System.out.println("In authenticate"); 
     return false; 
    } 

} 

Sunucum uygulamasıdır,

... 
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(); 
} 

PublickeyAuthenticator arayüzünü uygulamıştır. Kimlik doğrulaması yönteminin her zaman false döndürdüğü için başarısız olmasını beklerim. Ben PEMGeneratorHostKeyProvider ve SimpleGeneratorHostKeyProvider hem kullanmak için KeyPairProvider ayarlamayı denedim. SimpleKeyAuthenticator sınıfımı kullanmak için PublicKeyAuthenticator'ı da ayarladım. Not, konsol çıktısına baktığımda hiç bir zaman 'Kimlik doğrulamasında' göremiyorum, bu yüzden Kimlik Doğrulamanın asla çağrılmadığını biliyorum. Birisi beni neye özlediğimi gösterebilir mi? Herhangi bir yardım takdir edilir.

Selamlar, sınırının altında Mark

cevap

2

// herhangi doğrulaması İstemci girişini yapacaktır.

userAuthFactories.add (new UserAuthNone.Factory());

Böyle değiştirmek gerekir:

userAuthFactories.add (yeni UserAuthPublicKey.Factory());