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-
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.ChannelStreamWriterResolver
NONEFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTYFields 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 BuffercreateBuffer(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.voiddisconnect(int reason, String msg) Send a disconnect packet with the given reason and message.voidHandle any exceptions that occurred on this session.getKex()default SocketAddressdefault 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 BufferSend a global request and wait for the response, if the request is sent withwant-reply = true.default BufferSend 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> TAttempts to resolve the associated value by going up the store's hierarchy (if any)static <T> TresolveAttribute(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_DEBUGto the peer sessionsendIgnoreMessage(byte... data) Sends anSSH_MSG_IGNOREto the peer sessionvoidvoidstartService(String name, Buffer buffer) writePacket(Buffer buffer) Encode and send the given buffer.default IoWriteFuturewritePacket(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 IoWriteFuturewritePacket(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, getAttributesCountMethods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeMethods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolverMethods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListenerMethods inherited from interface org.apache.sshd.common.FactoryManagerHolder
getFactoryManagerMethods inherited from interface org.apache.sshd.common.kex.extension.KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandlerMethods 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, setMacFactoriesNamesMethods inherited from interface org.apache.sshd.common.auth.MutableUserHolder
setUsernameMethods inherited from interface org.apache.sshd.common.forward.PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListenerMethods inherited from interface org.apache.sshd.common.forward.PortForwardingInformationProvider
getBoundLocalPortForwards, getBoundRemotePortForward, getLocalForwardsBindings, getRemoteForwardsBindings, getStartedLocalPortForwards, getStartedRemotePortForwards, isLocalPortForwardingStartedForPort, isRemotePortForwardingStartedForPortMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmptyMethods inherited from interface org.apache.sshd.common.session.ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandlerMethods inherited from interface org.apache.sshd.common.session.SessionContext
getCipherInformation, getClientKexProposals, getClientVersion, getCompressionInformation, getKexNegotiationResult, getKexState, getMacInformation, getNegotiatedKexParameter, getServerKexProposals, getServerVersion, getSessionId, isAuthenticated, isServerSessionMethods inherited from interface org.apache.sshd.common.session.SessionDisconnectHandlerManager
getSessionDisconnectHandler, setSessionDisconnectHandlerMethods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatMethods inherited from interface org.apache.sshd.common.session.SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListenerMethods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesHolder
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNamesMethods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesManager
setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNamesMethods inherited from interface org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager
getUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandlerMethods 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- TheBufferinstance to initialize- Returns:
- The initialized buffer
-
sendDebugMessage
Sends anSSH_MSG_DEBUGto the peer session- Parameters:
display-trueif OK to display the message at the peer as-ismsg- The message object whosetoString()value to be used - ifnullthen the "null" string is sentlang- The language -null/empty if some pre-agreed default is used- Returns:
- An
IoWriteFuturethat 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_IGNOREto the peer session- Parameters:
data- The message data- Returns:
- An
IoWriteFuturethat 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
IoWriteFuturethat 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 returnedIoWriteFuturewill be set with aTimeoutExceptionexception to indicate a timeout.- Parameters:
buffer- the buffer to encode and spendtimeout- the (nevernull) timeout value - itsmillisecondsvalue 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 returnedIoWriteFuturewill be set with aTimeoutExceptionexception 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 returnedIoWriteFuturewill be set with aTimeoutExceptionexception 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- TheTimeUnitto wait for the response- Returns:
- the return buffer if the request was successful,
nullotherwise. - 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,
nullotherwise. - 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,
nullotherwise. - 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 receivedBufferto the givenGlobalRequestFuture.ReplyHandler, which may execute in a different thread.- want-reply == true && replyHandler != null
- The returned future is fulfilled with
nullwhen the request was sent, or with an exception if the request could not be sent. ThereplyHandleris 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
Bufferwhen 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- theBuffercontaining the global request, with thewant-replyflag set as appropriaterequest- the request namereplyHandler-GlobalRequestFuture.ReplyHandlerfor 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 anSshExceptionwith a positive error code- Parameters:
t- the exception to process
-
reExchangeKeys
Initiate a new key exchange.- Returns:
- A
KeyExchangeFuturefor 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 genericServicetype- Parameters:
clazz- The service class- Returns:
- The service instance
- Throws:
IllegalStateException- If failed to find a matching service
-
getIoSession
IoSession getIoSession()- Returns:
- The
IoSessionassociated to this session
-
getLocalAddress
- Specified by:
getLocalAddressin interfaceConnectionEndpointsIndicator- Returns:
- the socket address of local machine which is associated with this session.
-
getRemoteAddress
- Specified by:
getRemoteAddressin interfaceConnectionEndpointsIndicator- Returns:
- the socket address of remote peer.
-
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
KeyExchangein progress -nullif 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
Description copied from interface:AttributeRepositoryAttempts to resolve the associated value by going up the store's hierarchy (if any)- Specified by:
resolveAttributein interfaceAttributeRepository- Type Parameters:
T- The generic attribute type- Parameters:
key- The key of the attribute; must not benull.- Returns:
nullif there is no value associated with the specified key either in this repository or any of its ancestors (if any available)
-
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 ifnullkey- The attribute key - nevernull- Returns:
- Associated value -
nullif not found - See Also:
-