Exemplo n.º 1
0
 private void setupUserAuth(PublickeyAuthenticator auth) {
   List<NamedFactory<UserAuth>> list = new ArrayList<NamedFactory<UserAuth>>();
   if (auth != null) {
     list.add(new UserAuthPublicKey.Factory());
     sshd.setPublickeyAuthenticator(auth);
   } else {
     list.add(new UserAuthNone.Factory());
   }
   sshd.setUserAuthFactories(list);
 }
 /**
  * Starts a ssh server on the provided port.
  *
  * @param server the server mock to start
  * @return the server.
  * @throws IOException if so.
  */
 public static SshServer startServer(SshdServerMock server) throws IOException {
   SshServer sshd = SshServer.setUpDefaultServer();
   sshd.setPort(0);
   sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
   List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
   userAuthFactories.add(new UserAuthNone.Factory());
   sshd.setUserAuthFactories(userAuthFactories);
   sshd.setCommandFactory(server);
   sshd.start();
   return sshd;
 }
  public void start() throws IOException {
    if (isRunning()) {
      return;
    }

    sshd = SshServer.setUpDefaultServer();

    sshd.setPort(RGSParametersCLI.getSSHDServerPort());
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(HOST_KEY_PROVIDER_FILE));
    sshd.setFileSystemFactory(
        new CodeOrchestraFileSystemFactory(RGSParametersCLI.getWorkspacePath()));

    // sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" }));

    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
    userAuthFactories.add(new UserAuthPassword.Factory());
    sshd.setUserAuthFactories(userAuthFactories);
    sshd.setPasswordAuthenticator(
        new PasswordAuthenticator() {
          @Override
          public boolean authenticate(String user, String password, ServerSession serverSession) {
            return user.equals(RGSParametersCLI.getUsername())
                && password.equals(RGSParametersCLI.getPassword());
          }
        });

    sshd.setCommandFactory(new ScpCommandFactory());

    List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
    namedFactoryList.add(new SftpSubsystem.Factory());
    sshd.setSubsystemFactories(namedFactoryList);

    sshd.start();

    running = true;
  }