[KARAF-2789] Upgrade to SSHD 0.11.0
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/6057a370 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/6057a370 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/6057a370 Branch: refs/heads/master Commit: 6057a370184abe9fddb4ca2001883de1d1cfdc60 Parents: 9944918 Author: Guillaume Nodet <gno...@gmail.com> Authored: Tue Apr 22 09:35:49 2014 +0200 Committer: Guillaume Nodet <gno...@gmail.com> Committed: Tue Apr 22 14:31:49 2014 +0200 ---------------------------------------------------------------------- pom.xml | 2 +- .../karaf/shell/ssh/KarafFileSystemFactory.java | 10 ++- .../karaf/shell/ssh/KarafFileSystemView.java | 66 -------------------- 3 files changed, 10 insertions(+), 68 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/6057a370/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 0cc1447..69ef8aa 100644 --- a/pom.xml +++ b/pom.xml @@ -247,7 +247,7 @@ <spring40.version>4.0.2.RELEASE_1</spring40.version> <spring.security31.version>3.1.4.RELEASE</spring.security31.version> - <sshd.version>0.10.1</sshd.version> + <sshd.version>0.11.0</sshd.version> <struts.bundle.version>1.3.10_1</struts.bundle.version> <xbean.version>3.16</xbean.version> <xerces.version>2.11.0</xerces.version> http://git-wip-us.apache.org/repos/asf/karaf/blob/6057a370/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java ---------------------------------------------------------------------- diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java index ba3b741..8d69af3 100644 --- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java +++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java @@ -18,9 +18,14 @@ */ package org.apache.karaf.shell.ssh; +import java.io.File; +import java.util.HashMap; +import java.util.Map; + import org.apache.sshd.common.Session; import org.apache.sshd.common.file.FileSystemFactory; import org.apache.sshd.common.file.FileSystemView; +import org.apache.sshd.common.file.nativefs.NativeFileSystemView; /** * SSHd file system factory to reduce the visibility to the KARAF_BASE. @@ -28,7 +33,10 @@ import org.apache.sshd.common.file.FileSystemView; public class KarafFileSystemFactory implements FileSystemFactory { public FileSystemView createFileSystemView(Session session) { - return new KarafFileSystemView(session.getUsername()); + Map<String, String> roots = new HashMap<String, String>(); + String dir = new File(System.getProperty("karaf.base")).getAbsolutePath(); + roots.put("/", dir); + return new NativeFileSystemView(session.getUsername(), roots, "/"); } } http://git-wip-us.apache.org/repos/asf/karaf/blob/6057a370/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemView.java ---------------------------------------------------------------------- diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemView.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemView.java deleted file mode 100644 index 6724e4f..0000000 --- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemView.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.karaf.shell.ssh; - -import java.io.File; - -import org.apache.sshd.common.file.SshFile; -import org.apache.sshd.common.file.nativefs.NativeFileSystemView; -import org.apache.sshd.common.file.nativefs.NativeSshFile; - -/** - * Karaf file system view reduced to the KARAF_BASE location - */ -public class KarafFileSystemView extends NativeFileSystemView { - - private String username; - private String location; - - public KarafFileSystemView(String username) { - super(username); - this.username = username; - } - - @Override - public String getVirtualUserDir() { - return "/"; - } - - @Override - public String getPhysicalUserDir() { - if (location == null) { - location = new File(System.getProperty("karaf.base")).getAbsolutePath(); - } - return location; - } - - protected SshFile getFile(String dir, String file) { - // get actual file object - String location = getPhysicalUserDir(); - String physicalName = NativeSshFile.getPhysicalName(location, dir, file, false); - if (!physicalName.startsWith(location)) { - throw new IllegalArgumentException("The path is not relative to KARAF_BASE. For security reason, it's not allowed"); - } - File fileObj = new File(physicalName); - // strip the root directory and return - String karafFileName = physicalName.substring(location.length()); - return createNativeSshFile(karafFileName, fileObj, username); - } - -}