Пример #1
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());
 }
Пример #2
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
    }
  }
Пример #3
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()));
  }