Package org.apache.sshd.common.session
Interface Session
-
- All Superinterfaces:
AttributeRepository
,AttributeStore
,java.lang.AutoCloseable
,java.nio.channels.Channel
,ChannelListenerManager
,ChannelStreamPacketWriterResolver
,ChannelStreamPacketWriterResolverManager
,java.io.Closeable
,Closeable
,ConnectionEndpointsIndicator
,FactoryManagerHolder
,KexExtensionHandlerManager
,KexFactoryManager
,MutableUserHolder
,PacketWriter
,PortForwardingEventListenerManager
,PortForwardingInformationProvider
,PropertyResolver
,ReservedSessionMessagesManager
,SessionContext
,SessionDisconnectHandlerManager
,SessionHeartbeatController
,SessionListenerManager
,SignatureFactoriesManager
,UnknownChannelReferenceHandlerManager
,UsernameHolder
- All Known Subinterfaces:
ClientSession
,ServerSession
- All Known Implementing Classes:
AbstractClientSession
,AbstractServerSession
,AbstractSession
,ClientSessionImpl
,ServerSessionImpl
,SessionHelper
public interface Session extends SessionContext, MutableUserHolder, KexFactoryManager, SessionListenerManager, ReservedSessionMessagesManager, SessionDisconnectHandlerManager, ChannelListenerManager, ChannelStreamPacketWriterResolverManager, PortForwardingEventListenerManager, UnknownChannelReferenceHandlerManager, FactoryManagerHolder, PortForwardingInformationProvider, PacketWriter
Represents an SSH session. Note: the associated username for the session may benull
/empty if the session is not yet authenticated
-
-
Nested Class Summary
-
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 inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamPacketWriterResolver
NONE
-
Fields inherited from interface org.apache.sshd.common.Closeable
CLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUT
-
Fields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY
-
Fields inherited from interface org.apache.sshd.common.session.SessionContext
DEFAULT_SSH_VERSION_PREFIX, FALLBACK_SSH_VERSION_PREFIX, MAX_VERSION_LINE_LENGTH
-
Fields inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
DEFAULT_CONNECTION_HEARTBEAT_INTERVAL, SESSION_HEARTBEAT_INTERVAL, SESSION_HEARTBEAT_TYPE
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Buffer
createBuffer(byte cmd)
Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.Buffer
createBuffer(byte cmd, int estimatedSize)
Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.void
disconnect(int reason, java.lang.String msg)
Send a disconnect packet with the given reason and message.void
exceptionCaught(java.lang.Throwable t)
Handle any exceptions that occurred on this session.long
getAuthTimeout()
long
getAuthTimeoutStart()
long
getIdleTimeout()
long
getIdleTimeoutStart()
IoSession
getIoSession()
KeyExchange
getKex()
default java.net.SocketAddress
getLocalAddress()
default java.net.SocketAddress
getRemoteAddress()
<T extends Service>
TgetService(java.lang.Class<T> clazz)
Get the service of the specified type.TimeoutIndicator
getTimeoutStatus()
Check if timeout has occurred.Buffer
prepareBuffer(byte cmd, Buffer buffer)
Prepare a new "clean" buffer while reserving the needed space (5 bytes) for the packet header.KeyExchangeFuture
reExchangeKeys()
Initiate a new key exchange.Buffer
request(java.lang.String request, Buffer buffer, long timeout, java.util.concurrent.TimeUnit unit)
Send a global request and wait for the response.long
resetAuthTimeout()
Re-start the authentication timeout timerlong
resetIdleTimeout()
Re-start idle timeout timerdefault <T> T
resolveAttribute(AttributeRepository.AttributeKey<T> key)
Attempts to resolve the associated value by going up the store's hierarchy (if any)static <T> T
resolveAttribute(Session session, AttributeRepository.AttributeKey<T> key)
Attempts to use the session's attribute, if not found then tries the factory managerIoWriteFuture
sendDebugMessage(boolean display, java.lang.Object msg, java.lang.String lang)
Sends anSSH_MSG_DEBUG
to the peer sessionIoWriteFuture
sendIgnoreMessage(byte... data)
Sends anSSH_MSG_IGNORE
to the peer sessionvoid
setAuthenticated()
void
startService(java.lang.String name, Buffer buffer)
IoWriteFuture
writePacket(Buffer buffer, long timeout, java.util.concurrent.TimeUnit unit)
Encode and send the given buffer with the specified timeout.-
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.ChannelStreamPacketWriterResolverManager
getChannelStreamPacketWriterResolver, resolveChannelStreamPacketWriter, resolveChannelStreamPacketWriterResolver, setChannelStreamPacketWriterResolver
-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
Methods inherited from interface org.apache.sshd.common.FactoryManagerHolder
getFactoryManager
-
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.auth.MutableUserHolder
setUsername
-
Methods inherited from interface org.apache.sshd.common.io.PacketWriter
writePacket
-
Methods inherited from interface org.apache.sshd.common.forward.PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListener
-
Methods inherited from interface org.apache.sshd.common.forward.PortForwardingInformationProvider
getBoundLocalPortForward, getBoundRemotePortForward, getLocalForwardsBindings, getRemoteForwardsBindings, getStartedLocalPortForwards, getStartedRemotePortForwards, isLocalPortForwardingStartedForPort, isRemotePortForwardingStartedForPort
-
Methods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty
-
Methods inherited from interface org.apache.sshd.common.session.ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandler
-
Methods inherited from interface org.apache.sshd.common.session.SessionContext
getCipherInformation, getClientKexProposals, getClientVersion, getCompressionInformation, getKexNegotiationResult, getKexState, getMacInformation, getNegotiatedKexParameter, getServerKexProposals, getServerVersion, getSessionId, isAuthenticated, isServerSession
-
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
-
Methods inherited from interface org.apache.sshd.common.session.SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListener
-
Methods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesManager
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNames, 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.UsernameHolder
getUsername
-
-
-
-
Method Detail
-
createBuffer
default Buffer createBuffer(byte cmd)
Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.- Parameters:
cmd
- the SSH command- Returns:
- a new buffer (of unknown size) ready for write
- See Also:
createBuffer(byte, int)
-
createBuffer
Buffer createBuffer(byte cmd, int estimatedSize)
Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.- Parameters:
cmd
- The SSH command to initialize the buffer withestimatedSize
- Estimated number of bytes the buffer will hold, 0 if unknown.- Returns:
- a new buffer ready for write
- See Also:
prepareBuffer(byte, Buffer)
-
prepareBuffer
Buffer prepareBuffer(byte cmd, Buffer buffer)
Prepare a new "clean" buffer while reserving the needed space (5 bytes) for the packet header.- Parameters:
cmd
- The SSH command to initialize the buffer withbuffer
- TheBuffer
instance to initialize- Returns:
- The initialized buffer
-
sendDebugMessage
IoWriteFuture sendDebugMessage(boolean display, java.lang.Object msg, java.lang.String lang) throws java.io.IOException
Sends anSSH_MSG_DEBUG
to the peer session- Parameters:
display
-true
if OK to display the message at the peer as-ismsg
- The message object whosetoString()
value to be used - ifnull
then the "null" string is sentlang
- The language -null
/empty if some pre-agreed default is used- Returns:
- An
IoWriteFuture
that can be used to check when the packet has actually been sent - Throws:
java.io.IOException
- if an error occurred when encoding sending the packet- See Also:
- RFC 4253 - section 11.3
-
sendIgnoreMessage
IoWriteFuture sendIgnoreMessage(byte... data) throws java.io.IOException
Sends anSSH_MSG_IGNORE
to the peer session- Parameters:
data
- The message data- Returns:
- An
IoWriteFuture
that can be used to check when the packet has actually been sent - Throws:
java.io.IOException
- if an error occurred when encoding sending the packet- See Also:
- RFC 4253 - section 11.2
-
writePacket
IoWriteFuture writePacket(Buffer buffer, long timeout, java.util.concurrent.TimeUnit unit) throws java.io.IOException
Encode and send the given buffer with the specified timeout. If the buffer could not be written before the timeout elapses, the returnedIoWriteFuture
will be set with aTimeoutException
exception to indicate a timeout.- Parameters:
buffer
- the buffer to encode and spendtimeout
- the timeoutunit
- the time unit of the timeout parameter- Returns:
- a future that can be used to check when the packet has actually been sent
- Throws:
java.io.IOException
- if an error occurred when encoding sending the packet
-
request
Buffer request(java.lang.String request, Buffer buffer, long timeout, java.util.concurrent.TimeUnit unit) throws java.io.IOException
Send a global request and wait for the response. This must only be used when sending aSSH_MSG_GLOBAL_REQUEST
with a result expected, else it will time out- Parameters:
request
- the request name - used mainly for logging and debuggingbuffer
- the buffer containing the global requesttimeout
- The number of time units to wait - must be positiveunit
- TheTimeUnit
to wait for the response- Returns:
- the return buffer if the request was successful,
null
otherwise. - Throws:
java.io.IOException
- if an error occurred when encoding sending the packet
-
exceptionCaught
void exceptionCaught(java.lang.Throwable t)
Handle any exceptions that occurred on this session. The session will be closed and a disconnect packet will be sent before if the given exception is anSshException
with a positive error code- Parameters:
t
- the exception to process
-
reExchangeKeys
KeyExchangeFuture reExchangeKeys() throws java.io.IOException
Initiate a new key exchange.- Returns:
- A
KeyExchangeFuture
for awaiting the completion of the exchange - Throws:
java.io.IOException
- If failed to request keys re-negotiation
-
getService
<T extends Service> T getService(java.lang.Class<T> clazz)
Get the service of the specified type. If the service is not of the specified class, an IllegalStateException will be thrown.- Type Parameters:
T
- The genericService
type- Parameters:
clazz
- The service class- Returns:
- The service instance
- Throws:
java.lang.IllegalStateException
- If failed to find a matching service
-
getLocalAddress
default java.net.SocketAddress getLocalAddress()
- Specified by:
getLocalAddress
in interfaceConnectionEndpointsIndicator
- Returns:
- the socket address of local machine which is associated with this session.
-
getRemoteAddress
default java.net.SocketAddress getRemoteAddress()
- Specified by:
getRemoteAddress
in interfaceConnectionEndpointsIndicator
- Returns:
- the socket address of remote peer.
-
getTimeoutStatus
TimeoutIndicator getTimeoutStatus()
Check if timeout has occurred.- Returns:
- the timeout status - never
null
-
getIdleTimeout
long getIdleTimeout()
- Returns:
- Timeout value in milliseconds for communication
-
getIdleTimeoutStart
long getIdleTimeoutStart()
- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
-
resetIdleTimeout
long resetIdleTimeout()
Re-start idle timeout timer- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
- See Also:
getIdleTimeoutStart()
-
getAuthTimeout
long getAuthTimeout()
- Returns:
- Timeout value in milliseconds for authentication stage
-
getAuthTimeoutStart
long getAuthTimeoutStart()
- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
-
resetAuthTimeout
long resetAuthTimeout()
Re-start the authentication timeout timer- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
- See Also:
getAuthTimeoutStart()
-
setAuthenticated
void setAuthenticated() throws java.io.IOException
- Throws:
java.io.IOException
-
getKex
KeyExchange getKex()
-
disconnect
void disconnect(int reason, java.lang.String msg) throws java.io.IOException
Send a disconnect packet with the given reason and message. Once the packet has been sent, the session will be closed asynchronously.- Parameters:
reason
- the reason code for this disconnectmsg
- the text message- Throws:
java.io.IOException
- if an error occurred sending the packet
-
startService
void startService(java.lang.String name, Buffer buffer) throws java.lang.Exception
- Parameters:
name
- Service namebuffer
- Extra information provided when the service start request was received- Throws:
java.lang.Exception
- If failed to start it
-
resolveAttribute
default <T> T resolveAttribute(AttributeRepository.AttributeKey<T> key)
Description copied from interface:AttributeRepository
Attempts to resolve the associated value by going up the store's hierarchy (if any)- Specified by:
resolveAttribute
in interfaceAttributeRepository
- Type Parameters:
T
- The generic attribute type- Parameters:
key
- The key of the attribute; must not benull
.- Returns:
null
if there is no value associated with the specified key either in this repository or any of its ancestors (if any available)
-
resolveAttribute
static <T> T resolveAttribute(Session session, AttributeRepository.AttributeKey<T> key)
Attempts to use the session's attribute, if not found then tries the factory manager- Type Parameters:
T
- The generic attribute type- Parameters:
session
- TheSession
- ignored ifnull
key
- The attribute key - nevernull
- Returns:
- Associated value -
null
if not found - See Also:
FactoryManagerHolder.getFactoryManager()
,FactoryManager.resolveAttribute(FactoryManager, AttributeRepository.AttributeKey)
-
-