This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-filetransfer.git

commit f462a9f76fcfe4064a9d614ece3b29f147ec5d97
Author: Oliver Lietz <[email protected]>
AuthorDate: Wed Aug 22 23:07:53 2018 +0200

    SLING-7851 Provide file transfer over SFTP for JCR
---
 .gitignore                                         |  17 ++
 .sling-module.xml                                  |  24 ++
 LICENSE                                            | 202 +++++++++++++++++
 README.md                                          |   7 +
 bnd.bnd                                            |   3 +
 pom.xml                                            | 242 +++++++++++++++++++++
 .../jcr/filetransfer/ChrootDirectoryProvider.java  |  29 +++
 .../sling/jcr/filetransfer/package-info.java       |  22 ++
 .../internal/DefaultChrootDirectoryProvider.java   |  55 +++++
 ...efaultChrootDirectoryProviderConfiguration.java |  36 +++
 .../sftp/internal/FileHostKeyProvider.java         |  63 ++++++
 .../internal/FileHostKeyProviderConfiguration.java |  42 ++++
 .../sftp/internal/JcrFileSystemFactory.java        | 101 +++++++++
 .../sftp/internal/JcrHostKeyProvider.java          |  83 +++++++
 .../internal/JcrHostKeyProviderConfiguration.java  |  42 ++++
 .../sftp/internal/JcrPasswordAuthenticator.java    |  66 ++++++
 .../filetransfer/sftp/internal/SftpService.java    |  95 ++++++++
 .../sftp/internal/SftpServiceConfiguration.java    |  36 +++
 .../filetransfer/it/JcrFileSystemFactoryIT.java    |  39 ++++
 .../it/JcrFiletransferTestSupport.java             |  65 ++++++
 20 files changed, 1269 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5b783ed
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,17 @@
+/target
+.idea
+.classpath
+.metadata
+.project
+.settings
+.externalToolBuilders
+maven-eclipse.xml
+*.swp
+*.iml
+*.ipr
+*.iws
+*.bak
+.vlt
+.DS_Store
+jcr.log
+atlassian-ide-plugin.xml
diff --git a/.sling-module.xml b/.sling-module.xml
new file mode 100644
index 0000000..a402095
--- /dev/null
+++ b/.sling-module.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<sling-module>
+  <jenkins>
+    <enabled>false</enabled>
+  </jenkins>
+</sling-module>
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4be40fb
--- /dev/null
+++ b/README.md
@@ -0,0 +1,7 @@
+# Apache Sling JCR File Transfer
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
+
+This module provides file access to JCR over SFTP.
+
+    sftp -oPort=2222 admin@localhost
diff --git a/bnd.bnd b/bnd.bnd
new file mode 100644
index 0000000..e36a0d6
--- /dev/null
+++ b/bnd.bnd
@@ -0,0 +1,3 @@
+-removeheaders:\
+  Include-Resource,\
+  Private-Package
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..b490970
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,242 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.sling</groupId>
+    <artifactId>sling</artifactId>
+    <version>34</version>
+    <relativePath/>
+  </parent>
+
+  <artifactId>org.apache.sling.jcr.filetransfer</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+
+  <name>Apache Sling JCR File Transfer</name>
+  <description>File access to JCR over SFTP</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    <sling.java.version>8</sling.java.version>
+    <org.ops4j.pax.exam.version>4.12.0</org.ops4j.pax.exam.version>
+  </properties>
+
+  <scm>
+    
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-filetransfer.git</connection>
+    
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-filetransfer.git</developerConnection>
+    
<url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-jcr-filetransfer.git</url>
+  </scm>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>biz.aQute.bnd</groupId>
+        <artifactId>bnd-maven-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>biz.aQute.bnd</groupId>
+        <artifactId>bnd-baseline-maven-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-failsafe-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>integration-test</goal>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <redirectTestOutputToFile>true</redirectTestOutputToFile>
+          <systemProperties>
+            <property>
+              <name>bundle.filename</name>
+              <value>${basedir}/target/${project.build.finalName}.jar</value>
+            </property>
+          </systemProperties>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.servicemix.tooling</groupId>
+        <artifactId>depends-maven-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>maven-sling-plugin</artifactId>
+        <configuration>
+          <slingUrl>http://localhost:8181/system/console</slingUrl>
+          <user>karaf</user>
+          <password>karaf</password>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <!-- javax -->
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>javax.jcr</groupId>
+      <artifactId>jcr</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <!-- OSGi -->
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.annotation.versioning</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.metatype.annotations</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <!-- Apache Felix -->
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.framework</artifactId>
+      <version>5.6.10</version>
+      <scope>test</scope>
+    </dependency>
+    <!-- Apache MINA -->
+    <dependency>
+      <groupId>org.apache.sshd</groupId>
+      <artifactId>sshd-core</artifactId>
+      <version>2.0.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sshd</groupId>
+      <artifactId>sshd-sftp</artifactId>
+      <version>2.0.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <!-- Apache Sling -->
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.api</artifactId>
+      <version>2.11.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.commons.jcr.file</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.jcr.api</artifactId>
+      <version>2.4.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.serviceusermapper</artifactId>
+      <version>1.4.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.testing.paxexam</artifactId>
+      <version>2.0.0</version>
+      <scope>test</scope>
+    </dependency>
+    <!-- nullability -->
+    <dependency>
+      <groupId>org.jetbrains</groupId>
+      <artifactId>annotations</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <!-- logging -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <!-- testing -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicemix.bundles</groupId>
+      <artifactId>org.apache.servicemix.bundles.hamcrest</artifactId>
+      <version>1.3_1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-cm</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-container-forked</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-junit4</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-link-mvn</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/ChrootDirectoryProvider.java 
b/src/main/java/org/apache/sling/jcr/filetransfer/ChrootDirectoryProvider.java
new file mode 100644
index 0000000..7f333fb
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/ChrootDirectoryProvider.java
@@ -0,0 +1,29 @@
+/*
+ * 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.sling.jcr.filetransfer;
+
+import org.apache.sshd.common.session.Session;
+import org.jetbrains.annotations.NotNull;
+
+public interface ChrootDirectoryProvider {
+
+    @NotNull
+    String getChrootDirectory(@NotNull final Session session);
+
+}
diff --git a/src/main/java/org/apache/sling/jcr/filetransfer/package-info.java 
b/src/main/java/org/apache/sling/jcr/filetransfer/package-info.java
new file mode 100644
index 0000000..5966cfd
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/filetransfer/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+@Version("0.0.1")
+package org.apache.sling.jcr.filetransfer;
+
+import org.osgi.annotation.versioning.Version;
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/DefaultChrootDirectoryProvider.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/DefaultChrootDirectoryProvider.java
new file mode 100644
index 0000000..0f4f072
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/DefaultChrootDirectoryProvider.java
@@ -0,0 +1,55 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import org.apache.sling.jcr.filetransfer.ChrootDirectoryProvider;
+import org.apache.sshd.common.session.Session;
+import org.jetbrains.annotations.NotNull;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.metatype.annotations.Designate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+    property = {
+        Constants.SERVICE_DESCRIPTION + "=Apache Sling JCR File Transfer 
Default Chroot Directory Provider",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+    }
+)
+@Designate(
+    ocd = DefaultChrootDirectoryProviderConfiguration.class
+)
+public class DefaultChrootDirectoryProvider implements ChrootDirectoryProvider 
{
+
+    private final Logger logger = 
LoggerFactory.getLogger(DefaultChrootDirectoryProvider.class);
+
+    public DefaultChrootDirectoryProvider() {
+    }
+
+    @Override
+    @NotNull
+    public String getChrootDirectory(@NotNull final Session session) {
+        final String username = session.getUsername();
+        final String chroot = String.format("/var/filetransfer/%s", username);
+        logger.info("providing chroot {} for user {}", chroot, username);
+        return chroot;
+    }
+
+}
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/DefaultChrootDirectoryProviderConfiguration.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/DefaultChrootDirectoryProviderConfiguration.java
new file mode 100644
index 0000000..fce2366
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/DefaultChrootDirectoryProviderConfiguration.java
@@ -0,0 +1,36 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@ObjectClassDefinition(
+    name = "Apache Sling JCR File Transfer Default Chroot Directory Provider",
+    description = "Provides chroot directory based on session user"
+)
+@interface DefaultChrootDirectoryProviderConfiguration {
+
+    @AttributeDefinition(
+        name = "service ranking",
+        description = "service ranking"
+    )
+    int service_ranking() default 0;
+
+}
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/FileHostKeyProvider.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/FileHostKeyProvider.java
new file mode 100644
index 0000000..0fdaabc
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/FileHostKeyProvider.java
@@ -0,0 +1,63 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import java.nio.file.Paths;
+
+import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.Designate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+    service = KeyPairProvider.class,
+    property = {
+        Constants.SERVICE_DESCRIPTION + "=Apache Sling JCR File Transfer File 
Host Key Provider",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+        "type=file"
+    }
+)
+@Designate(
+    ocd = FileHostKeyProviderConfiguration.class
+)
+public class FileHostKeyProvider extends SimpleGeneratorHostKeyProvider {
+
+    private final Logger logger = 
LoggerFactory.getLogger(FileHostKeyProvider.class);
+
+    public FileHostKeyProvider() {
+    }
+
+    @Activate
+    private void activate(final FileHostKeyProviderConfiguration 
configuration) {
+        logger.debug("activating");
+        setPath(Paths.get(configuration.path()));
+    }
+
+    @Deactivate
+    private void deactivate() {
+        logger.debug("deactivating");
+        setPath(null);
+    }
+
+}
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/FileHostKeyProviderConfiguration.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/FileHostKeyProviderConfiguration.java
new file mode 100644
index 0000000..68a8a96
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/FileHostKeyProviderConfiguration.java
@@ -0,0 +1,42 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@ObjectClassDefinition(
+    name = "Apache Sling JCR File Transfer File Host Key Provider",
+    description = "Stores the SSH host key in file system"
+)
+@interface FileHostKeyProviderConfiguration {
+
+    @AttributeDefinition(
+        name = "service ranking",
+        description = "service ranking"
+    )
+    int service_ranking() default 1;
+
+    @AttributeDefinition(
+        name = "path",
+        description = "path where host key is stored, ensure path is 
readable/writable"
+    )
+    String path() default "/var/sling/ssh/hostkey.ser";
+
+}
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrFileSystemFactory.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrFileSystemFactory.java
new file mode 100644
index 0000000..0b57d34
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrFileSystemFactory.java
@@ -0,0 +1,101 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.FileSystem;
+import java.nio.file.spi.FileSystemProvider;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.Credentials;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.filetransfer.ChrootDirectoryProvider;
+import org.apache.sshd.common.file.FileSystemFactory;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+    service = FileSystemFactory.class,
+    property = {
+        Constants.SERVICE_DESCRIPTION + "=TODO",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+        "type=jcr"
+    }
+)
+public class JcrFileSystemFactory implements FileSystemFactory {
+
+    @Reference(
+        policy = ReferencePolicy.DYNAMIC,
+        policyOption = ReferencePolicyOption.GREEDY,
+        target = "(type=jcr)"
+    )
+    private volatile FileSystemProvider fileSystemProvider;
+
+    @Reference(
+        policy = ReferencePolicy.DYNAMIC,
+        policyOption = ReferencePolicyOption.GREEDY
+    )
+    private volatile SlingRepository slingRepository;
+
+    @Reference(
+        policy = ReferencePolicy.DYNAMIC,
+        policyOption = ReferencePolicyOption.GREEDY
+    )
+    private volatile ChrootDirectoryProvider chrootDirectoryProvider;
+
+    private final Logger logger = 
LoggerFactory.getLogger(JcrFileSystemFactory.class);
+
+    public JcrFileSystemFactory() {
+    }
+
+    @Override
+    public FileSystem createFileSystem(final 
org.apache.sshd.common.session.Session session) throws IOException {
+        logger.info("creating file system for {}", session.getUsername());
+        try {
+            final String username = session.getUsername();
+            final String chroot = 
chrootDirectoryProvider.getChrootDirectory(session);
+            final Session jcrSession = createUserSession(username);
+            final URI uri = new URI("jcr", null, chroot, null);
+            final Map<String, Object> env = new HashMap<>();
+            env.put(Session.class.getName(), jcrSession);
+            logger.debug("file system URI: {}", uri.toString());
+            return fileSystemProvider.newFileSystem(uri, env);
+        } catch (Exception e) {
+            throw new IOException(e);
+        }
+    }
+
+    private Session createUserSession(final String username) throws 
RepositoryException {
+        final Session session = slingRepository.loginAdministrative(null);
+        final Credentials credentials = new SimpleCredentials(username, 
"".toCharArray());
+        return session.impersonate(credentials);
+    }
+
+}
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrHostKeyProvider.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrHostKeyProvider.java
new file mode 100644
index 0000000..b2887c7
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrHostKeyProvider.java
@@ -0,0 +1,83 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Paths;
+import java.security.GeneralSecurityException;
+import java.security.KeyPair;
+
+import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.server.keyprovider.AbstractGeneratorHostKeyProvider;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.Designate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// TODO read and write host key from/to JCR
+
+@Component(
+    service = KeyPairProvider.class,
+    property = {
+        Constants.SERVICE_DESCRIPTION + "=Apache Sling JCR File Transfer JCR 
Host Key Provider",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+    }
+)
+@Designate(
+    ocd = JcrHostKeyProviderConfiguration.class
+)
+public class JcrHostKeyProvider extends AbstractGeneratorHostKeyProvider {
+
+    private final Logger logger = 
LoggerFactory.getLogger(JcrHostKeyProvider.class);
+
+    public JcrHostKeyProvider() {
+    }
+
+    @Activate
+    private void activate(final FileHostKeyProviderConfiguration 
configuration) {
+        logger.debug("activating");
+        setPath(Paths.get(configuration.path()));
+    }
+
+    @Deactivate
+    private void deactivate() {
+        logger.debug("deactivating");
+        setPath(null);
+    }
+
+    @Override
+    public KeyPair loadKey(String type) {
+        return null;
+    }
+
+    @Override
+    public Iterable<String> getKeyTypes() {
+        return null;
+    }
+
+    @Override
+    protected void doWriteKeyPair(String resourceKey, KeyPair kp, OutputStream 
outputStream) throws IOException, GeneralSecurityException {
+
+    }
+
+}
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrHostKeyProviderConfiguration.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrHostKeyProviderConfiguration.java
new file mode 100644
index 0000000..c709ad4
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrHostKeyProviderConfiguration.java
@@ -0,0 +1,42 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@ObjectClassDefinition(
+    name = "Apache Sling JCR File Transfer JCR Host Key Provider",
+    description = "Stores the SSH host key in JCR"
+)
+@interface JcrHostKeyProviderConfiguration {
+
+    @AttributeDefinition(
+        name = "service ranking",
+        description = "service ranking"
+    )
+    int service_ranking() default 0;
+
+    @AttributeDefinition(
+        name = "path",
+        description = "path where host key is stored, ensure path is 
readable/writable"
+    )
+    String path() default "/var/sling/ssh/hostkey.ser";
+
+}
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrPasswordAuthenticator.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrPasswordAuthenticator.java
new file mode 100644
index 0000000..612ebcc
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/JcrPasswordAuthenticator.java
@@ -0,0 +1,66 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.sshd.server.auth.AsyncAuthException;
+import org.apache.sshd.server.auth.password.PasswordAuthenticator;
+import org.apache.sshd.server.auth.password.PasswordChangeRequiredException;
+import org.apache.sshd.server.session.ServerSession;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+    property = {
+        Constants.SERVICE_DESCRIPTION + "=Apache Sling JCR File Transfer 'JCR 
Password Authenticator'",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+    }
+)
+public class JcrPasswordAuthenticator implements PasswordAuthenticator {
+
+    @Reference
+    private volatile Repository repository;
+
+    private final Logger logger = 
LoggerFactory.getLogger(JcrPasswordAuthenticator.class);
+
+    @Override
+    public boolean authenticate(final String username, final String password, 
final ServerSession serverSession) throws PasswordChangeRequiredException, 
AsyncAuthException {
+        logger.info("authenticating {} with password", username);
+        Session session = null;
+        try {
+            session = repository.login(new SimpleCredentials(username, 
password.toCharArray()));
+            logger.info("authenticating user {} ({}) succeeded", username, 
session.getUserID());
+            return true;
+        } catch (Exception e) {
+            logger.error("authenticating user {} failed: {}", username, 
e.getMessage());
+        } finally {
+            if (session != null) {
+                session.logout();
+            }
+        }
+        return false;
+    }
+
+}
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/SftpService.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/SftpService.java
new file mode 100644
index 0000000..f76091e
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/SftpService.java
@@ -0,0 +1,95 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.apache.sshd.common.file.FileSystemFactory;
+import org.apache.sshd.common.keyprovider.KeyPairProvider;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.password.PasswordAuthenticator;
+import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.Designate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+    immediate = true,
+    property = {
+        Constants.SERVICE_DESCRIPTION + "=Apache Sling JCR File Transfer SFTP 
Service",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+    }
+)
+@Designate(
+    ocd = SftpServiceConfiguration.class
+)
+public class SftpService {
+
+    @Reference(
+        target = "(type=jcr)"
+    )
+    private volatile FileSystemFactory fileSystemFactory;
+
+    @Reference
+    private volatile PasswordAuthenticator passwordAuthenticator;
+
+    @Reference
+    private volatile KeyPairProvider keyPairProvider;
+
+    private SftpSubsystemFactory sftpSubsystemFactory = new 
SftpSubsystemFactory();
+
+    private SshServer sshServer;
+
+    private SftpServiceConfiguration configuration;
+
+    private final Logger logger = LoggerFactory.getLogger(SftpService.class);
+
+    @Activate
+    private void activate(final SftpServiceConfiguration configuration) throws 
IOException {
+        logger.debug("activating");
+        this.configuration = configuration;
+        sshServer = sshServer();
+        sshServer.start();
+    }
+
+    @Deactivate
+    private void deactivate() throws IOException {
+        logger.debug("deactivating");
+        sshServer.stop();
+        sshServer = null;
+        configuration = null;
+    }
+
+    private SshServer sshServer() {
+        final SshServer sshServer = SshServer.setUpDefaultServer();
+        sshServer.setPort(configuration.ssh_server_port());
+        sshServer.setPasswordAuthenticator(passwordAuthenticator);
+        sshServer.setKeyPairProvider(keyPairProvider);
+        
sshServer.setSubsystemFactories(Collections.singletonList(sftpSubsystemFactory));
+        sshServer.setFileSystemFactory(fileSystemFactory);
+        return sshServer;
+    }
+
+}
diff --git 
a/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/SftpServiceConfiguration.java
 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/SftpServiceConfiguration.java
new file mode 100644
index 0000000..68bdc43
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/jcr/filetransfer/sftp/internal/SftpServiceConfiguration.java
@@ -0,0 +1,36 @@
+/*
+ * 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.sling.jcr.filetransfer.sftp.internal;
+
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@ObjectClassDefinition(
+    name = "Apache Sling JCR File Transfer 'SFTP Service'",
+    description = "Provides SFTP access to JCR"
+)
+@interface SftpServiceConfiguration {
+
+    @AttributeDefinition(
+        name = "SSH server port",
+        description = "port of the SSH server"
+    )
+    int ssh_server_port() default 2222;
+
+}
diff --git 
a/src/test/java/org/apache/sling/jcr/filetransfer/it/JcrFileSystemFactoryIT.java
 
b/src/test/java/org/apache/sling/jcr/filetransfer/it/JcrFileSystemFactoryIT.java
new file mode 100644
index 0000000..61c7ef6
--- /dev/null
+++ 
b/src/test/java/org/apache/sling/jcr/filetransfer/it/JcrFileSystemFactoryIT.java
@@ -0,0 +1,39 @@
+/*
+ * 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.sling.jcr.filetransfer.it;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class JcrFileSystemFactoryIT extends JcrFiletransferTestSupport {
+
+    @Test
+    public void testFileSystemFactory() {
+        assertThat(fileSystemFactory, notNullValue());
+    }
+
+}
diff --git 
a/src/test/java/org/apache/sling/jcr/filetransfer/it/JcrFiletransferTestSupport.java
 
b/src/test/java/org/apache/sling/jcr/filetransfer/it/JcrFiletransferTestSupport.java
new file mode 100644
index 0000000..a306ea6
--- /dev/null
+++ 
b/src/test/java/org/apache/sling/jcr/filetransfer/it/JcrFiletransferTestSupport.java
@@ -0,0 +1,65 @@
+/*
+ * 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.sling.jcr.filetransfer.it;
+
+import javax.inject.Inject;
+
+import org.apache.sling.testing.paxexam.TestSupport;
+import org.apache.sshd.common.file.FileSystemFactory;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.util.Filter;
+
+import static 
org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+
+public abstract class JcrFiletransferTestSupport extends TestSupport {
+
+    @Inject
+    @Filter(value = "(type=jcr)")
+    protected FileSystemFactory fileSystemFactory;
+
+    @Configuration
+    public Option[] configuration() {
+        return new Option[]{
+            baseConfiguration(),
+            quickstart(),
+            // Sling JCR File Transfer
+            testBundle("bundle.filename"),
+            
mavenBundle().groupId("org.apache.sshd").artifactId("sshd-core").versionAsInProject(),
+            
mavenBundle().groupId("org.apache.sshd").artifactId("sshd-sftp").versionAsInProject(),
+            // Sling Commons JCR File
+            
mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.commons.jcr.file").versionAsInProject(),
+            // testing
+            
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
+            junitBundles()
+        };
+    }
+
+    protected Option quickstart() {
+        final int httpPort = findFreePort();
+        final String workingDirectory = workingDirectory();
+        return composite(
+            slingQuickstartOakTar(workingDirectory, httpPort)
+        );
+    }
+
+}

Reply via email to