Package org.apache.sshd

Examples of org.apache.sshd.SshServer


        Logger log = LoggerFactory.getLogger(App.class);
        SampleSshApp app = new SampleSshApp();

        try {
            ApplicationContext context = app.start();
            SshServer server = (SshServer) context.getBean("sshServer");
            log.info("Server started on port " + server.getPort());
        } catch (Throwable t) {
            log.error("Error starting application: ", t);
            log.error("Exiting.");
            System.exit(1);
        }
View Full Code Here


        c.put(new ByteArrayInputStream(data.getBytes()), path);
        c.disconnect();
    }

    public static void main(String[] args) throws Exception {
        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setPort(8001);
        sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
        sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
        sshd.setShellFactory(new EchoShellFactory());
        sshd.setCommandFactory(new ScpCommandFactory());
        sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
        sshd.start();
        Thread.sleep(100000);
    }
View Full Code Here

  public void init() {
    try {
      ShellFactory factory = context.getPlugin(ShellFactory.class);

      //
      SshServer server = SshServer.setUpDefaultServer();
      server.setPort(port);

      if (this.idleTimeout > 0) {
        server.getProperties().put(ServerFactoryManager.IDLE_TIMEOUT, String.valueOf(this.idleTimeout));
      }
      if (this.authTimeout > 0) {
        server.getProperties().put(ServerFactoryManager.AUTH_TIMEOUT, String.valueOf(this.authTimeout));
      }

      server.setShellFactory(new CRaSHCommandFactory(factory, encoding));
      server.setCommandFactory(new SCPCommandFactory(context));
      server.setKeyPairProvider(keyPairProvider);

      //
      ArrayList<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>(0);
      for (SubsystemFactoryPlugin plugin : context.getPlugins(SubsystemFactoryPlugin.class)) {
        namedFactoryList.add(plugin.getFactory());
      }
      server.setSubsystemFactories(namedFactoryList);

      //
      for (AuthenticationPlugin authenticationPlugin : authenticationPlugins) {
        if (server.getPasswordAuthenticator() == null && authenticationPlugin.getCredentialType().equals(String.class)) {
          server.setPasswordAuthenticator(new PasswordAuthenticator() {
            public boolean authenticate(String _username, String _password, ServerSession session) {
              if (genericAuthenticate(String.class, _username, _password)) {
                // We store username and password in session for later reuse
                session.setAttribute(USERNAME, _username);
                session.setAttribute(PASSWORD, _password);
                return true;
              } else {
                return false;
              }
            }
          });
        }

        if (server.getPublickeyAuthenticator() == null && authenticationPlugin.getCredentialType().equals(PublicKey.class)) {
          server.setPublickeyAuthenticator(new PublickeyAuthenticator() {
            public boolean authenticate(String username, PublicKey key, ServerSession session) {
              return genericAuthenticate(PublicKey.class, username, key);
            }
          });
        }
      }

      //
      log.log(Level.INFO, "About to start CRaSSHD");
      server.start();
      localPort = server.getPort();
      log.log(Level.INFO, "CRaSSHD started on port " + localPort);

      //
      this.server = server;
    }
View Full Code Here

        ERXRouteRequestHandler.register(restHandler);
       
        boolean isSSHServerEnabled = ERXProperties.booleanForKeyWithDefault("er.wotaskd.sshd.enabled", false);
       
        if (isSSHServerEnabled) {
          SshServer sshd = SshServer.setUpDefaultServer();
          sshd.setPort(ERXProperties.intForKeyWithDefault("er.wotaskd.sshd.port", 6022));
          sshd.setPasswordAuthenticator(new SshPasswordAuthenticator());
          sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
          sshd.setCommandFactory(new ScpCommandFactory());
          sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
          sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/bash", "-i", "-l" }));
          try {
            sshd.start();
          }
          catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
View Full Code Here

    public void setSshServerId(String sshServerId) {
        this.sshServerId = sshServerId;
    }

    protected Object doExecute() throws Exception {
        SshServer server = (SshServer) container.getComponentInstance(sshServerId);

        log.debug("Created server: {}", server);

        server.setPort(port);

        server.start();

        System.out.println("SSH server listening on port " + port);

        if (!background) {
            synchronized (this) {
                log.debug("Waiting for server to shutdown");

                wait();
            }

            server.stop();
        }

        return null;
    }
View Full Code Here

        KarafJaasAuthenticator authenticator = new KarafJaasAuthenticator(sshRealm);

        UserAuthFactoriesFactory authFactoriesFactory = new UserAuthFactoriesFactory();
        authFactoriesFactory.setAuthMethods(authMethods);

        SshServer server = SshServer.setUpDefaultServer();
        server.setPort(sshPort);
        server.setHost(sshHost);
        server.setMacFactories(SshUtils.buildMacs(macs));
        server.setCipherFactories(SshUtils.buildCiphers(ciphers));
        server.setShellFactory(new ShellFactoryImpl(sessionFactory));
        server.setCommandFactory(new ScpCommandFactory(new ShellCommandFactory(sessionFactory)));
        server.setSubsystemFactories(Arrays.<NamedFactory<org.apache.sshd.server.Command>>asList(new SftpSubsystem.Factory()));
        server.setKeyPairProvider(keyPairProvider);
        server.setPasswordAuthenticator(authenticator);
        server.setPublickeyAuthenticator(authenticator);
        server.setFileSystemFactory(new KarafFileSystemFactory());
        server.setUserAuthFactories(authFactoriesFactory.getFactories());
        server.setAgentFactory(agentFactory);
        server.getProperties().put(SshServer.IDLE_TIMEOUT, Long.toString(sshIdleTimeout));
        if (welcomeBanner != null) {
            server.getProperties().put(SshServer.WELCOME_BANNER, welcomeBanner);
        }
        return server;
    }
View Full Code Here

     *
     * @return the server.
     * @throws IOException if so.
     */
    public static SshServer startServer(int port, SshdServerMock server) throws IOException {
        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setPort(port);
        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;
    }
View Full Code Here

TOP

Related Classes of org.apache.sshd.SshServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.