Package org.apache.sshd.common.session
Interface Session
- All Superinterfaces:
AttributeRepository
,AttributeStore
,AutoCloseable
,Channel
,ChannelListenerManager
,ChannelStreamWriterResolver
,ChannelStreamWriterResolverManager
,Closeable
,Closeable
,ConnectionEndpointsIndicator
,FactoryManagerHolder
,KexExtensionHandlerManager
,KexFactoryManager
,MutableUserHolder
,PortForwardingEventListenerManager
,PortForwardingInformationProvider
,PropertyResolver
,ReservedSessionMessagesManager
,SessionContext
,SessionDisconnectHandlerManager
,SessionHeartbeatController
,SessionListenerManager
,SignatureFactoriesHolder
,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, ChannelStreamWriterResolverManager, PortForwardingEventListenerManager, UnknownChannelReferenceHandlerManager, FactoryManagerHolder, PortForwardingInformationProvider
Represents an SSH session. Note: the associated username for the session may be
null
/empty if the
session is not yet authenticated- Author:
- Apache MINA SSHD Project
-
Nested Class Summary
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 inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONE
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
-
Method Summary
Modifier and TypeMethodDescriptiondefault Buffer
createBuffer
(byte cmd) Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.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, String msg) Send a disconnect packet with the given reason and message.void
Handle any exceptions that occurred on this session.getKex()
default SocketAddress
default SocketAddress
<T extends Service>
TgetService
(Class<T> clazz) Get the service of the specified type.Check if timeout has occurred.prepareBuffer
(byte cmd, Buffer buffer) Prepare a new "clean" buffer while reserving the needed space (5 bytes) for the packet header.Initiate a new key exchange.Send a global request and wait for the response, if the request is sent withwant-reply = true
.default Buffer
Send a global request and wait for the response, if the request is sent withwant-reply = true
.default Buffer
Send a global request and wait for the response, if the request is sent withwant-reply = true
.request
(Buffer buffer, String request, GlobalRequestFuture.ReplyHandler replyHandler) Send a global request and handle the reply asynchronously.Re-start the authentication timeout timerRe-start idle timeout timerdefault <T> T
static <T> T
resolveAttribute
(Session session, AttributeRepository.AttributeKey<T> key) Attempts to use the session's attribute, if not found then tries the factory managersendDebugMessage
(boolean display, Object msg, String lang) Sends anSSH_MSG_DEBUG
to the peer sessionsendIgnoreMessage
(byte... data) Sends anSSH_MSG_IGNORE
to the peer sessionvoid
void
startService
(String name, Buffer buffer) writePacket
(Buffer buffer) Encode and send the given buffer.default IoWriteFuture
writePacket
(Buffer buffer, long maxWaitMillis) Encode and send the given buffer with the specified timeout.writePacket
(Buffer buffer, long timeout, TimeUnit unit) Encode and send the given buffer with the specified timeout.default IoWriteFuture
writePacket
(Buffer buffer, Duration timeout) 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.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.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.forward.PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListener
Methods inherited from interface org.apache.sshd.common.forward.PortForwardingInformationProvider
getBoundLocalPortForwards, 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, isEmpty
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, 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.UsernameHolder
getUsername
-
Method Details
-
createBuffer
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
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
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
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:
IOException
- if an error occurred when encoding or sending the packet- See Also:
-
sendIgnoreMessage
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:
IOException
- if an error occurred when encoding or sending the packet- See Also:
-
writePacket
Encode and send the given buffer. The buffer has to have 5 bytes free at the beginning to allow the encoding to take place. Also, the write position of the buffer has to be set to the position of the last byte to write.- Parameters:
buffer
- the buffer to encode and send- Returns:
- An
IoWriteFuture
that can be used to check when the packet has actually been sent - Throws:
IOException
- if an error occurred when encoding sending the packet
-
writePacket
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 (nevernull
) timeout value - itsmilliseconds
value will be used- Returns:
- a future that can be used to check when the packet has actually been sent
- Throws:
IOException
- if an error occurred when encoding or sending the packet- See Also:
-
writePacket
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 spendmaxWaitMillis
- the timeout in milliseconds- Returns:
- a future that can be used to check when the packet has actually been sent
- Throws:
IOException
- if an error occurred when encoding or sending the packet
-
writePacket
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:
IOException
- if an error occurred when encoding or sending the packet
-
request
default Buffer request(String request, Buffer buffer, long timeout, TimeUnit unit) throws IOException Send a global request and wait for the response, if the request is sent withwant-reply = true
.- 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:
IOException
- if an error occurred when encoding or sending the packetSocketTimeoutException
- If no response received within specified timeout
-
request
Send a global request and wait for the response, if the request is sent withwant-reply = true
.- Parameters:
request
- the request name - used mainly for logging and debuggingbuffer
- the buffer containing the global requesttimeout
- The (nevernull
) timeout to wait - its milliseconds value is used- Returns:
- the return buffer if the request was successful,
null
otherwise. - Throws:
IOException
- if an error occurred when encoding or sending the packetSocketTimeoutException
- If no response received within specified timeout
-
request
Send a global request and wait for the response, if the request is sent withwant-reply = true
.- Parameters:
request
- the request name - used mainly for logging and debuggingbuffer
- the buffer containing the global requestmaxWaitMillis
- maximum time in milliseconds to wait for the request to finish - must be positive- Returns:
- the return buffer if the request was successful,
null
otherwise. - Throws:
IOException
- if an error occurred when encoding or sending the packetSocketTimeoutException
- If no response received within specified timeout
-
request
GlobalRequestFuture request(Buffer buffer, String request, GlobalRequestFuture.ReplyHandler replyHandler) throws IOException Send a global request and handle the reply asynchronously. Ifwant-reply = true
, pass the receivedBuffer
to the givenGlobalRequestFuture.ReplyHandler
, which may execute in a different thread.- want-reply == true && replyHandler != null
- The returned future is fulfilled with
null
when the request was sent, or with an exception if the request could not be sent. ThereplyHandler
is invoked once the reply is received, with the SSH reply code and the data received. - want-reply == true && replyHandler == null
- The returned future is fulfilled with an exception if the request could not be sent, or a failure reply was received. If a success reply was received, the future is fulfilled with the received data buffer.
- want-reply == false
- The returned future is fulfilled with an empty
Buffer
when the request was sent, or with an exception if the request could not be sent. If a reply handler is given, it is invoked with that empty buffer. The handler is not invoked if sending the request failed.
- Parameters:
buffer
- theBuffer
containing the global request, with thewant-reply
flag set as appropriaterequest
- the request namereplyHandler
-GlobalRequestFuture.ReplyHandler
for handling the reply; may benull
- Returns:
- Created
GlobalRequestFuture
- Throws:
IOException
- if an error occurred while encoding or sending the packet
-
exceptionCaught
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
Initiate a new key exchange.- Returns:
- A
KeyExchangeFuture
for awaiting the completion of the exchange - Throws:
IOException
- If failed to request keys re-negotiation
-
getService
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:
IllegalStateException
- If failed to find a matching service
-
getIoSession
IoSession getIoSession()- Returns:
- The
IoSession
associated to this session
-
getLocalAddress
- Specified by:
getLocalAddress
in interfaceConnectionEndpointsIndicator
-
getRemoteAddress
- Specified by:
getRemoteAddress
in interfaceConnectionEndpointsIndicator
-
getTimeoutStatus
TimeoutIndicator getTimeoutStatus()Check if timeout has occurred.- Returns:
- the timeout status - never
null
-
getIdleTimeout
Duration getIdleTimeout()- Returns:
- Timeout value in milliseconds for communication
-
getIdleTimeoutStart
Instant getIdleTimeoutStart()- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
-
resetIdleTimeout
Instant resetIdleTimeout()Re-start idle timeout timer- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
- See Also:
-
getAuthTimeout
Duration getAuthTimeout()- Returns:
- Timeout value in milliseconds for authentication stage
-
getAuthTimeoutStart
Instant getAuthTimeoutStart()- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
-
resetAuthTimeout
Instant resetAuthTimeout()Re-start the authentication timeout timer- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
- See Also:
-
setAuthenticated
- Throws:
IOException
-
getKex
KeyExchange getKex()- Returns:
- The current
KeyExchange
in progress -null
if KEX not started or successfully completed
-
disconnect
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:
IOException
- if an error occurred sending the packet
-
startService
- Parameters:
name
- Service namebuffer
- Extra information provided when the service start request was received- Throws:
Exception
- If failed to start it
-
resolveAttribute
- Specified by:
resolveAttribute
in interfaceAttributeRepository
-
resolveAttribute
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:
-