2015-04-23 80 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());您可以为您的服务器设置基本的密码验证。