简体   繁体   English

Apache Mina SSHD 1.0.0设置用户目录和映射

[英]Apache Mina SSHD 1.0.0 set user directory & mapping

Trying to set a home directory for a user using Apache Mina SSHD embedded in Java. 尝试使用Java中嵌入的Apache Mina SSHD为用户设置主目录。

Both solutions are deprecated in 1.0 in- 两种解决方案均在1.0 in-
How to Set Root Directory in Apache Mina Sshd Server in Java 如何在Java中的Apache Mina Sshd Server中设置根目录
How to override getVirtualUserDir() in Apache Mina sshd-core version 0.14.0 如何在Apache Mina sshd-core版本0.14.0中覆盖getVirtualUserDir()

In 0.14.0 the following worked fine: 在0.14.0中,以下工作正常:

sshd.setFileSystemFactory(new NativeFileSystemFactory() {
   @Override
   public FileSystemView createFileSystem(final Session session) {
      HashMap<String,String> map = new HashMap<String,String>();
      map.put("/", "/Users/someone/Documents");
      return new NativeFileSystemView(session.getUsername(), map, "/");
   };
});

This is as far as I got: 据我所知:

sshd.setFileSystemFactory(new NativeFileSystemFactory() {
    @Override
    public FileSystem createFileSystem(Session session) {
        // What should I do here?
        return super.createFileSystem(session);
    }
});

Found it. 找到了。
I had to use the VirtualFileSystemFactory class . 我必须使用VirtualFileSystemFactory

This is the result: 结果如下:

VirtualFileSystemFactory fsFactory = new VirtualFileSystemFactory();
fsFactory.setUserHomeDir(userName, realDirectory);
sshd.setFileSystemFactory(fsFactory);

Note: If you're using OS X or linux , don't forget to chmod your path first. 注:如果您使用OS XLinux,不要忘了chmod首先你的路径。

对于v1.2.0(如果是Java 7)/ v1.3.0(如果是Java 8)和java.nio.file.Path用法,解决方案可能是:

sshServer.setFileSystemFactory(new VirtualFileSystemFactory(FileSystems.getDefault().getPath(rootDir)));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM