Package org.apache.sshd.server
Class SshServer
- java.lang.Object
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.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
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.- 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>
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
SessionHeartbeatController.HeartbeatType
-
-
Field Summary
Fields Modifier and Type Field Description protected IoAcceptoracceptorprivate CommandFactorycommandFactorystatic java.util.List<ServiceFactory>DEFAULT_SERVICE_FACTORIESstatic Factory<SshServer>DEFAULT_SSH_SERVER_FACTORYprivate GSSAuthenticatorgssAuthenticatorprotected java.lang.Stringhostprivate HostBasedAuthenticatorhostBasedAuthenticatorprivate HostKeyCertificateProviderhostKeyCertificateProviderprivate KeyboardInteractiveAuthenticatorinteractiveAuthenticatorprivate KeyPairProviderkeyPairProviderprivate PasswordAuthenticatorpasswordAuthenticatorprotected intportprivate ServerProxyAcceptorproxyAcceptorprivate PublickeyAuthenticatorpublickeyAuthenticatorprivate SessionFactorysessionFactoryprivate ShellFactoryshellFactoryprivate java.util.concurrent.atomic.AtomicBooleanstartedprivate java.util.List<? extends SubsystemFactory>subsystemFactoriesprivate java.util.List<UserAuthFactory>userAuthFactories-
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()java.util.List<AbstractSession>getActiveSessions()Obtain the list of active sessions.java.util.Set<java.net.SocketAddress>getBoundAddresses()CommandFactorygetCommandFactory()Retrieve theCommandFactoryto be used to process commands requests.GSSAuthenticatorgetGSSAuthenticator()Retrieve theGSSAuthenticatorto be used by the SSH server.java.lang.StringgetHost()HostBasedAuthenticatorgetHostBasedAuthenticator()Retrieve theHostBasedAuthenticatorto be used by the SSH server.HostKeyCertificateProvidergetHostKeyCertificateProvider()protected CloseablegetInnerCloseable()KeyboardInteractiveAuthenticatorgetKeyboardInteractiveAuthenticator()Retrieve theKeyboardInteractiveAuthenticatorto be used by the SSH server.KeyPairProvidergetKeyPairProvider()Retrieve theKeyPairProviderthat will be used to find the host key to use on the server side or the user key on the client side.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.java.util.List<? extends SubsystemFactory>getSubsystemFactories()Retrieve the list of named factories forCommandFactory.Commandto be used to create subsystems.java.util.List<UserAuthFactory>getUserAuthFactories()Retrieve the list of named factories forUserAuthobjects.booleanisStarted()voidopen()voidsetCommandFactory(CommandFactory commandFactory)voidsetGSSAuthenticator(GSSAuthenticator gssAuthenticator)voidsetHost(java.lang.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(java.util.List<? extends SubsystemFactory> subsystemFactories)static SshServersetUpDefaultServer()Setup a default servervoidsetUserAuthFactories(java.util.List<UserAuthFactory> userAuthFactories)voidstart()Start the SSH server and accept incoming exceptions on the configured port.voidstop()Stop the SSH server.voidstop(boolean immediately)java.lang.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.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 java.util.List<ServiceFactory> DEFAULT_SERVICE_FACTORIES
-
acceptor
protected IoAcceptor acceptor
-
host
protected java.lang.String host
-
port
protected int port
-
proxyAcceptor
private ServerProxyAcceptor proxyAcceptor
-
shellFactory
private ShellFactory shellFactory
-
sessionFactory
private SessionFactory sessionFactory
-
commandFactory
private CommandFactory commandFactory
-
subsystemFactories
private java.util.List<? extends SubsystemFactory> subsystemFactories
-
userAuthFactories
private java.util.List<UserAuthFactory> userAuthFactories
-
keyPairProvider
private KeyPairProvider keyPairProvider
-
hostKeyCertificateProvider
private HostKeyCertificateProvider hostKeyCertificateProvider
-
passwordAuthenticator
private PasswordAuthenticator passwordAuthenticator
-
publickeyAuthenticator
private PublickeyAuthenticator publickeyAuthenticator
-
interactiveAuthenticator
private KeyboardInteractiveAuthenticator interactiveAuthenticator
-
hostBasedAuthenticator
private HostBasedAuthenticator hostBasedAuthenticator
-
gssAuthenticator
private GSSAuthenticator gssAuthenticator
-
started
private final java.util.concurrent.atomic.AtomicBoolean started
-
-
Method Detail
-
getHost
public java.lang.String getHost()
-
setHost
public void setHost(java.lang.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 java.util.Set<java.net.SocketAddress> getBoundAddresses()
-
getUserAuthFactories
public java.util.List<UserAuthFactory> 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
public void setUserAuthFactories(java.util.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 java.util.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(java.util.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()
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
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 java.io.IOExceptionStart the SSH server and accept incoming exceptions on the configured port. Ignored if alreadystarted- Throws:
java.io.IOException- If failed to start
-
stop
public void stop() throws java.io.IOExceptionStop the SSH server. This method will block until all resources are actually disposed.- Throws:
java.io.IOException- if stopping failed somehow
-
stop
public void stop(boolean immediately) throws java.io.IOException- Throws:
java.io.IOException
-
open
public void open() throws java.io.IOException- Throws:
java.io.IOException
-
getInnerCloseable
protected Closeable getInnerCloseable()
- Specified by:
getInnerCloseablein classAbstractInnerCloseable
-
getActiveSessions
public java.util.List<AbstractSession> getActiveSessions()
Obtain the list of active sessions.- Returns:
- A
Listof the currently active session
-
createAcceptor
protected IoAcceptor createAcceptor()
-
createSessionFactory
protected SessionFactory createSessionFactory()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-