org.apache.sshd.server.command.Command Java Examples

The following examples show how to use org.apache.sshd.server.command.Command. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SshServerLauncher.java    From onedev with MIT License 6 votes vote down vote up
@Listen
  public void on(SystemStarted event) {
      server = SshServer.setUpDefaultServer();

      server.setPort(serverConfig.getSshPort());
      server.setKeyPairProvider(keyPairProvider);
      server.setShellFactory(new DisableShellAccess());
      
      server.setPublickeyAuthenticator(new CachingPublicKeyAuthenticator(authenticator));
      server.setKeyboardInteractiveAuthenticator(null);
      
      server.setCommandFactory(command -> {
      	for (SshCommandCreator creator: commandCreators) {
      		Command sshCommand = creator.createCommand(command);
      		if (sshCommand != null)
      			return sshCommand;
      	}
          return new UnknownCommand(command);
      });

      try {
	server.start();
} catch (IOException e) {
	throw new RuntimeException(e);
}
  }
 
Example #2
Source File: SftpServerRunner.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    sshd.setPort(port);
    sshd.setSubsystemFactories(
            Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
    sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(path)));
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
        @Override
        public boolean authenticate(final String username, final String password, final ServerSession session) {
            return StringUtils.equals(username, ftpUser) && StringUtils.equals(password, ftpPassword);
        }
    });
    try {
        LOGGER.info("Starting SFTP server on port {}", port);
        sshd.start();
    } catch (IOException e) {
        LOGGER.error("Error starting SFTP server", e);
    }
}
 
Example #3
Source File: ESBJAVA3470.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Starts a SFTP server on port 22
 * @param carbonHome
 */
private void setupSftpServer(String carbonHome) {
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setPort(FTP_PORT);
    //sshd.setKeyPairProvider(new FileKeyPairProvider(new String[]{"/home/ravi/WORK/SUPPORT/JIRA/SKYTVNZDEV-26/SftpTest/dist/hostkey.ser"}));
    ClassLoader classLoader = getClass().getClassLoader();
    log.info("Using identity file: " + classLoader.getResource("sftp/id_rsa.pub").getFile());
    File file = new File(classLoader.getResource("sftp/id_rsa.pub").getFile());
    SFTPServer sftpServer = new SFTPServer();
    sshd.setKeyPairProvider(sftpServer.createTestHostKeyProvider(Paths.get(file.getAbsolutePath())));
    sshd.setKeyPairProvider(createTestHostKeyProvider(Paths.get(file.getAbsolutePath())));
    sshd.setUserAuthFactories(
            Arrays.<NamedFactory<UserAuth>>asList(new UserAuthPublicKeyFactory()));
    sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(carbonHome)));
    sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
        public boolean authenticate(String username, PublicKey key, ServerSession session) {
            return "sftpuser".equals(username);
        }
    });

    sshd.setCommandFactory(new ScpCommandFactory());

    sshd.setSubsystemFactories(
            Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));

    try {
        sshd.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #4
Source File: SftpServerRunner.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
SftpServer(int port, String path, String ftpUser, String ftpPassword) {

            sshd.setPort(port);
            sshd.setSubsystemFactories(
                    Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
            sshd.setCommandFactory(new ScpCommandFactory());
            sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
            sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(path)));
            sshd.setPasswordAuthenticator((username, password, session) -> StringUtils.equals(username, ftpUser)
                                                                           && StringUtils.equals(password,
                                                                                                 ftpPassword));
        }
 
Example #5
Source File: SshServerBuilder.java    From java-11-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Set {@link CommandProcessor} for ssh-client library processing.
 * @param commandProcessor implementation of {@link CommandProcessor} dedicated to ssh-client communication.
 * @param sshClientSessionListener provides instances of {@link SshClientSession} for pushing data to ssh-client.
 * @return
 */
public SshServerBuilder withSshClientProcessor(CommandProcessor commandProcessor,
                                               SshClientSessionListener sshClientSessionListener) {
    List<NamedFactory<Command>> namedFactories = new ArrayList<>();
    namedFactories.add(new SshClientNamedCommandFactory(keyMap, commandProcessor,
            sshClientSessionListener, sshClientSessionCounter));
    sshd.setSubsystemFactories(namedFactories);
    return this;
}
 
Example #6
Source File: ShellFactoryImpl.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
@Override
public Command create() {
    LOG.info("create command");
    return new REPLCommand(prompt, keyMap, commandProcessor, sshClientSessionCounter);
}
 
Example #7
Source File: Server.java    From sftpserver with Apache License 2.0 4 votes vote down vote up
@Override
public Command createShell(final ChannelSession channel) throws IOException {
	return new SecureShellCommand();
}
 
Example #8
Source File: EmbeddedSSHServer.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Override
public Command createCommand(String command) {
    return new EchoCommand(command);
}
 
Example #9
Source File: OpenEJBShellFactory.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public Command create() {
    return new OpenEJBCommands(bind, port);
}
 
Example #10
Source File: SshdServerConfiguration.java    From sshd-shell-spring-boot with Apache License 2.0 4 votes vote down vote up
private void configureServerForSshAndFileTransfer(SshServer server) {
    server.setCommandFactory(sshAndScpCommandFactory());
    server.setFileSystemFactory(new SshdNativeFileSystemFactory(properties.getFilesystem().getBase().getDir()));
    server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(
            new SftpSubsystemFactory.Builder().build()));
}
 
Example #11
Source File: SshSessionInstance.java    From sshd-shell-spring-boot with Apache License 2.0 4 votes vote down vote up
@Override
public Command create() {
    return this;
}
 
Example #12
Source File: ShellFactoryImpl.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
@Override
public Command get() {
    LOG.info("get command");
    return new REPLCommand(prompt, keyMap, commandProcessor, sshClientSessionCounter);
}
 
Example #13
Source File: SshClientNamedCommandFactory.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
@Override
public Command create() {
    LOG.info("create ssh-client command processor");
    return new SshClientCommand(keyMap, commandProcessor, sshClientMessageDispatcherRegistration, sshClientSessionCounter);
}
 
Example #14
Source File: CommandFactoryImpl.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
@Override
public Command createCommand(String command) {
    LOG.info("createCommand: {}", command);
    return new SingleCommand(command.getBytes(Charset.forName("UTF-8")), commandProcessor, sshClientSessionCounter);
}
 
Example #15
Source File: DisableShellAccess.java    From onedev with MIT License 4 votes vote down vote up
@Override
public Command create() {
    return new WelcomeMessage();
}
 
Example #16
Source File: SshCommandCreator.java    From onedev with MIT License 4 votes vote down vote up
@Nullable
Command createCommand(String command);
 
Example #17
Source File: SshShellRunnable.java    From ssh-shell-spring-boot with Apache License 2.0 4 votes vote down vote up
@Override
public Command create() {
    return sshShellCommandFactory;
}