Package org.apache.sshd.server
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.- Author:
- Apache MINA SSHD Project
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State
Nested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T extends Object>
Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
SessionHeartbeatController.HeartbeatType
-
Field Summary
Modifier and TypeFieldDescriptionprotected IoAcceptor
static final List<ServiceFactory>
protected String
protected int
Fields inherited from class org.apache.sshd.common.helpers.AbstractFactoryManager
agentFactory, channelFactories, channelListenerProxy, channelListeners, executor, fileSystemFactory, forwarderFactory, forwardingFilter, globalRequestHandlers, ioServiceFactory, ioServiceFactoryFactory, randomFactory, serviceFactories, sessionListenerProxy, sessionListeners, sessionTimeoutListener, shutdownExecutor, timeoutListenerFuture, tunnelListenerProxy, tunnelListeners
Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, state
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
Fields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONE
Fields inherited from interface org.apache.sshd.common.FactoryManager
DEFAULT_VERSION
Fields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY
Fields inherited from interface org.apache.sshd.server.ServerAuthenticationManager
DEFAULT_USER_AUTH_GSS_FACTORY, DEFAULT_USER_AUTH_KB_INTERACTIVE_FACTORY, DEFAULT_USER_AUTH_PASSWORD_FACTORY, DEFAULT_USER_AUTH_PUBLIC_KEY_FACTORY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected IoAcceptor
protected SessionFactory
Obtain the list of active sessions.Retrieve theCommandFactory
to be used to process commands requests.Retrieve theGSSAuthenticator
to be used by the SSH server.getHost()
Retrieve theHostBasedAuthenticator
to be used by the SSH server.protected Closeable
Retrieve theKeyboardInteractiveAuthenticator
to be used by the SSH server.Retrieve thePasswordAuthenticator
to be used by the SSH server.int
getPort()
Retrieve thePublickeyAuthenticator
to be used by SSH server.Retrieve theShellFactory
object to be used to create shells.List<? extends SubsystemFactory>
Retrieve the list of named factories forCommandFactory.Command
to be used to create subsystems.boolean
void
open()
void
setCommandFactory
(CommandFactory commandFactory) void
setGSSAuthenticator
(GSSAuthenticator gssAuthenticator) void
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
Setup a default servervoid
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) toString()
Methods inherited from class org.apache.sshd.common.helpers.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, stopSessionTimeoutListener
Methods inherited from class org.apache.sshd.common.kex.AbstractKexFactoryManager
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactories
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediately
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListener
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCount
Methods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttribute
Methods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListener
Methods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolver
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
Methods inherited from interface org.apache.sshd.common.FactoryManager
getAgentFactory, getAgentForwardingFilter, getChannelFactories, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceFactory, getRandomFactory, getScheduledExecutorService, getServiceFactories, getTcpForwardingFilter, getVersion, getX11ForwardingFilter, resolveAttribute
Methods inherited from interface org.apache.sshd.common.io.IoServiceEventListenerManager
getIoServiceEventListener, setIoServiceEventListener
Methods inherited from interface org.apache.sshd.common.kex.extension.KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandler
Methods inherited from interface org.apache.sshd.common.kex.KexFactoryManager
getCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNames
Methods inherited from interface org.apache.sshd.common.forward.PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListener
Methods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmpty
Methods inherited from interface org.apache.sshd.common.session.ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandler
Methods inherited from interface org.apache.sshd.server.ServerAuthenticationManager
setUserAuthFactoriesNames
Methods inherited from interface org.apache.sshd.common.session.SessionDisconnectHandlerManager
getSessionDisconnectHandler, setSessionDisconnectHandler
Methods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeat
Methods inherited from interface org.apache.sshd.common.session.SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListener
Methods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesHolder
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNames
Methods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesManager
setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNames
Methods inherited from interface org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager
getUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandler
Methods inherited from interface org.apache.sshd.common.auth.UserAuthFactoriesManager
getUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNames
-
Field Details
-
DEFAULT_SSH_SERVER_FACTORY
-
DEFAULT_SERVICE_FACTORIES
-
acceptor
-
host
-
port
protected int port
-
-
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
- Specified by:
getUserAuthFactories
in interfaceUserAuthFactoriesManager<ServerSession,
UserAuth, UserAuthFactory>
-
setUserAuthFactories
- Specified by:
setUserAuthFactories
in interfaceUserAuthFactoriesManager<ServerSession,
UserAuth, UserAuthFactory>
-
getShellFactory
Description copied from interface:ServerFactoryManager
Retrieve theShellFactory
object to be used to create shells.- Specified by:
getShellFactory
in interfaceServerFactoryManager
- Returns:
- a valid
ShellFactory
object ornull
if shells are not supported on this server
-
setShellFactory
-
getSessionFactory
-
setSessionFactory
-
getServerProxyAcceptor
- Specified by:
getServerProxyAcceptor
in interfaceServerProxyAcceptorHolder
-
setServerProxyAcceptor
- Specified by:
setServerProxyAcceptor
in interfaceServerProxyAcceptorHolder
-
getCommandFactory
Description copied from interface:ServerFactoryManager
Retrieve theCommandFactory
to be used to process commands requests.- Specified by:
getCommandFactory
in interfaceServerFactoryManager
- Returns:
- A valid
CommandFactory
object ornull
if commands are not supported on this server
-
setCommandFactory
-
getSubsystemFactories
Description copied from interface:ServerFactoryManager
Retrieve the list of named factories forCommandFactory.Command
to be used to create subsystems.- Specified by:
getSubsystemFactories
in interfaceServerFactoryManager
- Returns:
- a list of named
SubsystemFactory
-ies ornull
/empty if subsystems are not supported on this server
-
setSubsystemFactories
-
getPasswordAuthenticator
Description copied from interface:ServerAuthenticationManager
Retrieve thePasswordAuthenticator
to 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:
getPasswordAuthenticator
in interfaceServerAuthenticationManager
- Returns:
- the
PasswordAuthenticator
ornull
-
setPasswordAuthenticator
- Specified by:
setPasswordAuthenticator
in interfaceServerAuthenticationManager
-
getPublickeyAuthenticator
Description copied from interface:ServerAuthenticationManager
Retrieve thePublickeyAuthenticator
to 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:
getPublickeyAuthenticator
in interfaceServerAuthenticationManager
- Returns:
- the
PublickeyAuthenticator
ornull
-
setPublickeyAuthenticator
- Specified by:
setPublickeyAuthenticator
in interfaceServerAuthenticationManager
-
getKeyboardInteractiveAuthenticator
Description copied from interface:ServerAuthenticationManager
Retrieve theKeyboardInteractiveAuthenticator
to 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:
getKeyboardInteractiveAuthenticator
in interfaceServerAuthenticationManager
- Returns:
- The
KeyboardInteractiveAuthenticator
ornull
-
setKeyboardInteractiveAuthenticator
public void setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator interactiveAuthenticator) - Specified by:
setKeyboardInteractiveAuthenticator
in interfaceServerAuthenticationManager
-
getGSSAuthenticator
Description copied from interface:ServerAuthenticationManager
Retrieve theGSSAuthenticator
to 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:
getGSSAuthenticator
in interfaceServerAuthenticationManager
- Returns:
- the
GSSAuthenticator
ornull
-
setGSSAuthenticator
- Specified by:
setGSSAuthenticator
in interfaceServerAuthenticationManager
-
getHostBasedAuthenticator
Description copied from interface:ServerAuthenticationManager
Retrieve theHostBasedAuthenticator
to 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:
getHostBasedAuthenticator
in interfaceServerAuthenticationManager
- Returns:
- the
HostBasedAuthenticator
ornull
-
setHostBasedAuthenticator
- Specified by:
setHostBasedAuthenticator
in interfaceServerAuthenticationManager
-
getKeyPairProvider
- Specified by:
getKeyPairProvider
in interfaceKeyPairProviderHolder
-
setKeyPairProvider
- Specified by:
setKeyPairProvider
in interfaceKeyPairProviderHolder
-
getHostKeyCertificateProvider
- Specified by:
getHostKeyCertificateProvider
in interfaceServerAuthenticationManager
- Returns:
- a
HostKeyCertificateProvider
if available, null as default
-
setHostKeyCertificateProvider
- Specified by:
setHostKeyCertificateProvider
in interfaceServerAuthenticationManager
-
checkConfig
protected void checkConfig()- Overrides:
checkConfig
in 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:
getInnerCloseable
in classAbstractInnerCloseable
-
getActiveSessions
Obtain the list of active sessions.- Returns:
- A
List
of the currently active session
-
createAcceptor
-
createSessionFactory
-
toString
-
setUpDefaultServer
Setup a default server- Returns:
- a newly create
SshServer
with default configurations
-