Esempio n. 1
0
  @Override
  public void start() throws ServiceException {
    sshServer = SshServer.setUpDefaultServer();
    sshServer.setPort(port);
    sshServer.setHost(bind);

    final String basePath = SystemInstance.get().getBase().getDirectory().getAbsolutePath();
    if (SecurityUtils.isBouncyCastleRegistered()) {
      sshServer.setKeyPairProvider(
          new PEMGeneratorHostKeyProvider(new File(basePath, KEY_NAME + ".pem").getPath()));
    } else {
      sshServer.setKeyPairProvider(
          new SimpleGeneratorHostKeyProvider(new File(basePath, KEY_NAME + ".ser").getPath()));
    }

    final OpenEJBShellFactory sf = new OpenEJBShellFactory(bind, port);
    sshServer.setShellFactory(sf);

    final JaasPasswordAuthenticator authenticator = new OpenEJBJaasPasswordAuthenticator();
    authenticator.setDomain(domain);
    sshServer.setPasswordAuthenticator(authenticator);

    try {
      sshServer.start();
    } catch (IOException e) {
      // no-op
    }
  }
Esempio n. 2
0
 public NccCLI(Integer port) {
   sshd = SshServer.setUpDefaultServer();
   sshd.setPort(port);
   sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
   sshd.setPasswordAuthenticator(new NccPasswordAuthenticator());
   sshd.setShellFactory(new NccShellFactory());
 }
Esempio n. 3
0
  @Before
  public void setup() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(10000);

    // Write port number to configuration file in target
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
      basedir = new File(".").getCanonicalPath();
    }

    // Read in camel configuration file and substitute in the correct port
    File f = new File(basedir + "/src/test/resources/camel-scp.xml");

    FileInputStream inputStream = new FileInputStream(f);
    String content = IOUtils.toString(inputStream, "UTF-8");
    inputStream.close();
    content = content.replaceAll("portno", "" + port);

    File f2 = new File(basedir + "/target/test-classes/camel-scp.xml");
    FileOutputStream outputStream = new FileOutputStream(f2);
    IOUtils.write(content, outputStream, "UTF-8");
    outputStream.close();

    sshServer = SshServer.setUpDefaultServer();
    sshServer.setPort(port);

    // Generate a key
    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("target/generatedkey.pem"));

    sshServer.setCommandFactory(new ScpCommandFactory());

    sshServer.setPasswordAuthenticator(new CamelPasswordAuthenticator());
    sshServer.start();

    setupKnownHosts(port);

    // Create "storage" directory (delete it first if it exists)
    File storageDirectory = new File(basedir + "/target/storage");
    if (storageDirectory.exists()) {
      storageDirectory.delete();
    }
    storageDirectory.mkdir();
  }
  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;
  }
Esempio n. 5
0
  @Autowired
  public OpalSshServer(
      @Qualifier("ssh") CommandRegistry commandRegistry,
      OpalShellFactory shellFactory,
      OpalShellHolder opalShellHolder,
      @Value("${org.obiba.opal.ssh.port}") Integer port) {
    this.commandRegistry = commandRegistry;
    this.shellFactory = shellFactory;
    this.opalShellHolder = opalShellHolder;

    sshd = SshServer.setUpDefaultServer();
    sshd.setPort(port);
    sshd.setKeyPairProvider(
        new PEMGeneratorHostKeyProvider(
            System.getProperty("OPAL_HOME") + "/conf/sshd.pem", "RSA", 2048));
    sshd.setShellFactory(
        new Factory<Command>() {

          @Override
          public Command create() {
            return new OpalShellCommand();
          }
        });
    sshd.setPasswordAuthenticator(
        new PasswordAuthenticator() {

          @Override
          public boolean authenticate(String username, String password, ServerSession session) {
            try {
              Subject subject = SecurityUtils.getSubject();
              subject.login(
                  new UsernamePasswordToken(
                      username,
                      password.toCharArray(),
                      session.getIoSession().getRemoteAddress().toString()));
              ensureProfile(subject);
              // Sessions don't expire automatically
              SecurityUtils.getSubject().getSession().setTimeout(-1);
            } catch (AuthenticationException ae) {
              return false;
            }
            return SecurityUtils.getSubject().isAuthenticated();
          }

          private void ensureProfile(Subject subject) {
            Object principal = subject.getPrincipal();

            if (!subjectProfileService.supportProfile(principal)) {
              return;
            }
            subjectProfileService.ensureProfile(subject.getPrincipals());
          }
        });
    sshd.setFileSystemFactory(
        new FileSystemFactory() {

          @Override
          public FileSystemView createFileSystemView(Session session) throws IOException {
            return new OpalFileSystemView(opalRuntime, session.getUsername());
          }
        });
    sshd.setSubsystemFactories(
        ImmutableList.<NamedFactory<Command>>of(new SftpSubsystem.Factory()));
  }