org.apache.sshd
Class SshServer

java.lang.Object
  extended by org.apache.sshd.common.AbstractFactoryManager
      extended by org.apache.sshd.SshServer
All Implemented Interfaces:
FactoryManager, ServerFactoryManager

public class SshServer
extends AbstractFactoryManager
implements ServerFactoryManager

The SshServer class is the main entry point for the server side of the SSH protocol. The SshServer has to be configured before being started. Such configuration can be done either using a dependency injection mechanism (such as the Spring framework) or programmatically. Basic setup is usually done using the setUpDefaultServer() method, which will known ciphers, macs, channels, etc... Besides this basic setup, a few things have to be manually configured such as the port number, Factory, the KeyPairProvider and the PasswordAuthenticator. Some properties can also be configured using the AbstractFactoryManager.setProperties(java.util.Map) method. Once the SshServer instance has been configured, it can be started using the start() method and stopped using the stop() method.

Author:
Apache MINA SSHD Project
See Also:
ServerFactoryManager, FactoryManager

Field Summary
protected  org.apache.mina.core.service.IoAcceptor acceptor
           
protected  int backlog
           
protected  CommandFactory commandFactory
           
protected  ScheduledExecutorService executor
           
protected  FileSystemFactory fileSystemFactory
           
protected  ForwardingFilter forwardingFilter
           
protected  GSSAuthenticator gssAuthenticator
           
protected  String host
           
protected  PasswordAuthenticator passwordAuthenticator
           
protected  int port
           
protected  PublickeyAuthenticator publickeyAuthenticator
           
protected  boolean reuseAddress
           
protected  org.apache.mina.core.session.IoSessionConfig sessionConfig
           
protected  SessionFactory sessionFactory
           
protected  Factory<Command> shellFactory
           
protected  boolean shutdownExecutor
           
protected  List<NamedFactory<Command>> subsystemFactories
           
protected  List<NamedFactory<UserAuth>> userAuthFactories
           
 
Fields inherited from class org.apache.sshd.common.AbstractFactoryManager
channelFactories, cipherFactories, compressionFactories, keyExchangeFactories, keyPairProvider, macFactories, properties, randomFactory, signatureFactories, version
 
Fields inherited from interface org.apache.sshd.server.ServerFactoryManager
AUTH_TIMEOUT, IDLE_TIMEOUT, MAX_AUTH_REQUESTS, MAX_CONCURRENT_SESSIONS, SERVER_IDENTIFICATION
 
Fields inherited from interface org.apache.sshd.common.FactoryManager
DEFAULT_NIO_WORKERS, MAX_PACKET_SIZE, NIO_WORKERS, WINDOW_SIZE
 
Constructor Summary
SshServer()
           
 
Method Summary
protected  void checkConfig()
           
protected  void configure(org.apache.mina.core.service.IoAcceptor acceptor)
           
protected  org.apache.mina.core.service.IoAcceptor createAcceptor()
           
protected  SessionFactory createSessionFactory()
           
 int getBacklog()
           
 CommandFactory getCommandFactory()
          Retrieve the CommandFactory to be used to process commands requests.
 FileSystemFactory getFileSystemFactory()
          Retrieve the FileSystemFactory to be used to traverse the file system.
 ForwardingFilter getForwardingFilter()
          Retrieve the ForwardingFilter to be used by the SSH server.
 GSSAuthenticator getGSSAuthenticator()
          Retrieve the GSSAuthenticator to be used by the SSH server.
 String getHost()
           
 PasswordAuthenticator getPasswordAuthenticator()
          Retrieve the PasswordAuthenticator to be used by the SSH server.
 int getPort()
           
 PublickeyAuthenticator getPublickeyAuthenticator()
          Retrieve the PublickeyAuthenticator to be used by SSH server.
 boolean getReuseAddress()
           
 ScheduledExecutorService getScheduledExecutorService()
          Retrieve the ScheduledExecutorService to be used.
 org.apache.mina.core.session.IoSessionConfig getSessionConfig()
           
 SessionFactory getSessionFactory()
           
 Factory<Command> getShellFactory()
          Retrieve the ShellFactory object to be used to create shells.
 List<NamedFactory<Command>> getSubsystemFactories()
          Retrieve the list of named factories for CommandFactory.Command to be used to create subsystems.
 List<NamedFactory<UserAuth>> getUserAuthFactories()
          Retrieve the list of named factories for UserAuth objects.
static void main(String[] args)
           
 void setBacklog(int backlog)
           
 void setCommandFactory(CommandFactory commandFactory)
           
 void setFileSystemFactory(FileSystemFactory fileSystemFactory)
           
 void setForwardingFilter(ForwardingFilter forwardingFilter)
           
 void setGSSAuthenticator(GSSAuthenticator gssAuthenticator)
           
 void setHost(String host)
           
 void setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator)
           
 void setPort(int port)
          Configure the port number to use for this SSH server.
 void setPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator)
           
 void setReuseAddress(boolean reuseAddress)
           
 void setScheduledExecutorService(ScheduledExecutorService executor)
           
 void setScheduledExecutorService(ScheduledExecutorService executor, boolean shutdownExecutor)
           
 void setSessionConfig(org.apache.mina.core.session.IoSessionConfig sessionConfig)
           
 void setSessionFactory(SessionFactory sessionFactory)
           
 void setShellFactory(Factory<Command> shellFactory)
           
 void setSubsystemFactories(List<NamedFactory<Command>> subsystemFactories)
           
static SshServer setUpDefaultServer()
           
 void setUserAuthFactories(List<NamedFactory<UserAuth>> userAuthFactories)
           
 void start()
          Start the SSH server and accept incoming exceptions on the configured port.
 void stop()
          Stop the SSH server.
 void stop(boolean immediately)
           
 
Methods inherited from class org.apache.sshd.common.AbstractFactoryManager
getChannelFactories, getCipherFactories, getCompressionFactories, getKeyExchangeFactories, getKeyPairProvider, getMacFactories, getNioWorkers, getProperties, getRandomFactory, getSignatureFactories, getVersion, loadVersion, setChannelFactories, setCipherFactories, setCompressionFactories, setKeyExchangeFactories, setKeyPairProvider, setMacFactories, setNioWorkers, setProperties, setRandomFactory, setSignatureFactories
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.sshd.common.FactoryManager
getChannelFactories, getCipherFactories, getCompressionFactories, getKeyExchangeFactories, getKeyPairProvider, getMacFactories, getProperties, getRandomFactory, getSignatureFactories, getVersion
 

Field Detail

acceptor

protected org.apache.mina.core.service.IoAcceptor acceptor

host

protected String host

port

protected int port

backlog

protected int backlog

reuseAddress

protected boolean reuseAddress

sessionConfig

protected org.apache.mina.core.session.IoSessionConfig sessionConfig

userAuthFactories

protected List<NamedFactory<UserAuth>> userAuthFactories

shellFactory

protected Factory<Command> shellFactory

sessionFactory

protected SessionFactory sessionFactory

commandFactory

protected CommandFactory commandFactory

fileSystemFactory

protected FileSystemFactory fileSystemFactory

subsystemFactories

protected List<NamedFactory<Command>> subsystemFactories

passwordAuthenticator

protected PasswordAuthenticator passwordAuthenticator

publickeyAuthenticator

protected PublickeyAuthenticator publickeyAuthenticator

gssAuthenticator

protected GSSAuthenticator gssAuthenticator

forwardingFilter

protected ForwardingFilter forwardingFilter

executor

protected ScheduledExecutorService executor

shutdownExecutor

protected boolean shutdownExecutor
Constructor Detail

SshServer

public SshServer()
Method Detail

getHost

public String getHost()

setHost

public void setHost(String host)

getPort

public int getPort()

setPort

public void setPort(int port)
Configure the port number to use for this SSH server.

Parameters:
port - the port number for this SSH server

getReuseAddress

public boolean getReuseAddress()

setReuseAddress

public void setReuseAddress(boolean reuseAddress)

getBacklog

public int getBacklog()

setBacklog

public void setBacklog(int backlog)

getSessionConfig

public org.apache.mina.core.session.IoSessionConfig getSessionConfig()

setSessionConfig

public void setSessionConfig(org.apache.mina.core.session.IoSessionConfig sessionConfig)

getUserAuthFactories

public List<NamedFactory<UserAuth>> getUserAuthFactories()
Description copied from interface: ServerFactoryManager
Retrieve the list of named factories for UserAuth objects.

Specified by:
getUserAuthFactories in interface ServerFactoryManager
Returns:
a list of named UserAuth factories, never null

setUserAuthFactories

public void setUserAuthFactories(List<NamedFactory<UserAuth>> userAuthFactories)

getShellFactory

public Factory<Command> getShellFactory()
Description copied from interface: ServerFactoryManager
Retrieve the ShellFactory object to be used to create shells.

Specified by:
getShellFactory in interface ServerFactoryManager
Returns:
a valid ShellFactory object or null if shells are not supported on this server

setShellFactory

public void setShellFactory(Factory<Command> shellFactory)

getSessionFactory

public SessionFactory getSessionFactory()

setSessionFactory

public void setSessionFactory(SessionFactory sessionFactory)

getCommandFactory

public CommandFactory getCommandFactory()
Description copied from interface: ServerFactoryManager
Retrieve the CommandFactory to be used to process commands requests.

Specified by:
getCommandFactory in interface ServerFactoryManager
Returns:
a valid CommandFactory object or null if commands are not supported on this server

setCommandFactory

public void setCommandFactory(CommandFactory commandFactory)

getFileSystemFactory

public FileSystemFactory getFileSystemFactory()
Description copied from interface: ServerFactoryManager
Retrieve the FileSystemFactory to be used to traverse the file system.

Specified by:
getFileSystemFactory in interface ServerFactoryManager
Returns:
a valid FileSystemFactory object or null if commands are not supported on this server

setFileSystemFactory

public void setFileSystemFactory(FileSystemFactory fileSystemFactory)

getSubsystemFactories

public List<NamedFactory<Command>> getSubsystemFactories()
Description copied from interface: ServerFactoryManager
Retrieve the list of named factories for CommandFactory.Command to be used to create subsystems.

Specified by:
getSubsystemFactories in interface ServerFactoryManager
Returns:
a list of named CommandFactory.Command factories or null if subsystems are not supported on this server

setSubsystemFactories

public void setSubsystemFactories(List<NamedFactory<Command>> subsystemFactories)

getPasswordAuthenticator

public PasswordAuthenticator getPasswordAuthenticator()
Description copied from interface: ServerFactoryManager
Retrieve the PasswordAuthenticator to be used by the SSH server. If no authenticator has been configured (i.e. this method returns null), then client authentication requests based on passwords will be rejected.

Specified by:
getPasswordAuthenticator in interface ServerFactoryManager
Returns:
the PasswordAuthenticator or null

setPasswordAuthenticator

public void setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator)

getPublickeyAuthenticator

public PublickeyAuthenticator getPublickeyAuthenticator()
Description copied from interface: ServerFactoryManager
Retrieve the PublickeyAuthenticator to be used by SSH server. If no authenticator has been configured (i.e. this method returns null), then client authentication requests based on keys will be rejected.

Specified by:
getPublickeyAuthenticator in interface ServerFactoryManager
Returns:
the PublickeyAuthenticato or null

setPublickeyAuthenticator

public void setPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator)

getGSSAuthenticator

public GSSAuthenticator getGSSAuthenticator()
Description copied from interface: ServerFactoryManager
Retrieve the GSSAuthenticator to be used by the SSH server. If no authenticator has been configured (i.e. this method returns null), then client authentication requests based on gssapi will be rejected.

Specified by:
getGSSAuthenticator in interface ServerFactoryManager
Returns:
the GSSAuthenticator or null

setGSSAuthenticator

public void setGSSAuthenticator(GSSAuthenticator gssAuthenticator)

getForwardingFilter

public ForwardingFilter getForwardingFilter()
Description copied from interface: ServerFactoryManager
Retrieve the ForwardingFilter to be used by the SSH server. If no filter has been configured (i.e. this method returns null), then all forwarding requests will be rejected.

Specified by:
getForwardingFilter in interface ServerFactoryManager
Returns:
the ForwardingFilter or null

setForwardingFilter

public void setForwardingFilter(ForwardingFilter forwardingFilter)

getScheduledExecutorService

public ScheduledExecutorService getScheduledExecutorService()
Description copied from interface: ServerFactoryManager
Retrieve the ScheduledExecutorService to be used.

Specified by:
getScheduledExecutorService in interface ServerFactoryManager
Returns:
the ScheduledExecutorService, never null

setScheduledExecutorService

public void setScheduledExecutorService(ScheduledExecutorService executor)

setScheduledExecutorService

public void setScheduledExecutorService(ScheduledExecutorService executor,
                                        boolean shutdownExecutor)

checkConfig

protected void checkConfig()

start

public void start()
           throws IOException
Start the SSH server and accept incoming exceptions on the configured port.

Throws:
IOException

stop

public void stop()
          throws InterruptedException
Stop the SSH server. This method will block until all resources are actually disposed.

Throws:
InterruptedException

stop

public void stop(boolean immediately)
          throws InterruptedException
Throws:
InterruptedException

createAcceptor

protected org.apache.mina.core.service.IoAcceptor createAcceptor()

configure

protected void configure(org.apache.mina.core.service.IoAcceptor acceptor)

createSessionFactory

protected SessionFactory createSessionFactory()

setUpDefaultServer

public static SshServer setUpDefaultServer()

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception


Copyright © 2008-2012 Apache Software Foundation. All Rights Reserved.