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

The following examples show how to use org.apache.sshd.server.command.Command. These examples are extracted from open source projects. 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 Project: onedev   Author: theonedev   File: SshServerLauncher.java    License: 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 Project: product-ei   Author: wso2   File: SftpServerRunner.java    License: 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 Project: micro-integrator   Author: wso2   File: SftpServerRunner.java    License: 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 #4
Source Project: java-11-examples   Author: jveverka   File: SshServerBuilder.java    License: 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 #5
Source Project: product-ei   Author: wso2   File: ESBJAVA3470.java    License: 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 #6
Source Project: ssh-shell-spring-boot   Author: fonimus   File: SshShellRunnable.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Command create() {
    return sshShellCommandFactory;
}
 
Example #7
Source Project: onedev   Author: theonedev   File: SshCommandCreator.java    License: MIT License 4 votes vote down vote up
@Nullable
Command createCommand(String command);
 
Example #8
Source Project: onedev   Author: theonedev   File: DisableShellAccess.java    License: MIT License 4 votes vote down vote up
@Override
public Command create() {
    return new WelcomeMessage();
}
 
Example #9
Source Project: java-11-examples   Author: jveverka   File: CommandFactoryImpl.java    License: 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 #10
Source Project: java-11-examples   Author: jveverka   File: SshClientNamedCommandFactory.java    License: 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 #11
Source Project: java-11-examples   Author: jveverka   File: ShellFactoryImpl.java    License: 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 #12
Source Project: java-11-examples   Author: jveverka   File: ShellFactoryImpl.java    License: 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 #13
Source Project: sshd-shell-spring-boot   Author: anand1st   File: SshSessionInstance.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Command create() {
    return this;
}
 
Example #14
Source Project: sshd-shell-spring-boot   Author: anand1st   File: SshdServerConfiguration.java    License: 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 #15
Source Project: tomee   Author: apache   File: OpenEJBShellFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Command create() {
    return new OpenEJBCommands(bind, port);
}
 
Example #16
Source Project: wildfly-camel   Author: wildfly-extras   File: EmbeddedSSHServer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Command createCommand(String command) {
    return new EchoCommand(command);
}
 
Example #17
Source Project: sftpserver   Author: ggrandes   File: Server.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Command createShell(final ChannelSession channel) throws IOException {
	return new SecureShellCommand();
}