Repository: mina-sshd
Updated Branches:
  refs/heads/master b8bf38740 -> 169ff4e43


[SSHD-792] Using common code to generate welcome banner for SshFsMounter


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/83ea75fa
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/83ea75fa
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/83ea75fa

Branch: refs/heads/master
Commit: 83ea75fad641ec9c564ce45e5f6d16e4c8d153e9
Parents: c047525
Author: Goldstein Lyor <l...@c-b4.com>
Authored: Sun Feb 25 12:21:23 2018 +0200
Committer: Lyor Goldstein <lyor.goldst...@gmail.com>
Committed: Wed Feb 28 19:47:03 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/sshd/server/SshServer.java  |  5 ++---
 .../server/subsystem/sftp/SshFsMounter.java     | 23 ++++++++++----------
 2 files changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/83ea75fa/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java 
b/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java
index e8dc4bf..5725152 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/SshServer.java
@@ -600,8 +600,6 @@ public class SshServer extends AbstractFactoryManager 
implements ServerFactoryMa
             System.exit(-1);
         }
 
-        System.err.println("Starting SSHD on port " + port);
-
         SshServer sshd = SshServer.setUpDefaultServer();
         Map<String, Object> props = sshd.getProperties();
         props.putAll(options);
@@ -626,8 +624,9 @@ public class SshServer extends AbstractFactoryManager 
implements ServerFactoryMa
             command -> new ProcessShellFactory(GenericUtils.split(command, ' 
')).create()
         ).build());
         sshd.setSubsystemFactories(Collections.singletonList(new 
SftpSubsystemFactory()));
-        sshd.start();
 
+        System.err.println("Starting SSHD on port " + port);
+        sshd.start();
         Thread.sleep(Long.MAX_VALUE);
     }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/83ea75fa/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java
 
b/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java
index 9320cc7..6b57926 100644
--- 
a/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java
+++ 
b/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java
@@ -26,13 +26,15 @@ import java.io.OutputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.TreeMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 
+import org.apache.sshd.common.PropertyResolver;
+import org.apache.sshd.common.PropertyResolverUtils;
 import org.apache.sshd.common.config.SshConfigFileReader;
 import org.apache.sshd.common.io.IoServiceFactory;
 import org.apache.sshd.common.io.mina.MinaServiceFactory;
@@ -244,13 +246,12 @@ public final class SshFsMounter {
     public static void main(String[] args) throws Exception {
         int port = SshConfigFileReader.DEFAULT_PORT;
         boolean error = false;
-        Map<String, String> options = new LinkedHashMap<>();
-
+        Map<String, Object> options = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
         int numArgs = GenericUtils.length(args);
         for (int i = 0; i < numArgs; i++) {
             String argName = args[i];
             if ("-p".equals(argName)) {
-                if (i + 1 >= numArgs) {
+                if ((i + 1) >= numArgs) {
                     System.err.println("option requires an argument: " + 
argName);
                     break;
                 }
@@ -272,7 +273,7 @@ public final class SshFsMounter {
                     break;
                 }
             } else if ("-o".equals(argName)) {
-                if (i + 1 >= numArgs) {
+                if ((i + 1) >= numArgs) {
                     System.err.println("option requires and argument: " + 
argName);
                     error = true;
                     break;
@@ -300,28 +301,28 @@ public final class SshFsMounter {
             System.exit(-1);
         }
 
-        System.err.println("Starting SSHD on port " + port);
-
         SshServer sshd = Utils.setupTestServer(SshFsMounter.class);
         Map<String, Object> props = sshd.getProperties();
-//        FactoryManagerUtils.updateProperty(props, 
ServerFactoryManager.WELCOME_BANNER, "Welcome to SSH-FS Mounter\n");
         props.putAll(options);
-        sshd.setPort(port);
-
+        PropertyResolver resolver = 
PropertyResolverUtils.toPropertyResolver(options);
         File targetFolder = 
Objects.requireNonNull(Utils.detectTargetFolder(MounterCommandFactory.class), 
"Failed to detect target folder");
         if (SecurityUtils.isBouncyCastleRegistered()) {
             
sshd.setKeyPairProvider(SecurityUtils.createGeneratorHostKeyProvider(new 
File(targetFolder, "key.pem").toPath()));
         } else {
             sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new 
File(targetFolder, "key.ser")));
         }
+        // Should come AFTER key pair provider setup so auto-welcome can be 
generated if needed
+        SshServer.setupServerBanner(sshd, resolver);
 
         sshd.setShellFactory(InteractiveProcessShellFactory.INSTANCE);
         sshd.setPasswordAuthenticator(AcceptAllPasswordAuthenticator.INSTANCE);
         sshd.setForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
         sshd.setCommandFactory(new 
ScpCommandFactory.Builder().withDelegate(MounterCommandFactory.INSTANCE).build());
         sshd.setSubsystemFactories(Collections.singletonList(new 
SftpSubsystemFactory()));
-        sshd.start();
+        sshd.setPort(port);
 
+        System.err.println("Starting SSHD on port " + port);
+        sshd.start();
         Thread.sleep(Long.MAX_VALUE);
     }
 }

Reply via email to