public class SshServer extends AbstractFactoryManager implements ServerFactoryManager, Closeable
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.
start() method and stopped using the stop() method.ServerFactoryManager,
FactoryManagerCloseableUtils.AbstractCloseable.State| Modifier and Type | Field and Description |
|---|---|
protected IoAcceptor |
acceptor |
protected CommandFactory |
commandFactory |
static List<ServiceFactory> |
DEFAULT_SERVICE_FACTORIES |
static Factory<SshServer> |
DEFAULT_SSH_SERVER_FACTORY |
static UserAuthGSSFactory |
DEFAULT_USER_AUTH_GSS_FACTORY |
static UserAuthKeyboardInteractiveFactory |
DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY |
static UserAuthPasswordFactory |
DEFAULT_USER_AUTH_PASSWORD_FACTORY |
static UserAuthPublicKeyFactory |
DEFAULT_USER_AUTH_PUBLIC_KEY_FACTORY |
protected GSSAuthenticator |
gssAuthenticator |
protected String |
host |
protected PasswordAuthenticator |
passwordAuthenticator |
protected int |
port |
protected PublickeyAuthenticator |
publickeyAuthenticator |
protected SessionFactory |
sessionFactory |
protected Factory<Command> |
shellFactory |
protected List<NamedFactory<Command>> |
subsystemFactories |
protected List<NamedFactory<UserAuth>> |
userAuthFactories |
agentFactory, channelFactories, cipherFactories, compressionFactories, executor, fileSystemFactory, globalRequestHandlers, ioServiceFactory, ioServiceFactoryFactory, keyExchangeFactories, keyPairProvider, macFactories, properties, randomFactory, serviceFactories, sessionTimeoutListener, shutdownExecutor, signatureFactories, tcpipForwarderFactory, tcpipForwardingFilter, timeoutListenerFuturecloseFuture, lock, statelogAUTH_METHODS, COMMAND_EXIT_TIMEOUT, MAX_AUTH_REQUESTS, MAX_CONCURRENT_SESSIONS, MODULI_URL, REKEY_BYTES_LIMIT, REKEY_TIME_LIMIT, SERVER_IDENTIFICATION, WELCOME_BANNERAUTH_TIMEOUT, CHANNEL_CLOSE_TIMEOUT, DEFAULT_NIO_WORKERS, DEFAULT_VERSION, DISCONNECT_TIMEOUT, IDLE_TIMEOUT, MAX_PACKET_SIZE, NIO_WORKERS, NIO2_READ_BUFFER_SIZE, SOCKET_BACKLOG, SOCKET_KEEPALIVE, SOCKET_LINGER, SOCKET_RCVBUF, SOCKET_REUSEADDR, SOCKET_SNDBUF, TCP_NODELAY, WINDOW_SIZE, WINDOW_TIMEOUT| Constructor and Description |
|---|
SshServer() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkConfig() |
protected IoAcceptor |
createAcceptor() |
protected SessionFactory |
createSessionFactory() |
List<AbstractSession> |
getActiveSessions()
Obtain the list of active sessions.
|
CommandFactory |
getCommandFactory()
Retrieve the
CommandFactory to be used to process commands requests. |
GSSAuthenticator |
getGSSAuthenticator()
Retrieve the
GSSAuthenticator to be used by the SSH server. |
String |
getHost() |
protected Closeable |
getInnerCloseable() |
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. |
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 |
open() |
void |
setCommandFactory(CommandFactory commandFactory) |
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 |
setSessionFactory(SessionFactory sessionFactory) |
void |
setShellFactory(Factory<Command> shellFactory) |
void |
setSubsystemFactories(List<NamedFactory<Command>> subsystemFactories) |
void |
setTcpipForwardingFilter(ForwardingFilter forwardingFilter) |
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) |
String |
toString() |
createSessionTimeoutListener, getAgentFactory, getChannelFactories, getCipherFactories, getCompressionFactories, getFileSystemFactory, getGlobalRequestHandlers, getIoServiceFactory, getIoServiceFactoryFactory, getKeyExchangeFactories, getKeyPairProvider, getMacFactories, getNioWorkers, getProperties, getRandomFactory, getScheduledExecutorService, getServiceFactories, getSignatureFactories, getTcpipForwarderFactory, getTcpipForwardingFilter, getVersion, removeSessionTimeout, setAgentFactory, setChannelFactories, setCipherFactories, setCompressionFactories, setFileSystemFactory, setGlobalRequestHandlers, setIoServiceFactoryFactory, setKeyExchangeFactories, setKeyPairProvider, setMacFactories, setNioWorkers, setProperties, setRandomFactory, setScheduledExecutorService, setScheduledExecutorService, setServiceFactories, setSignatureFactories, setTcpipForwarderFactory, setupSessionTimeout, stopSessionTimeoutListenerdoCloseGracefully, doCloseImmediatelybuilder, close, isClosed, isClosing, preCloseclose, isOpenclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetAgentFactory, getChannelFactories, getCipherFactories, getCompressionFactories, getFileSystemFactory, getGlobalRequestHandlers, getIoServiceFactory, getKeyExchangeFactories, getKeyPairProvider, getMacFactories, getProperties, getRandomFactory, getScheduledExecutorService, getServiceFactories, getSignatureFactories, getTcpipForwarderFactory, getTcpipForwardingFilter, getVersionpublic static final List<ServiceFactory> DEFAULT_SERVICE_FACTORIES
public static final UserAuthPublicKeyFactory DEFAULT_USER_AUTH_PUBLIC_KEY_FACTORY
public static final UserAuthGSSFactory DEFAULT_USER_AUTH_GSS_FACTORY
public static final UserAuthPasswordFactory DEFAULT_USER_AUTH_PASSWORD_FACTORY
public static final UserAuthKeyboardInteractiveFactory DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY
protected IoAcceptor acceptor
protected String host
protected int port
protected List<NamedFactory<UserAuth>> userAuthFactories
protected SessionFactory sessionFactory
protected CommandFactory commandFactory
protected List<NamedFactory<Command>> subsystemFactories
protected PasswordAuthenticator passwordAuthenticator
protected PublickeyAuthenticator publickeyAuthenticator
protected GSSAuthenticator gssAuthenticator
public String getHost()
public void setHost(String host)
public int getPort()
public void setPort(int port)
port - the port number for this SSH serverpublic List<NamedFactory<UserAuth>> getUserAuthFactories()
ServerFactoryManagerUserAuth objects.getUserAuthFactories in interface ServerFactoryManagerUserAuth factories, never nullpublic void setUserAuthFactories(List<NamedFactory<UserAuth>> userAuthFactories)
public Factory<Command> getShellFactory()
ServerFactoryManagerShellFactory object to be used to create shells.getShellFactory in interface ServerFactoryManagerShellFactory object or null if shells
are not supported on this serverpublic SessionFactory getSessionFactory()
public void setSessionFactory(SessionFactory sessionFactory)
public CommandFactory getCommandFactory()
ServerFactoryManagerCommandFactory to be used to process commands requests.getCommandFactory in interface ServerFactoryManagerCommandFactory object or null if commands
are not supported on this serverpublic void setCommandFactory(CommandFactory commandFactory)
public List<NamedFactory<Command>> getSubsystemFactories()
ServerFactoryManagerCommandFactory.Command to
be used to create subsystems.getSubsystemFactories in interface ServerFactoryManagerCommandFactory.Command factories
or null if subsystems are not supported on this serverpublic void setSubsystemFactories(List<NamedFactory<Command>> subsystemFactories)
public PasswordAuthenticator getPasswordAuthenticator()
ServerFactoryManagerPasswordAuthenticator 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.getPasswordAuthenticator in interface ServerFactoryManagerPasswordAuthenticator or nullpublic void setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator)
public PublickeyAuthenticator getPublickeyAuthenticator()
ServerFactoryManagerPublickeyAuthenticator 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.getPublickeyAuthenticator in interface ServerFactoryManagerPublickeyAuthenticato or nullpublic void setPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator)
public GSSAuthenticator getGSSAuthenticator()
ServerFactoryManagerGSSAuthenticator 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.getGSSAuthenticator in interface ServerFactoryManagerGSSAuthenticator or nullpublic void setGSSAuthenticator(GSSAuthenticator gssAuthenticator)
public void setTcpipForwardingFilter(ForwardingFilter forwardingFilter)
setTcpipForwardingFilter in class AbstractFactoryManagerprotected void checkConfig()
checkConfig in class AbstractFactoryManagerpublic void start()
throws IOException
IOException - If failed to startpublic void stop()
throws IOException
IOException - if stopping failed somehowpublic void stop(boolean immediately)
throws IOException
IOExceptionpublic void open()
throws IOException
IOExceptionprotected Closeable getInnerCloseable()
getInnerCloseable in class CloseableUtils.AbstractInnerCloseablepublic List<AbstractSession> getActiveSessions()
List of the currently active sessionprotected IoAcceptor createAcceptor()
protected SessionFactory createSessionFactory()
public static SshServer setUpDefaultServer()
Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.