|
17 | 17 | package org.springframework.integration.sftp;
|
18 | 18 |
|
19 | 19 | import java.io.File;
|
20 |
| -import java.io.IOException; |
21 |
| -import java.nio.file.FileSystem; |
22 |
| -import java.nio.file.InvalidPathException; |
23 |
| -import java.nio.file.Path; |
24 | 20 | import java.util.Collections;
|
25 |
| -import java.util.Objects; |
26 | 21 |
|
27 |
| -import org.apache.sshd.common.file.root.RootedFileSystem; |
28 |
| -import org.apache.sshd.common.file.root.RootedFileSystemProvider; |
29 |
| -import org.apache.sshd.common.file.root.RootedPath; |
30 | 22 | import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
|
31 |
| -import org.apache.sshd.common.session.SessionContext; |
32 |
| -import org.apache.sshd.common.util.io.IoUtils; |
33 | 23 | import org.apache.sshd.server.SshServer;
|
34 | 24 | import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
35 | 25 | import org.apache.sshd.sftp.client.SftpClient;
|
@@ -81,7 +71,7 @@ public static void createServer() throws Exception {
|
81 | 71 | });
|
82 | 72 | sftpFactory.addSftpEventListener(EVENT_LISTENER);
|
83 | 73 | server.setSubsystemFactories(Collections.singletonList(sftpFactory));
|
84 |
| - server.setFileSystemFactory(new FixedVirtualFileSystemFactory(getRemoteTempFolder())); |
| 74 | + server.setFileSystemFactory(new VirtualFileSystemFactory(getRemoteTempFolder().toPath())); |
85 | 75 | server.start();
|
86 | 76 | port = server.getPort();
|
87 | 77 | }
|
@@ -111,37 +101,4 @@ public static void stopServer() throws Exception {
|
111 | 101 | }
|
112 | 102 | }
|
113 | 103 |
|
114 |
| - private static class FixedVirtualFileSystemFactory extends VirtualFileSystemFactory { |
115 |
| - |
116 |
| - FixedVirtualFileSystemFactory(File defaultHomeDir) { |
117 |
| - super(defaultHomeDir.toPath()); |
118 |
| - } |
119 |
| - |
120 |
| - @Override |
121 |
| - public FileSystem createFileSystem(SessionContext session) throws IOException { |
122 |
| - Path dir = getUserHomeDir(session); |
123 |
| - if (dir == null) { |
124 |
| - throw new InvalidPathException(session.getUsername(), "Cannot resolve home directory"); |
125 |
| - } |
126 |
| - |
127 |
| - return new FixedRootedFileSystemProvider().newFileSystem(dir, Collections.emptyMap()); |
128 |
| - } |
129 |
| - |
130 |
| - private static class FixedRootedFileSystemProvider extends RootedFileSystemProvider { |
131 |
| - |
132 |
| - protected Path resolveLocalPath(RootedPath path) { |
133 |
| - Objects.requireNonNull(path, "No rooted path to resolve"); |
134 |
| - RootedFileSystem rfs = path.getFileSystem(); |
135 |
| - Path root = rfs.getRoot(); |
136 |
| - Path resolved = IoUtils.chroot(root, path).normalize(); |
137 |
| - if (!resolved.startsWith(root)) { |
138 |
| - throw new InvalidPathException(root.toString(), "Not under root"); |
139 |
| - } |
140 |
| - return resolved; |
141 |
| - } |
142 |
| - |
143 |
| - } |
144 |
| - |
145 |
| - } |
146 |
| - |
147 | 104 | }
|
0 commit comments