Class SshServer
java.lang.Object
- All Implemented Interfaces:
Closeable, AutoCloseable, Channel, AttributeRepository, AttributeStore, UserAuthFactoriesManager<ServerSession, UserAuth, UserAuthFactory>, ChannelListenerManager, ChannelStreamWriterResolver, ChannelStreamWriterResolverManager, Closeable, FactoryManager, PortForwardingEventListenerManager, IoServiceEventListenerManager, KexExtensionHandlerManager, KexFactoryManager, KeyPairProviderHolder, PropertyResolver, ReservedSessionMessagesManager, SessionDisconnectHandlerManager, SessionHeartbeatController, SessionListenerManager, UnknownChannelReferenceHandlerManager, SignatureFactoriesHolder, SignatureFactoriesManager, ServerAuthenticationManager, ServerFactoryManager, ServerProxyAcceptorHolder
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.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractCloseable
AbstractCloseable.StateNested classes/interfaces inherited from interface AttributeRepository
AttributeRepository.AttributeKey<T>Nested classes/interfaces inherited from interface SessionHeartbeatController
SessionHeartbeatController.HeartbeatType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected IoAcceptorprivate CommandFactorystatic final List<ServiceFactory> private GSSAuthenticatorprotected Stringprivate HostBasedAuthenticatorprivate HostKeyCertificateProviderprivate KeyboardInteractiveAuthenticatorprivate KeyPairProviderprivate PasswordAuthenticatorprotected intprivate ServerProxyAcceptorprivate PublickeyAuthenticatorprivate SessionFactoryprivate ShellFactoryprivate final AtomicBooleanprivate List<? extends SubsystemFactory> private List<UserAuthFactory> Fields inherited from class AbstractFactoryManager
agentFactory, channelFactories, channelListenerProxy, channelListeners, executor, fileSystemFactory, forwarderFactory, forwardingFilter, globalRequestHandlers, ioServiceFactory, ioServiceFactoryFactory, randomFactory, serviceFactories, sessionListenerProxy, sessionListeners, sessionTimeoutListener, shutdownExecutor, timeoutListenerFuture, tunnelListenerProxy, tunnelListenersFields inherited from class AbstractCloseable
closeFuture, futureLock, stateFields inherited from class AbstractLoggingBean
logFields inherited from interface ChannelStreamWriterResolver
NONEFields inherited from interface FactoryManager
DEFAULT_VERSIONFields inherited from interface PropertyResolver
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected IoAcceptorprotected SessionFactoryObtain the list of active sessions.Retrieve theCommandFactoryto be used to process commands requests.Retrieve theGSSAuthenticatorto be used by the SSH server.getHost()Retrieve theHostBasedAuthenticatorto be used by the SSH server.protected CloseableRetrieve theKeyboardInteractiveAuthenticatorto be used by the SSH server.Retrieve theKeyPairProviderthat will be used to find the host key to use on the server side or the user key on the client side.Retrieve thePasswordAuthenticatorto be used by the SSH server.intgetPort()Retrieve thePublickeyAuthenticatorto be used by SSH server.Retrieve theShellFactoryobject to be used to create shells.List<? extends SubsystemFactory> Retrieve the list of named factories forCommandFactory.Commandto be used to create subsystems.Retrieve the list of named factories forUserAuthobjects.booleanvoidopen()voidsetCommandFactory(CommandFactory commandFactory) voidsetGSSAuthenticator(GSSAuthenticator gssAuthenticator) voidvoidsetHostBasedAuthenticator(HostBasedAuthenticator hostBasedAuthenticator) voidsetHostKeyCertificateProvider(HostKeyCertificateProvider hostKeyCertificateProvider) voidsetKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator interactiveAuthenticator) voidsetKeyPairProvider(KeyPairProvider keyPairProvider) voidsetPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator) voidsetPort(int port) Configure the port number to use for this SSH server.voidsetPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator) voidsetServerProxyAcceptor(ServerProxyAcceptor proxyAcceptor) voidsetSessionFactory(SessionFactory sessionFactory) voidsetShellFactory(ShellFactory shellFactory) voidsetSubsystemFactories(List<? extends SubsystemFactory> subsystemFactories) static SshServerSetup a default servervoidsetUserAuthFactories(List<UserAuthFactory> userAuthFactories) voidstart()Start the SSH server and accept incoming exceptions on the configured port.voidstop()Stop the SSH server.voidstop(boolean immediately) toString()Methods inherited from class AbstractFactoryManager
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, stopSessionTimeoutListenerMethods inherited from class AbstractKexFactoryManager
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactoriesMethods inherited from class AbstractInnerCloseable
doCloseGracefully, doCloseImmediatelyMethods inherited from class AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListenerMethods inherited from class AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface AttributeRepository
attributeKeys, getAttribute, getAttributesCountMethods inherited from interface AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeMethods inherited from interface ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolverMethods inherited from interface FactoryManager
getAgentFactory, getAgentForwardingFilter, getChannelFactories, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceFactory, getRandomFactory, getScheduledExecutorService, getServiceFactories, getTcpForwardingFilter, getVersion, getX11ForwardingFilter, resolveAttributeMethods inherited from interface IoServiceEventListenerManager
getIoServiceEventListener, setIoServiceEventListenerMethods inherited from interface KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandlerMethods inherited from interface KexFactoryManager
getCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNamesMethods inherited from interface PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListenerMethods inherited from interface PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmptyMethods inherited from interface ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandlerMethods inherited from interface ServerAuthenticationManager
setUserAuthFactoriesNamesMethods inherited from interface SessionDisconnectHandlerManager
getSessionDisconnectHandler, setSessionDisconnectHandlerMethods inherited from interface SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatMethods inherited from interface SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListenerMethods inherited from interface SignatureFactoriesHolder
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNamesMethods inherited from interface SignatureFactoriesManager
setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNamesMethods inherited from interface UnknownChannelReferenceHandlerManager
getUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandlerMethods inherited from interface UserAuthFactoriesManager
getUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNames
-
Field Details
-
DEFAULT_SSH_SERVER_FACTORY
-
DEFAULT_SERVICE_FACTORIES
-
acceptor
-
host
-
port
protected int port -
proxyAcceptor
-
shellFactory
-
sessionFactory
-
commandFactory
-
subsystemFactories
-
userAuthFactories
-
keyPairProvider
-
hostKeyCertificateProvider
-
passwordAuthenticator
-
publickeyAuthenticator
-
interactiveAuthenticator
-
hostBasedAuthenticator
-
gssAuthenticator
-
started
-
-
Constructor Details
-
SshServer
public SshServer()
-
-
Method Details
-
getHost
-
setHost
-
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
-
getBoundAddresses
-
getUserAuthFactories
Description copied from interface:UserAuthFactoriesManagerRetrieve the list of named factories forUserAuthobjects.- Specified by:
getUserAuthFactoriesin interfaceUserAuthFactoriesManager<ServerSession, UserAuth, UserAuthFactory>- Returns:
- a list of named
UserAuthfactories, nevernull/empty
-
setUserAuthFactories
- Specified by:
setUserAuthFactoriesin interfaceUserAuthFactoriesManager<ServerSession, UserAuth, UserAuthFactory>
-
getShellFactory
Description copied from interface:ServerFactoryManagerRetrieve theShellFactoryobject to be used to create shells.- Specified by:
getShellFactoryin interfaceServerFactoryManager- Returns:
- a valid
ShellFactoryobject ornullif shells are not supported on this server
-
setShellFactory
-
getSessionFactory
-
setSessionFactory
-
getServerProxyAcceptor
- Specified by:
getServerProxyAcceptorin interfaceServerProxyAcceptorHolder
-
setServerProxyAcceptor
- Specified by:
setServerProxyAcceptorin interfaceServerProxyAcceptorHolder
-
getCommandFactory
Description copied from interface:ServerFactoryManagerRetrieve theCommandFactoryto be used to process commands requests.- Specified by:
getCommandFactoryin interfaceServerFactoryManager- Returns:
- A valid
CommandFactoryobject ornullif commands are not supported on this server
-
setCommandFactory
-
getSubsystemFactories
Description copied from interface:ServerFactoryManagerRetrieve the list of named factories forCommandFactory.Commandto be used to create subsystems.- Specified by:
getSubsystemFactoriesin interfaceServerFactoryManager- Returns:
- a list of named
SubsystemFactory-ies ornull/empty if subsystems are not supported on this server
-
setSubsystemFactories
-
getPasswordAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve thePasswordAuthenticatorto be used by the SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on passwords will be rejected.- Specified by:
getPasswordAuthenticatorin interfaceServerAuthenticationManager- Returns:
- the
PasswordAuthenticatorornull
-
setPasswordAuthenticator
- Specified by:
setPasswordAuthenticatorin interfaceServerAuthenticationManager
-
getPublickeyAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve thePublickeyAuthenticatorto be used by SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on keys will be rejected.- Specified by:
getPublickeyAuthenticatorin interfaceServerAuthenticationManager- Returns:
- the
PublickeyAuthenticatorornull
-
setPublickeyAuthenticator
- Specified by:
setPublickeyAuthenticatorin interfaceServerAuthenticationManager
-
getKeyboardInteractiveAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve theKeyboardInteractiveAuthenticatorto be used by the SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on this method will be rejected.- Specified by:
getKeyboardInteractiveAuthenticatorin interfaceServerAuthenticationManager- Returns:
- The
KeyboardInteractiveAuthenticatorornull
-
setKeyboardInteractiveAuthenticator
public void setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator interactiveAuthenticator) - Specified by:
setKeyboardInteractiveAuthenticatorin interfaceServerAuthenticationManager
-
getGSSAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve theGSSAuthenticatorto be used by the SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on gssapi will be rejected.- Specified by:
getGSSAuthenticatorin interfaceServerAuthenticationManager- Returns:
- the
GSSAuthenticatorornull
-
setGSSAuthenticator
- Specified by:
setGSSAuthenticatorin interfaceServerAuthenticationManager
-
getHostBasedAuthenticator
Description copied from interface:ServerAuthenticationManagerRetrieve theHostBasedAuthenticatorto be used by the SSH server. If no authenticator has been configured (i.e. this method returnsnull), then client authentication requests based on this method will be rejected.- Specified by:
getHostBasedAuthenticatorin interfaceServerAuthenticationManager- Returns:
- the
HostBasedAuthenticatorornull
-
setHostBasedAuthenticator
- Specified by:
setHostBasedAuthenticatorin interfaceServerAuthenticationManager
-
getKeyPairProvider
Description copied from interface:KeyPairProviderHolderRetrieve theKeyPairProviderthat will be used to find the host key to use on the server side or the user key on the client side.- Specified by:
getKeyPairProviderin interfaceKeyPairProviderHolder- Returns:
- the
KeyPairProvider, nevernull
-
setKeyPairProvider
- Specified by:
setKeyPairProviderin interfaceKeyPairProviderHolder
-
getHostKeyCertificateProvider
- Specified by:
getHostKeyCertificateProviderin interfaceServerAuthenticationManager- Returns:
- a
HostKeyCertificateProviderif available, null as default
-
setHostKeyCertificateProvider
- Specified by:
setHostKeyCertificateProviderin interfaceServerAuthenticationManager
-
checkConfig
protected void checkConfig()- Overrides:
checkConfigin classAbstractFactoryManager
-
isStarted
public boolean isStarted() -
start
Start the SSH server and accept incoming exceptions on the configured port. Ignored if alreadystarted- Throws:
IOException- If failed to start
-
stop
Stop the SSH server. This method will block until all resources are actually disposed.- Throws:
IOException- if stopping failed somehow
-
stop
- Throws:
IOException
-
open
- Throws:
IOException
-
getInnerCloseable
- Specified by:
getInnerCloseablein classAbstractInnerCloseable
-
getActiveSessions
Obtain the list of active sessions.- Returns:
- A
Listof the currently active session
-
createAcceptor
-
createSessionFactory
-
toString
-
setUpDefaultServer
-