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
, theKeyPairProvider
and thePasswordAuthenticator
.Some properties can also be configured using the
Once the SshServer instance has been configured, it can be started using thePropertyResolverUtils
updateProperty
methods.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 IoAcceptor
acceptor
static List<ServiceFactory>
DEFAULT_SERVICE_FACTORIES
static Factory<SshServer>
DEFAULT_SSH_SERVER_FACTORY
protected String
host
protected int
port
-
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 void
checkConfig()
protected IoAcceptor
createAcceptor()
protected SessionFactory
createSessionFactory()
List<AbstractSession>
getActiveSessions()
Obtain the list of active sessions.Set<SocketAddress>
getBoundAddresses()
CommandFactory
getCommandFactory()
Retrieve theCommandFactory
to be used to process commands requests.GSSAuthenticator
getGSSAuthenticator()
Retrieve theGSSAuthenticator
to be used by the SSH server.String
getHost()
HostBasedAuthenticator
getHostBasedAuthenticator()
Retrieve theHostBasedAuthenticator
to be used by the SSH server.HostKeyCertificateProvider
getHostKeyCertificateProvider()
protected Closeable
getInnerCloseable()
KeyboardInteractiveAuthenticator
getKeyboardInteractiveAuthenticator()
Retrieve theKeyboardInteractiveAuthenticator
to be used by the SSH server.KeyPairProvider
getKeyPairProvider()
PasswordAuthenticator
getPasswordAuthenticator()
Retrieve thePasswordAuthenticator
to be used by the SSH server.int
getPort()
PublickeyAuthenticator
getPublickeyAuthenticator()
Retrieve thePublickeyAuthenticator
to be used by SSH server.ServerProxyAcceptor
getServerProxyAcceptor()
SessionFactory
getSessionFactory()
ShellFactory
getShellFactory()
Retrieve theShellFactory
object to be used to create shells.List<? extends SubsystemFactory>
getSubsystemFactories()
Retrieve the list of named factories forCommandFactory.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 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)
String
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 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:
getUserAuthFactories
in interfaceUserAuthFactoriesManager<ServerSession,UserAuth,UserAuthFactory>
-
setUserAuthFactories
public void setUserAuthFactories(List<UserAuthFactory> userAuthFactories)
- Specified by:
setUserAuthFactories
in interfaceUserAuthFactoriesManager<ServerSession,UserAuth,UserAuthFactory>
-
getShellFactory
public ShellFactory 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
public void setShellFactory(ShellFactory shellFactory)
-
getSessionFactory
public SessionFactory getSessionFactory()
-
setSessionFactory
public void setSessionFactory(SessionFactory sessionFactory)
-
getServerProxyAcceptor
public ServerProxyAcceptor getServerProxyAcceptor()
- Specified by:
getServerProxyAcceptor
in interfaceServerProxyAcceptorHolder
-
setServerProxyAcceptor
public void setServerProxyAcceptor(ServerProxyAcceptor proxyAcceptor)
- Specified by:
setServerProxyAcceptor
in interfaceServerProxyAcceptorHolder
-
getCommandFactory
public CommandFactory 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
public void setCommandFactory(CommandFactory commandFactory)
-
getSubsystemFactories
public List<? extends SubsystemFactory> 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
public void setSubsystemFactories(List<? extends SubsystemFactory> subsystemFactories)
-
getPasswordAuthenticator
public PasswordAuthenticator 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
public void setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator)
- Specified by:
setPasswordAuthenticator
in interfaceServerAuthenticationManager
-
getPublickeyAuthenticator
public PublickeyAuthenticator 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
public void setPublickeyAuthenticator(PublickeyAuthenticator publickeyAuthenticator)
- Specified by:
setPublickeyAuthenticator
in interfaceServerAuthenticationManager
-
getKeyboardInteractiveAuthenticator
public KeyboardInteractiveAuthenticator 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
public GSSAuthenticator 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
public void setGSSAuthenticator(GSSAuthenticator gssAuthenticator)
- Specified by:
setGSSAuthenticator
in interfaceServerAuthenticationManager
-
getHostBasedAuthenticator
public HostBasedAuthenticator 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
public void setHostBasedAuthenticator(HostBasedAuthenticator hostBasedAuthenticator)
- Specified by:
setHostBasedAuthenticator
in interfaceServerAuthenticationManager
-
getKeyPairProvider
public KeyPairProvider getKeyPairProvider()
- Specified by:
getKeyPairProvider
in interfaceKeyPairProviderHolder
-
setKeyPairProvider
public void setKeyPairProvider(KeyPairProvider keyPairProvider)
- Specified by:
setKeyPairProvider
in interfaceKeyPairProviderHolder
-
getHostKeyCertificateProvider
public HostKeyCertificateProvider getHostKeyCertificateProvider()
- Specified by:
getHostKeyCertificateProvider
in interfaceServerAuthenticationManager
- Returns:
- a
HostKeyCertificateProvider
if available, null as default
-
setHostKeyCertificateProvider
public void setHostKeyCertificateProvider(HostKeyCertificateProvider hostKeyCertificateProvider)
- Specified by:
setHostKeyCertificateProvider
in interfaceServerAuthenticationManager
-
checkConfig
protected void checkConfig()
- Overrides:
checkConfig
in classAbstractFactoryManager
-
isStarted
public boolean isStarted()
-
start
public void start() throws IOException
Start 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 IOException
Stop 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:
getInnerCloseable
in classAbstractInnerCloseable
-
getActiveSessions
public List<AbstractSession> getActiveSessions()
Obtain the list of active sessions.- Returns:
- A
List
of the currently active session
-
createAcceptor
protected IoAcceptor createAcceptor()
-
createSessionFactory
protected SessionFactory createSessionFactory()
-
-