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
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, theKeyPairProviderand thePasswordAuthenticator.Some properties can also be configured using the
Once the SshServer instance has been configured, it can be started using thePropertyResolverUtilsupdatePropertymethods.start()method and stopped using thestop()method.- Author:
- Apache MINA SSHD Project
- See Also:
ServerFactoryManager,FactoryManager
-
-
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
Fields Modifier and Type Field Description protected IoAcceptoracceptorstatic List<ServiceFactory>DEFAULT_SERVICE_FACTORIESstatic Factory<SshServer>DEFAULT_SSH_SERVER_FACTORYprotected Stringhostprotected intport-
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
Constructors Constructor Description SshServer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckConfig()protected IoAcceptorcreateAcceptor()protected SessionFactorycreateSessionFactory()List<AbstractSession>getActiveSessions()Obtain the list of active sessions.Set<SocketAddress>getBoundAddresses()CommandFactorygetCommandFactory()Retrieve theCommandFactoryto be used to process commands requests.GSSAuthenticatorgetGSSAuthenticator()Retrieve theGSSAuthenticatorto be used by the SSH server.StringgetHost()HostBasedAuthenticatorgetHostBasedAuthenticator()Retrieve theHostBasedAuthenticatorto be used by the SSH server.HostKeyCertificateProvidergetHostKeyCertificateProvider()protected CloseablegetInnerCloseable()KeyboardInteractiveAuthenticatorgetKeyboardInteractiveAuthenticator()Retrieve theKeyboardInteractiveAuthenticatorto be used by the SSH server.KeyPairProvidergetKeyPairProvider()PasswordAuthenticatorgetPasswordAuthenticator()Retrieve thePasswordAuthenticatorto be used by the SSH server.intgetPort()PublickeyAuthenticatorgetPublickeyAuthenticator()Retrieve thePublickeyAuthenticatorto be used by SSH server.ServerProxyAcceptorgetServerProxyAcceptor()SessionFactorygetSessionFactory()ShellFactorygetShellFactory()Retrieve theShellFactoryobject to be used to create shells.List<? extends SubsystemFactory>getSubsystemFactories()Retrieve the list of named factories forCommandFactory.Commandto be used to create subsystems.List<UserAuthFactory>getUserAuthFactories()booleanisStarted()voidopen()voidsetCommandFactory(CommandFactory commandFactory)voidsetGSSAuthenticator(GSSAuthenticator gssAuthenticator)voidsetHost(String host)voidsetHostBasedAuthenticator(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 SshServersetUpDefaultServer()Setup 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)StringtoString()-
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 Detail
-
DEFAULT_SERVICE_FACTORIES
public static final List<ServiceFactory> DEFAULT_SERVICE_FACTORIES
-
acceptor
protected IoAcceptor acceptor
-
host
protected String host
-
port
protected int port
-
-
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
-
getBoundAddresses
public Set<SocketAddress> getBoundAddresses()
-
getUserAuthFactories
public List<UserAuthFactory> getUserAuthFactories()
- Specified by:
getUserAuthFactoriesin interfaceUserAuthFactoriesManager<ServerSession,UserAuth,UserAuthFactory>
-
setUserAuthFactories
public void setUserAuthFactories(List<UserAuthFactory> userAuthFactories)
- Specified by:
setUserAuthFactoriesin interfaceUserAuthFactoriesManager<ServerSession,UserAuth,UserAuthFactory>
-
getShellFactory
public ShellFactory 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
public void setShellFactory(ShellFactory shellFactory)
-
getSessionFactory
public SessionFactory getSessionFactory()
-
setSessionFactory
public void setSessionFactory(SessionFactory sessionFactory)
-
getServerProxyAcceptor
public ServerProxyAcceptor getServerProxyAcceptor()
- Specified by:
getServerProxyAcceptorin interfaceServerProxyAcceptorHolder
-
setServerProxyAcceptor
public void setServerProxyAcceptor(ServerProxyAcceptor proxyAcceptor)
- Specified by:
setServerProxyAcceptorin interfaceServerProxyAcceptorHolder
-
getCommandFactory
public CommandFactory 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
public void setCommandFactory(CommandFactory commandFactory)
-
getSubsystemFactories
public List<? extends SubsystemFactory> 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
public void setSubsystemFactories(List<? extends SubsystemFactory> subsystemFactories)
-
getPasswordAuthenticator
public PasswordAuthenticator 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
public void setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator)
- Specified by:
setPasswordAuthenticatorin interfaceServerAuthenticationManager
-
getPublickeyAuthenticator
public PublickeyAuthenticator 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
public void setPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator)
- Specified by:
setPublickeyAuthenticatorin interfaceServerAuthenticationManager
-
getKeyboardInteractiveAuthenticator
public KeyboardInteractiveAuthenticator 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
public GSSAuthenticator 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
public void setGSSAuthenticator(GSSAuthenticator gssAuthenticator)
- Specified by:
setGSSAuthenticatorin interfaceServerAuthenticationManager
-
getHostBasedAuthenticator
public HostBasedAuthenticator 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
public void setHostBasedAuthenticator(HostBasedAuthenticator hostBasedAuthenticator)
- Specified by:
setHostBasedAuthenticatorin interfaceServerAuthenticationManager
-
getKeyPairProvider
public KeyPairProvider getKeyPairProvider()
- Specified by:
getKeyPairProviderin interfaceKeyPairProviderHolder
-
setKeyPairProvider
public void setKeyPairProvider(KeyPairProvider keyPairProvider)
- Specified by:
setKeyPairProviderin interfaceKeyPairProviderHolder
-
getHostKeyCertificateProvider
public HostKeyCertificateProvider getHostKeyCertificateProvider()
- Specified by:
getHostKeyCertificateProviderin interfaceServerAuthenticationManager- Returns:
- a
HostKeyCertificateProviderif available, null as default
-
setHostKeyCertificateProvider
public void setHostKeyCertificateProvider(HostKeyCertificateProvider hostKeyCertificateProvider)
- Specified by:
setHostKeyCertificateProviderin interfaceServerAuthenticationManager
-
checkConfig
protected void checkConfig()
- Overrides:
checkConfigin classAbstractFactoryManager
-
isStarted
public boolean isStarted()
-
start
public void start() throws IOExceptionStart the SSH server and accept incoming exceptions on the configured port. Ignored if alreadystarted- Throws:
IOException- If failed to start
-
stop
public void stop() throws IOExceptionStop the SSH server. This method will block until all resources are actually disposed.- Throws:
IOException- if stopping failed somehow
-
stop
public void stop(boolean immediately) throws IOException- Throws:
IOException
-
open
public void open() throws IOException- Throws:
IOException
-
getInnerCloseable
protected Closeable getInnerCloseable()
- Specified by:
getInnerCloseablein classAbstractInnerCloseable
-
getActiveSessions
public List<AbstractSession> getActiveSessions()
Obtain the list of active sessions.- Returns:
- A
Listof the currently active session
-
createAcceptor
protected IoAcceptor createAcceptor()
-
createSessionFactory
protected SessionFactory createSessionFactory()
-
-