2015-04-23 37 views
2

我已經安裝的Apache米娜SSHD SFTP服務器,我添加一些用戶權限到it.To測試我使用WINSCP但我可以帶出服務器連接輸入正確的密碼和用戶name.It好像SetPasswordAuthenticator方法不會called.So我想知道如何爲啓動我的Apache米娜sshd的SFTP服務器,我設置了用戶名和密碼了安全服務器。阿帕奇米娜SSHD SetPasswordAuthenticator不執行

我的服務器代碼,

sshd = SshServer.setUpDefaultServer(); 
    sshd.setPort(2525); 
    sshd.setHost("172.xx.xx.xx"); 
    sshd.setPasswordAuthenticator(new MyPasswordAuthenticator()); 
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); 
    sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>> asList(new SftpSubsystem.Factory())); 

    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>(); 
    userAuthFactories.add(new UserAuthNone.Factory()); 
    sshd.setUserAuthFactories(userAuthFactories); 

    sshd.setCommandFactory(new ScpCommandFactory()); 

    sshd.setKeyExchangeFactories(Arrays 
      .<NamedFactory<KeyExchange>> asList(new DHG1.Factory())); 
    sshd.setCommandFactory(new ScpCommandFactory()); 
    sshd.setFileSystemFactory(new VirtualFileSystemFactory("C:/root")); 

MyPasswordAuthenticator代碼,

public class MyPasswordAuthenticator implements PasswordAuthenticator { 

public boolean authenticate(String username, String password, ServerSession session) { 
    boolean retour = false; 

    if ("user".equals(username) && "123".equals(password)) { 
     retour = true; 
    } 

    return retour; 
} 

}

Maven的依賴,

<dependency> 
     <groupId>org.apache.mina</groupId> 
     <artifactId>mina-core</artifactId> 
     <version>2.0.9</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.sshd</groupId> 
     <artifactId>sshd-sftp</artifactId> 
     <version>0.11.0</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.sshd</groupId> 
     <artifactId>sshd-core</artifactId> 
     <version>0.14.0</version> 
    </dependency> 

我是新來的Apache米娜Sshd.Appreciate任何 幫幫我。

回答

3

最後我發現它出錯了。通過刪除下面的代碼片段,您可以在服務器上執行sshd.setPasswordAuthenticator

List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>(); 
userAuthFactories.add(new UserAuthNone.Factory()); 
sshd.setUserAuthFactories(userAuthFactories); 

注意:如果你需要更多的安全性,你可以在上面的代碼片段使用適當實現,但僅僅只增加sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());您可以爲您的服務器設置基本的密碼驗證。