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 PropertyResolverUtils updateProperty methods.
start() method and stopped
using the stop() method.ServerFactoryManager,
FactoryManagerAbstractCloseable.StateAttributeRepository.AttributeKey<T>SessionHeartbeatController.HeartbeatType| Modifier and Type | Field and Description |
|---|---|
protected IoAcceptor |
acceptor |
static List<ServiceFactory> |
DEFAULT_SERVICE_FACTORIES |
static Factory<SshServer> |
DEFAULT_SSH_SERVER_FACTORY |
protected String |
host |
protected int |
port |
agentFactory, channelFactories, channelListenerProxy, channelListeners, executor, fileSystemFactory, forwarderFactory, forwardingFilter, globalRequestHandlers, ioServiceFactory, ioServiceFactoryFactory, randomFactory, serviceFactories, sessionListenerProxy, sessionListeners, sessionTimeoutListener, shutdownExecutor, timeoutListenerFuture, tunnelListenerProxy, tunnelListenerscloseFuture, futureLock, statelogDEFAULT_VERSIONNONEEMPTYDEFAULT_USER_AUTH_GSS_FACTORY, DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY, DEFAULT_USER_AUTH_PASSWORD_FACTORY, DEFAULT_USER_AUTH_PUBLIC_KEY_FACTORY| 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.
|
Set<SocketAddress> |
getBoundAddresses() |
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() |
HostBasedAuthenticator |
getHostBasedAuthenticator()
Retrieve the
HostBasedAuthenticator to be used by the SSH server. |
HostKeyCertificateProvider |
getHostKeyCertificateProvider() |
protected Closeable |
getInnerCloseable() |
KeyboardInteractiveAuthenticator |
getKeyboardInteractiveAuthenticator()
Retrieve the
KeyboardInteractiveAuthenticator to be used by the SSH server. |
KeyPairProvider |
getKeyPairProvider() |
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. |
ServerProxyAcceptor |
getServerProxyAcceptor() |
SessionFactory |
getSessionFactory() |
ShellFactory |
getShellFactory()
Retrieve the
ShellFactory object to be used to create shells. |
List<? extends SubsystemFactory> |
getSubsystemFactories()
Retrieve the list of named factories for
CommandFactory.Command to be used to create subsystems. |
List<UserAuthFactory> |
getUserAuthFactories() |
boolean |
isStarted() |
void |
open() |
void |
setCommandFactory(CommandFactory commandFactory) |
void |
setGSSAuthenticator(GSSAuthenticator gssAuthenticator) |
void |
setHost(String host) |
void |
setHostBasedAuthenticator(HostBasedAuthenticator hostBasedAuthenticator) |
void |
setHostKeyCertificateProvider(HostKeyCertificateProvider hostKeyCertificateProvider) |
void |
setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator interactiveAuthenticator) |
void |
setKeyPairProvider(KeyPairProvider keyPairProvider) |
void |
setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator) |
void |
setPort(int port)
Configure the port number to use for this SSH server.
|
void |
setPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator) |
void |
setServerProxyAcceptor(ServerProxyAcceptor proxyAcceptor) |
void |
setSessionFactory(SessionFactory sessionFactory) |
void |
setShellFactory(ShellFactory shellFactory) |
void |
setSubsystemFactories(List<? extends SubsystemFactory> subsystemFactories) |
static SshServer |
setUpDefaultServer()
Setup a default server
|
void |
setUserAuthFactories(List<UserAuthFactory> 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() |
addChannelListener, addPortForwardingEventListener, addSessionListener, attributeKeys, clearAttributes, computeAttributeIfAbsent, createSessionTimeoutListener, getAgentFactory, getAttribute, getAttributesCount, getChannelFactories, getChannelListenerProxy, getChannelStreamWriterResolver, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceEventListener, getIoServiceFactory, getIoServiceFactoryFactory, getNioWorkers, getParentPropertyResolver, getPortForwardingEventListenerProxy, getProperties, getRandomFactory, getReservedSessionMessagesHandler, getScheduledExecutorService, getServiceFactories, getSessionDisconnectHandler, getSessionListenerProxy, getUnknownChannelReferenceHandler, getVersion, removeAttribute, removeChannelListener, removePortForwardingEventListener, removeSessionListener, removeSessionTimeout, resolveUnknownChannelReferenceHandler, setAgentFactory, setAttribute, setChannelFactories, setChannelStreamWriterResolver, setFileSystemFactory, setForwarderFactory, setForwardingFilter, setGlobalRequestHandlers, setIoServiceEventListener, setIoServiceFactoryFactory, setNioWorkers, setParentPropertyResolver, setRandomFactory, setReservedSessionMessagesHandler, setScheduledExecutorService, setScheduledExecutorService, setServiceFactories, setSessionDisconnectHandler, setUnknownChannelReferenceHandler, setupSessionTimeout, stopSessionTimeoutListenergetCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactoriesdoCloseGracefully, doCloseImmediatelyaddCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListenerdebug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetAgentFactory, getAgentForwardingFilter, getChannelFactories, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceFactory, getRandomFactory, getScheduledExecutorService, getServiceFactories, getTcpForwardingFilter, getVersion, getX11ForwardingFilter, resolveAttribute, resolveAttributegetCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNamesgetSignatureFactories, resolveSignatureFactories, setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNamesgetSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNamesgetKexExtensionHandler, setKexExtensionHandleraddSessionListener, getSessionListenerProxy, removeSessionListenergetReservedSessionMessagesHandler, setReservedSessionMessagesHandlergetSessionDisconnectHandler, setSessionDisconnectHandleraddChannelListener, getChannelListenerProxy, removeChannelListenergetChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolvergetUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandleraddPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListenergetIoServiceEventListener, setIoServiceEventListenerclearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeattributeKeys, getAttribute, getAttributesCount, ofAttributesMap, ofKeyValuePairdisableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatgetBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmpty, isEmptyresolveUserAuthFactories, resolveUserAuthFactories, setUserAuthFactoriesNamesgetUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNamesaddCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListenerpublic static final List<ServiceFactory> DEFAULT_SERVICE_FACTORIES
protected IoAcceptor acceptor
protected String host
protected int port
public String getHost()
public void setHost(String host)
public int getPort()
public void setPort(int port)
port - the port number for this SSH serverpublic Set<SocketAddress> getBoundAddresses()
public List<UserAuthFactory> getUserAuthFactories()
getUserAuthFactories in interface UserAuthFactoriesManager<ServerSession,UserAuth,UserAuthFactory>public void setUserAuthFactories(List<UserAuthFactory> userAuthFactories)
setUserAuthFactories in interface UserAuthFactoriesManager<ServerSession,UserAuth,UserAuthFactory>public ShellFactory getShellFactory()
ServerFactoryManagerShellFactory object to be used to create shells.getShellFactory in interface ServerFactoryManagerShellFactory object or null if shells are not supported on this serverpublic void setShellFactory(ShellFactory shellFactory)
public SessionFactory getSessionFactory()
public void setSessionFactory(SessionFactory sessionFactory)
public ServerProxyAcceptor getServerProxyAcceptor()
getServerProxyAcceptor in interface ServerProxyAcceptorHolderpublic void setServerProxyAcceptor(ServerProxyAcceptor proxyAcceptor)
setServerProxyAcceptor in interface ServerProxyAcceptorHolderpublic 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<? extends SubsystemFactory> getSubsystemFactories()
ServerFactoryManagerCommandFactory.Command to be used to create subsystems.getSubsystemFactories in interface ServerFactoryManagerSubsystemFactory-ies or null/empty if subsystems are not supported on
this serverpublic void setSubsystemFactories(List<? extends SubsystemFactory> subsystemFactories)
public PasswordAuthenticator getPasswordAuthenticator()
ServerAuthenticationManagerPasswordAuthenticator 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 ServerAuthenticationManagerPasswordAuthenticator or nullpublic void setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator)
setPasswordAuthenticator in interface ServerAuthenticationManagerpublic PublickeyAuthenticator getPublickeyAuthenticator()
ServerAuthenticationManagerPublickeyAuthenticator 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 ServerAuthenticationManagerPublickeyAuthenticator or nullpublic void setPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator)
setPublickeyAuthenticator in interface ServerAuthenticationManagerpublic KeyboardInteractiveAuthenticator getKeyboardInteractiveAuthenticator()
ServerAuthenticationManagerKeyboardInteractiveAuthenticator 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 this method
will be rejected.getKeyboardInteractiveAuthenticator in interface ServerAuthenticationManagerKeyboardInteractiveAuthenticator or nullpublic void setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator interactiveAuthenticator)
setKeyboardInteractiveAuthenticator in interface ServerAuthenticationManagerpublic GSSAuthenticator getGSSAuthenticator()
ServerAuthenticationManagerGSSAuthenticator 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 ServerAuthenticationManagerGSSAuthenticator or nullpublic void setGSSAuthenticator(GSSAuthenticator gssAuthenticator)
setGSSAuthenticator in interface ServerAuthenticationManagerpublic HostBasedAuthenticator getHostBasedAuthenticator()
ServerAuthenticationManagerHostBasedAuthenticator 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 this method will be
rejected.getHostBasedAuthenticator in interface ServerAuthenticationManagerHostBasedAuthenticator or nullpublic void setHostBasedAuthenticator(HostBasedAuthenticator hostBasedAuthenticator)
setHostBasedAuthenticator in interface ServerAuthenticationManagerpublic KeyPairProvider getKeyPairProvider()
getKeyPairProvider in interface KeyPairProviderHolderpublic void setKeyPairProvider(KeyPairProvider keyPairProvider)
setKeyPairProvider in interface KeyPairProviderHolderpublic HostKeyCertificateProvider getHostKeyCertificateProvider()
getHostKeyCertificateProvider in interface ServerAuthenticationManagerHostKeyCertificateProvider if available, null as defaultpublic void setHostKeyCertificateProvider(HostKeyCertificateProvider hostKeyCertificateProvider)
setHostKeyCertificateProvider in interface ServerAuthenticationManagerprotected void checkConfig()
checkConfig in class AbstractFactoryManagerpublic boolean isStarted()
public void start()
throws IOException
startedIOException - 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 AbstractInnerCloseablepublic List<AbstractSession> getActiveSessions()
List of the currently active sessionprotected IoAcceptor createAcceptor()
protected SessionFactory createSessionFactory()
Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.