Top Description Fields Methods
org.apache.sshd.common.session

public Interface Session

extends SessionContext, MutableUserHolder, KexFactoryManager, SessionListenerManager, ReservedSessionMessagesManager, SessionDisconnectHandlerManager, ChannelListenerManager, ChannelStreamWriterResolverManager, PortForwardingEventListenerManager, UnknownChannelReferenceHandlerManager, FactoryManagerHolder, PortForwardingInformationProvider
Known Direct Subinterfaces
org.apache.sshd.server.session.ServerSession, org.apache.sshd.client.session.ClientSession
Known Direct Implementers
org.apache.sshd.common.session.helpers.SessionHelper
Imports
java.io.IOException, java.net.SocketAddress, java.time.Duration, .Instant, java.util.Objects, java.util.concurrent.TimeUnit, org.apache.sshd.common.AttributeRepository, .FactoryManager, .FactoryManagerHolder, .Service, org.apache.sshd.common.auth.MutableUserHolder, org.apache.sshd.common.channel.ChannelListenerManager, org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager, org.apache.sshd.common.forward.PortForwardingEventListenerManager, .PortForwardingInformationProvider, org.apache.sshd.common.future.GlobalRequestFuture, .GlobalRequestFuture.ReplyHandler, .KeyExchangeFuture, org.apache.sshd.common.io.IoSession, .IoWriteFuture, org.apache.sshd.common.kex.KexFactoryManager, .KeyExchange, org.apache.sshd.common.session.helpers.TimeoutIndicator, org.apache.sshd.common.util.ValidateUtils, org.apache.sshd.common.util.buffer.Buffer

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

Field Summary

Inherited from org.apache.sshd.common.session.SessionContext:
DEFAULT_SSH_VERSION_PREFIXFALLBACK_SSH_VERSION_PREFIXMAX_VERSION_LINE_LENGTH

Method Summary

Modifier and TypeMethod and Description
public default Buffer

Returns:

a new buffer (of unknown size) ready for write
createBuffer
(byte
the SSH command
cmd
)

Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.

public Buffer

Returns:

a new buffer ready for write
createBuffer
(byte
The SSH command to initialize the buffer with
cmd
,
int
Estimated number of bytes the buffer will hold, 0 if unknown.
estimatedSize
)

Create a new buffer for the specified SSH packet and reserve the needed space (5 bytes) for the packet header.

public void
disconnect(int
the reason code for this disconnect
reason
,
String
the text message
msg
)

Send a disconnect packet with the given reason and message.

public void
exceptionCaught(Throwable
the exception to process
t
)

Handle any exceptions that occurred on this session.

public Duration

Returns:

Timeout value in milliseconds for authentication stage
getAuthTimeout
()

public Instant

Returns:

The timestamp value (milliseconds since EPOCH) when timer was started
getAuthTimeoutStart
()

public Duration

Returns:

Timeout value in milliseconds for communication
getIdleTimeout
()

public Instant

Returns:

The timestamp value (milliseconds since EPOCH) when timer was started
getIdleTimeoutStart
()

public IoSession

Returns:

The IoSession associated to this session
getIoSession
()

public KeyExchange

Returns:

The current KeyExchange in progress - null if KEX not started or successfully completed
getKex
()

public default SocketAddress
public default SocketAddress
public <
The generic Service type
T extends Service
>
T

Returns:

The service instance
getService
(Class<T>
The service class
clazz
)

Get the service of the specified type.

public TimeoutIndicator

Returns:

the timeout status - never null
getTimeoutStatus
()

Check if timeout has occurred.

public Buffer

Returns:

The initialized buffer
prepareBuffer
(byte
The SSH command to initialize the buffer with
cmd
,
Buffer
The Buffer instance to initialize
buffer
)

Prepare a new "clean" buffer while reserving the needed space (5 bytes) for the packet header.

public KeyExchangeFuture

Returns:

A KeyExchangeFuture for awaiting the completion of the exchange
reExchangeKeys
()

Initiate a new key exchange.

public default Buffer

Returns:

the return buffer if the request was successful, null otherwise.
request
(String
the request name - used mainly for logging and debugging
request
,
Buffer
the buffer containing the global request
buffer
,
long
The number of time units to wait - must be positive
timeout
,
TimeUnit
The TimeUnit to wait for the response
unit
)

Send a global request and wait for the response, if the request is sent with want-reply = true.

public default Buffer

Returns:

the return buffer if the request was successful, null otherwise.
request
(String
the request name - used mainly for logging and debugging
request
,
Buffer
the buffer containing the global request
buffer
,
Duration
The (never null) timeout to wait - its milliseconds value is used
timeout
)

Send a global request and wait for the response, if the request is sent with want-reply = true.

public Buffer

Returns:

the return buffer if the request was successful, null otherwise.
request
(String
the request name - used mainly for logging and debugging
request
,
Buffer
the buffer containing the global request
buffer
,
long
maximum time in milliseconds to wait for the request to finish - must be positive
maxWaitMillis
)

Send a global request and wait for the response, if the request is sent with want-reply = true.

public GlobalRequestFuture

Returns:

Created GlobalRequestFuture
request
(Buffer
the Buffer containing the global request, with the want-reply flag set as appropriate
buffer
,
String
the request name
request
,
GlobalRequestFuture.ReplyHandler
ReplyHandler for handling the reply; may be null
replyHandler
)

Send a global request and handle the reply asynchronously.

public Instant

Returns:

The timestamp value (milliseconds since EPOCH) when timer was started
resetAuthTimeout
()

Re-start the authentication timeout timer

public Instant

Returns:

The timestamp value (milliseconds since EPOCH) when timer was started
resetIdleTimeout
()

Re-start idle timeout timer

public default <T> T
resolveAttribute(AttributeRepository.AttributeKey<T>
The key of the attribute; must not be null.
key
)

Overrides default org.apache.sshd.common.AttributeRepository.resolveAttribute.

Attempts to resolve the associated value by going up the store's hierarchy (if any)

public static <
The generic attribute type
T
>
T

Returns:

Associated value - null if not found
resolveAttribute
(Session
The Session - ignored if null
session
,
AttributeRepository.AttributeKey<T>
The attribute key - never null
key
)

Attempts to use the session's attribute, if not found then tries the factory manager

public IoWriteFuture

Returns:

An IoWriteFuture that can be used to check when the packet has actually been sent
sendDebugMessage
(boolean
true if OK to display the message at the peer as-is
display
,
Object
The message object whose toString() value to be used - if null then the "null" string is sent
msg
,
String
The language - null/empty if some pre-agreed default is used
lang
)

Sends an SSH_MSG_DEBUG to the peer session

public IoWriteFuture

Returns:

An IoWriteFuture that can be used to check when the packet has actually been sent
sendIgnoreMessage
(byte...
The message data
data
)

Sends an SSH_MSG_IGNORE to the peer session

public void
public void
startService(String
Service name
name
,
Buffer
Extra information provided when the service start request was received
buffer
)

public IoWriteFuture

Returns:

An IoWriteFuture that can be used to check when the packet has actually been sent
writePacket
(Buffer
the buffer to encode and send
buffer
)

Encode and send the given buffer.

public default IoWriteFuture

Returns:

a future that can be used to check when the packet has actually been sent
writePacket
(Buffer
the buffer to encode and spend
buffer
,
Duration
the (never null) timeout value - its milliseconds value will be used
timeout
)

Encode and send the given buffer with the specified timeout.

public default IoWriteFuture

Returns:

a future that can be used to check when the packet has actually been sent
writePacket
(Buffer
the buffer to encode and spend
buffer
,
long
the timeout in milliseconds
maxWaitMillis
)

Encode and send the given buffer with the specified timeout.

public IoWriteFuture

Returns:

a future that can be used to check when the packet has actually been sent
writePacket
(Buffer
the buffer to encode and spend
buffer
,
long
the timeout
timeout
,
TimeUnit
the time unit of the timeout parameter
unit
)

Encode and send the given buffer with the specified timeout.

Inherited from org.apache.sshd.common.auth.MutableUserHolder:
setUsername
Inherited from org.apache.sshd.common.channel.ChannelListenerManager:
addChannelListenergetChannelListenerProxyremoveChannelListener
Inherited from org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager:
getChannelStreamWriterResolverresolveChannelStreamWriterresolveChannelStreamWriterResolversetChannelStreamWriterResolver
Inherited from org.apache.sshd.common.FactoryManagerHolder:
getFactoryManager
Inherited from org.apache.sshd.common.forward.PortForwardingEventListenerManager:
addPortForwardingEventListenergetPortForwardingEventListenerProxyremovePortForwardingEventListener
Inherited from org.apache.sshd.common.forward.PortForwardingInformationProvider:
getBoundLocalPortForwardsgetBoundRemotePortForwardgetLocalForwardsBindingsgetRemoteForwardsBindingsgetStartedLocalPortForwardsgetStartedRemotePortForwardsisLocalPortForwardingStartedForPortisRemotePortForwardingStartedForPort
Inherited from org.apache.sshd.common.kex.KexFactoryManager:
getCipherFactoriesgetCipherFactoriesNameListgetCipherFactoriesNamesgetCompressionFactoriesgetCompressionFactoriesNameListgetCompressionFactoriesNamesgetKeyExchangeFactoriesgetMacFactoriesgetMacFactoriesNameListgetMacFactoriesNamessetCipherFactoriessetCipherFactoriesNameListsetCipherFactoriesNamessetCipherFactoriesNamessetCompressionFactoriessetCompressionFactoriesNameListsetCompressionFactoriesNamessetCompressionFactoriesNamessetKeyExchangeFactoriessetMacFactoriessetMacFactoriesNameListsetMacFactoriesNamessetMacFactoriesNames
Inherited from org.apache.sshd.common.session.ReservedSessionMessagesManager:
getReservedSessionMessagesHandlersetReservedSessionMessagesHandler
Inherited from org.apache.sshd.common.session.SessionContext:
getCipherInformationgetClientKexProposalsgetClientVersiongetCompressionInformationgetKexNegotiationResultgetKexStategetMacInformationgetNegotiatedKexParametergetServerKexProposalsgetServerVersiongetSessionIdisAuthenticatedisDataIntegrityTransportisSecureSessionTransportisServerSessionisValidSessionPayloadSizeisValidVersionPrefixvalidateSessionPayloadSize
Inherited from org.apache.sshd.common.session.SessionDisconnectHandlerManager:
getSessionDisconnectHandlersetSessionDisconnectHandler
Inherited from org.apache.sshd.common.session.SessionListenerManager:
addSessionListenergetSessionListenerProxyremoveSessionListener
Inherited from org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager:
getUnknownChannelReferenceHandlerresolveUnknownChannelReferenceHandlersetUnknownChannelReferenceHandler

Method Detail

createBufferback to summary
public 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:byte

the SSH command

Returns:Buffer

a new buffer (of unknown size) ready for write

See Also
createBuffer(byte, int)
createBufferback to summary
public 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:byte

The SSH command to initialize the buffer with

estimatedSize:int

Estimated number of bytes the buffer will hold, 0 if unknown.

Returns:Buffer

a new buffer ready for write

See Also
prepareBuffer(byte, Buffer)
disconnectback to summary
public void disconnect(int reason, String msg) throws 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:int

the reason code for this disconnect

msg:String

the text message

Exceptions
IOException:
if an error occurred sending the packet
exceptionCaughtback to summary
public void exceptionCaught(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 an org.apache.sshd.common.SshException with a positive error code

Parameters
t:Throwable

the exception to process

getAuthTimeoutback to summary
public Duration getAuthTimeout()
Returns:Duration

Timeout value in milliseconds for authentication stage

getAuthTimeoutStartback to summary
public Instant getAuthTimeoutStart()
Returns:Instant

The timestamp value (milliseconds since EPOCH) when timer was started

getIdleTimeoutback to summary
public Duration getIdleTimeout()
Returns:Duration

Timeout value in milliseconds for communication

getIdleTimeoutStartback to summary
public Instant getIdleTimeoutStart()
Returns:Instant

The timestamp value (milliseconds since EPOCH) when timer was started

getIoSessionback to summary
public IoSession getIoSession()
Returns:IoSession

The IoSession associated to this session

getKexback to summary
public KeyExchange getKex()
Returns:KeyExchange

The current KeyExchange in progress - null if KEX not started or successfully completed

getLocalAddressback to summary
public default SocketAddress getLocalAddress()

Implements org.apache.sshd.common.util.net.ConnectionEndpointsIndicator.getLocalAddress.

Returns:SocketAddress

Doc from org.apache.sshd.common.util.net.ConnectionEndpointsIndicator.getLocalAddress.

the socket address of local machine which is associated with this session.

Annotations
@Override
getRemoteAddressback to summary
public default SocketAddress getRemoteAddress()

Implements org.apache.sshd.common.util.net.ConnectionEndpointsIndicator.getRemoteAddress.

Returns:SocketAddress

Doc from org.apache.sshd.common.util.net.ConnectionEndpointsIndicator.getRemoteAddress.

the socket address of remote peer.

Annotations
@Override
getServiceback to summary
public <T extends Service> T getService(Class<T> clazz)

Get the service of the specified type. If the service is not of the specified class, an IllegalStateException will be thrown.

Parameters
<T>
The generic Service type
clazz:Class<T>

The service class

Returns:T

The service instance

Exceptions
IllegalStateException:
If failed to find a matching service
getTimeoutStatusback to summary
public TimeoutIndicator getTimeoutStatus()

Check if timeout has occurred.

Returns:TimeoutIndicator

the timeout status - never null

prepareBufferback to summary
public Buffer prepareBuffer(byte cmd, Buffer buffer)

Prepare a new "clean" buffer while reserving the needed space (5 bytes) for the packet header.

Parameters
cmd:byte

The SSH command to initialize the buffer with

buffer:Buffer

The Buffer instance to initialize

Returns:Buffer

The initialized buffer

reExchangeKeysback to summary
public KeyExchangeFuture reExchangeKeys() throws IOException

Initiate a new key exchange.

Returns:KeyExchangeFuture

A KeyExchangeFuture for awaiting the completion of the exchange

Exceptions
IOException:
If failed to request keys re-negotiation
requestback to summary
public 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 with want-reply = true.

Parameters
request:String

the request name - used mainly for logging and debugging

buffer:Buffer

the buffer containing the global request

timeout:long

The number of time units to wait - must be positive

unit:TimeUnit

The TimeUnit to wait for the response

Returns:Buffer

the return buffer if the request was successful, null otherwise.

Exceptions
IOException:
if an error occurred when encoding or sending the packet
SocketTimeoutException:
If no response received within specified timeout
requestback to summary
public default Buffer request(String request, Buffer buffer, Duration timeout) throws IOException

Send a global request and wait for the response, if the request is sent with want-reply = true.

Parameters
request:String

the request name - used mainly for logging and debugging

buffer:Buffer

the buffer containing the global request

timeout:Duration

The (never null) timeout to wait - its milliseconds value is used

Returns:Buffer

the return buffer if the request was successful, null otherwise.

Exceptions
IOException:
if an error occurred when encoding or sending the packet
SocketTimeoutException:
If no response received within specified timeout
requestback to summary
public Buffer request(String request, Buffer buffer, long maxWaitMillis) throws IOException

Send a global request and wait for the response, if the request is sent with want-reply = true.

Parameters
request:String

the request name - used mainly for logging and debugging

buffer:Buffer

the buffer containing the global request

maxWaitMillis:long

maximum time in milliseconds to wait for the request to finish - must be positive

Returns:Buffer

the return buffer if the request was successful, null otherwise.

Exceptions
IOException:
if an error occurred when encoding or sending the packet
SocketTimeoutException:
If no response received within specified timeout
requestback to summary
public GlobalRequestFuture request(Buffer buffer, String request, GlobalRequestFuture.ReplyHandler replyHandler) throws IOException

Send a global request and handle the reply asynchronously. If want-reply = true, pass the received Buffer to the given 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. The replyHandler 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:Buffer

the Buffer containing the global request, with the want-reply flag set as appropriate

request:String

the request name

replyHandler:GlobalRequestFuture.ReplyHandler

ReplyHandler for handling the reply; may be null

Returns:GlobalRequestFuture

Created GlobalRequestFuture

Exceptions
IOException:
if an error occurred while encoding or sending the packet
resetAuthTimeoutback to summary
public Instant resetAuthTimeout()

Re-start the authentication timeout timer

Returns:Instant

The timestamp value (milliseconds since EPOCH) when timer was started

See Also
getAuthTimeoutStart()
resetIdleTimeoutback to summary
public Instant resetIdleTimeout()

Re-start idle timeout timer

Returns:Instant

The timestamp value (milliseconds since EPOCH) when timer was started

See Also
getIdleTimeoutStart()
resolveAttributeback to summary
public default <T> T resolveAttribute(AttributeRepository.AttributeKey<T> key)

Overrides default org.apache.sshd.common.AttributeRepository.resolveAttribute.

Doc from org.apache.sshd.common.AttributeRepository.resolveAttribute.

Attempts to resolve the associated value by going up the store's hierarchy (if any)

Parameters
<T>
The generic attribute type
key:AttributeRepository.AttributeKey<T>

The key of the attribute; must not be null.

Returns:T

null if there is no value associated with the specified key either in this repository or any of its ancestors (if any available)

Annotations
@Override
resolveAttributeback to summary
public 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

Parameters
<T>
The generic attribute type
session:Session

The Session - ignored if null

key:AttributeRepository.AttributeKey<T>

The attribute key - never null

Returns:T

Associated value - null if not found

See Also
Session#getFactoryManager(), FactoryManager#resolveAttribute(FactoryManager, AttributeRepository.AttributeKey)
sendDebugMessageback to summary
public IoWriteFuture sendDebugMessage(boolean display, Object msg, String lang) throws IOException

Sends an SSH_MSG_DEBUG to the peer session

Parameters
display:boolean

true if OK to display the message at the peer as-is

msg:Object

The message object whose toString() value to be used - if null then the "null" string is sent

lang:String

The language - null/empty if some pre-agreed default is used

Returns:IoWriteFuture

An IoWriteFuture that can be used to check when the packet has actually been sent

Exceptions
IOException:
if an error occurred when encoding or sending the packet
See Also
RFC 4253 - section 11.3
sendIgnoreMessageback to summary
public IoWriteFuture sendIgnoreMessage(byte... data) throws IOException

Sends an SSH_MSG_IGNORE to the peer session

Parameters
data:byte[]

The message data

Returns:IoWriteFuture

An IoWriteFuture that can be used to check when the packet has actually been sent

Exceptions
IOException:
if an error occurred when encoding or sending the packet
See Also
RFC 4253 - section 11.2
setAuthenticatedback to summary
public void setAuthenticated() throws IOException
startServiceback to summary
public void startService(String name, Buffer buffer) throws Exception
Parameters
name:String

Service name

buffer:Buffer

Extra information provided when the service start request was received

Exceptions
Exception:
If failed to start it
writePacketback to summary
public IoWriteFuture writePacket(Buffer buffer) throws IOException

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:Buffer

the buffer to encode and send

Returns:IoWriteFuture

An IoWriteFuture that can be used to check when the packet has actually been sent

Exceptions
IOException:
if an error occurred when encoding sending the packet
writePacketback to summary
public default IoWriteFuture writePacket(Buffer buffer, Duration timeout) throws IOException

Encode and send the given buffer with the specified timeout. If the buffer could not be written before the timeout elapses, the returned org.apache.sshd.common.io.IoWriteFuture will be set with a java.util.concurrent.TimeoutException exception to indicate a timeout.

Parameters
buffer:Buffer

the buffer to encode and spend

timeout:Duration

the (never null) timeout value - its milliseconds value will be used

Returns:IoWriteFuture

a future that can be used to check when the packet has actually been sent

Exceptions
IOException:
if an error occurred when encoding or sending the packet
See Also
writePacket(Buffer, long)
writePacketback to summary
public default IoWriteFuture writePacket(Buffer buffer, long maxWaitMillis) throws IOException

Encode and send the given buffer with the specified timeout. If the buffer could not be written before the timeout elapses, the returned org.apache.sshd.common.io.IoWriteFuture will be set with a java.util.concurrent.TimeoutException exception to indicate a timeout.

Parameters
buffer:Buffer

the buffer to encode and spend

maxWaitMillis:long

the timeout in milliseconds

Returns:IoWriteFuture

a future that can be used to check when the packet has actually been sent

Exceptions
IOException:
if an error occurred when encoding or sending the packet
writePacketback to summary
public IoWriteFuture writePacket(Buffer buffer, long timeout, TimeUnit unit) throws IOException

Encode and send the given buffer with the specified timeout. If the buffer could not be written before the timeout elapses, the returned org.apache.sshd.common.io.IoWriteFuture will be set with a java.util.concurrent.TimeoutException exception to indicate a timeout.

Parameters
buffer:Buffer

the buffer to encode and spend

timeout:long

the timeout

unit:TimeUnit

the time unit of the timeout parameter

Returns:IoWriteFuture

a future that can be used to check when the packet has actually been sent

Exceptions
IOException:
if an error occurred when encoding or sending the packet