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

public abstract Class SessionHelper

extends AbstractKexFactoryManager
implements Session
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.session.Session, org.apache.sshd.common.forward.PortForwardingInformationProvider, org.apache.sshd.common.FactoryManagerHolder, org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager, org.apache.sshd.common.forward.PortForwardingEventListenerManager, org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager, org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver, org.apache.sshd.common.channel.ChannelListenerManager, org.apache.sshd.common.session.SessionDisconnectHandlerManager, org.apache.sshd.common.session.ReservedSessionMessagesManager, org.apache.sshd.common.session.SessionListenerManager, org.apache.sshd.common.kex.KexFactoryManager, org.apache.sshd.common.kex.extension.KexExtensionHandlerManager, org.apache.sshd.common.signature.SignatureFactoriesManager, org.apache.sshd.common.signature.SignatureFactoriesHolder, org.apache.sshd.common.auth.MutableUserHolder, org.apache.sshd.common.auth.UsernameHolder, org.apache.sshd.common.session.SessionContext, org.apache.sshd.common.Closeable, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, org.apache.sshd.common.AttributeStore, org.apache.sshd.common.AttributeRepository, org.apache.sshd.common.session.SessionHeartbeatController, org.apache.sshd.common.PropertyResolver, org.apache.sshd.common.util.net.ConnectionEndpointsIndicator
Known Direct Subclasses
org.apache.sshd.common.session.helpers.AbstractSession
Imports
java.io.IOException, .StreamCorruptedException, java.net.SocketAddress, java.nio.charset.StandardCharsets, java.security.GeneralSecurityException, java.time.Duration, .Instant, java.util.ArrayList, .Collection, .Collections, .EnumMap, .HashSet, .List, .Map, .NavigableSet, .Objects, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicReference, java.util.function.Function, org.apache.sshd.common.AttributeRepository, .FactoryManager, .NamedResource, .PropertyResolver, .RuntimeSshException, .SshConstants, .SshException, org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver, .ChannelStreamWriterResolverManager, org.apache.sshd.common.digest.Digest, org.apache.sshd.common.forward.Forwarder, org.apache.sshd.common.io.IoSession, .IoWriteFuture, org.apache.sshd.common.kex.AbstractKexFactoryManager, .KexProposalOption, org.apache.sshd.common.kex.extension.KexExtensionHandler, org.apache.sshd.common.random.Random, org.apache.sshd.common.session.ConnectionService, .ReservedSessionMessagesHandler, .Session, .SessionContext, .SessionDisconnectHandler, .SessionListener, .UnknownChannelReferenceHandler, org.apache.sshd.common.session.helpers.TimeoutIndicator.TimeoutStatus, org.apache.sshd.common.util.ExceptionUtils, .GenericUtils, .MapEntryUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.Buffer, .BufferUtils, .ByteArrayBuffer, org.apache.sshd.common.util.io.functors.Invoker, org.apache.sshd.common.util.net.SshdSocketAddress, org.apache.sshd.core.CoreModuleProperties

Contains split code in order to make AbstractSession class smaller

Field Summary

Modifier and TypeField and Description
private final Map<AttributeRepository.AttributeKey<?>, Object>
attributes

Session specific attributes

private volatile boolean
authed

Boolean indicating if this session has been authenticated or not

protected Instant
private ChannelStreamWriterResolver
protected Instant
protected Map<KexProposalOption, String>
initialKexProposal

Stores the initial KEX proposal after it has been run through the hooks allowing client code to modify it; see getKexProposal().

private final IoSession
ioSession

The underlying network session

private final Map<String, Object>
properties

The session specific properties

private ReservedSessionMessagesHandler
private final boolean
serverSession

Client or server side

private SessionDisconnectHandler
private final AtomicReference<TimeoutIndicator>
private UnknownChannelReferenceHandler
private volatile String
username

The name of the authenticated user

Constructor Summary

AccessConstructor and Description
protected
SessionHelper(boolean
true if this is a server session, false if client one
serverSession
,
FactoryManager
the factory manager
factoryManager
,
IoSession
the underlying I/O session
ioSession
)

Create a new session.

Method Summary

Modifier and TypeMethod and Description
public Collection<AttributeRepository.AttributeKey<?>>
protected long
calculateNextIgnorePacketCount(Random r, long freq, int variance)

protected TimeoutIndicator

Returns:

A TimeoutIndicator specifying the timeout status and disconnect reason message if timeout expired, null or NoTimeout if no timeout occurred
checkAuthenticationTimeout
(Instant
The current time in millis
now
,
Duration
The configured timeout - if non-positive then no timeout
authTimeout
)

Checks if authentication timeout expired

protected TimeoutIndicator

Returns:

An indication whether timeout has been detected
checkForTimeouts
()

Checks whether the session has timed out (both authentication and idle timeouts are checked).

protected TimeoutIndicator

Returns:

A TimeoutIndicator specifying the timeout status and disconnect reason message if timeout expired, null or NoTimeout if no timeout occurred
checkIdleTimeout
(Instant
The current time in millis
now
,
Duration
The configured timeout - if non-positive then no timeout
idleTimeout
)

Checks if idle timeout expired

public void
clearAttributes()

Implements org.apache.sshd.common.AttributeStore.clearAttributes.

Removes all currently stored user-defined attributes

public <T> T
computeAttributeIfAbsent(AttributeRepository.AttributeKey<T>
The key of the attribute; must not be null.
key
,
Function<? super AttributeRepository.AttributeKey<T>, ? extends T>
The (never null) mapping function to use if value not already mapped. If returns null then value is not mapped to the provided key.
resolver
)

Overrides default org.apache.sshd.common.AttributeStore.computeAttributeIfAbsent.

If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.

protected Map<KexProposalOption, String>

Returns:

The proposal Map
createProposal
(String
The comma-separated list of supported host key types
hostKeyTypes
)

Create our proposal for SSH negotiation

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

Implements org.apache.sshd.common.session.Session.disconnect.

Send a disconnect packet with the given reason and message.

protected void
doInvokeDebugMessageHandler(Buffer
The input Buffer
buffer
)

Invoked by handleDebug(Buffer) after validating that the buffer structure seems well-formed and also resetting the idle timeout.

protected void
doInvokeIgnoreMessageHandler(Buffer
The input Buffer
buffer
)

Invoked by handleDebug(Buffer) after validating that the buffer structure seems well-formed and also resetting the idle timeout.

protected boolean

Returns:

Result of invoking handleUnimplementedMessage
doInvokeUnimplementedMessageHandler
(int
The unimplemented command
cmd
,
Buffer
The input Buffer
buffer
)

protected List<String>

Returns:

A List of all received remote identification lines until the version line was read or null if more data is needed. The identification line is the last one in the list
doReadIdentification
(Buffer
the buffer containing the identification string
buffer
,
boolean
true if it is called by the server session, false if by the client session
server
)

Read the remote identification from this buffer.

public void
exceptionCaught(Throwable
the exception to process
t
)

Implements org.apache.sshd.common.session.Session.exceptionCaught.

Handle any exceptions that occurred on this session.

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

Implements org.apache.sshd.common.AttributeRepository.getAttribute.

Returns the value of the user-defined attribute.

public int
public Duration
public Instant
public List<SshdSocketAddress>
public SshdSocketAddress
public ChannelStreamWriterResolver
protected abstract ConnectionService
public FactoryManager
protected Forwarder
public Duration
public Instant
public IoSession
protected Map<KexProposalOption, String>

Returns:

the proposal Map
getKexProposal
()

Retrieves this side's initial proposal for KEX negotiation.

public List<Map.Entry<SshdSocketAddress, SshdSocketAddress>>
public PropertyResolver
public Map<String, Object>
getProperties()

Implements org.apache.sshd.common.PropertyResolver.getProperties.

A map of properties that can be used to configure the SSH server or client.

public List<Map.Entry<Integer, SshdSocketAddress>>
public ReservedSessionMessagesHandler
public SessionDisconnectHandler
public List<SshdSocketAddress>
public NavigableSet<Integer>
public TimeoutIndicator
public UnknownChannelReferenceHandler
public String
protected void
protected void
protected void
handleDisconnect(int code, String msg, String lang, Buffer buffer)

protected void
protected void
protected void
public boolean
public boolean
public boolean
public boolean
isServerSession()

Implements org.apache.sshd.common.session.SessionContext.isServerSession.

Quick indication if this is a server or client session (instead of having to ask instanceof).

protected Map<KexProposalOption, String>
protected Buffer

Returns:

The adjusted Buffer

Note

users may use this method to totally alter the contents of the buffer being sent but it is highly discouraged as it may have unexpected results.

preProcessEncodeBuffer
(int
The command stored in the buffer
cmd
,
Buffer
The original Buffer - assumed to be properly formatted and be of at least the required minimum length.
buffer
)

Invoked by the session before encoding the buffer in order to make sure that it is at least of size SSH_PACKET_HEADER_LEN.

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

Implements org.apache.sshd.common.AttributeStore.removeAttribute.

Removes the user-defined attribute

public Instant
resetAuthTimeout()

Implements org.apache.sshd.common.session.Session.resetAuthTimeout.

Re-start the authentication timeout timer

public Instant
protected byte[]

Returns:

the resized key
resizeKey
(byte[]
the key to resize
e
,
int
the cipher key-derivation-factor (in bytes)
kdfSize
,
Digest
the hash algorithm
hash
,
byte[]
the key exchange k parameter
k
,
byte[]
the key exchange h parameter
h
)

Method used while putting new keys into use that will resize the key used to initialize the cipher to the needed length.

protected String

Returns:

A comma-separated list of all the signature protocols to be included in the proposal - null/empty if no proposal
resolveAvailableSignaturesProposal
()

Computes the list of available host key signature algorithms supported.

protected abstract String

Returns:

A comma-separated list of all the signature protocols to be included in the proposal - null/empty if no proposal
resolveAvailableSignaturesProposal
(FactoryManager manager)

Computes the list of available host key signature algorithms supported.

public ChannelStreamWriterResolver
protected String

Returns:

The resolved identification value
resolveIdentificationString
(String
The property used to query the factory manager
configPropName
)

Resolves the identification to send to the peer session by consulting the associated FactoryManager.

protected SocketAddress

Returns:

The external address if not null otherwise, the IoSession peer address
resolvePeerAddress
(SocketAddress
Any externally set peer address - e.g., due to some proxy mechanism meta-data
knownAddress
)

protected ReservedSessionMessagesHandler
protected String
public UnknownChannelReferenceHandler
resolveUnknownChannelReferenceHandler()

Implements org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager.resolveUnknownChannelReferenceHandler.

Check if current manager has a specific handler set for it - if not, try and resolve one from the "parent" container (if any)

public IoWriteFuture
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
)

Implements org.apache.sshd.common.session.Session.sendDebugMessage.

Sends an SSH_MSG_DEBUG to the peer session

protected IoWriteFuture

Returns:

IoWriteFuture that can be used to wait for notification that identification has been send
sendIdentification
(String
our identification to send
version
,
List<String>
Extra lines to send - used only by server sessions
extraLines
)

Send our identification.

public IoWriteFuture
sendIgnoreMessage(byte...
The message data
data
)

Implements org.apache.sshd.common.session.Session.sendIgnoreMessage.

Sends an SSH_MSG_IGNORE to the peer session

protected IoWriteFuture

Returns:

An IoWriteFuture that can be used to wait for packet write completion
sendNotImplemented
(long
The referenced sequence number
seqNoValue
)

Sends a SSH_MSG_UNIMPLEMENTED message

public <T> T
setAttribute(AttributeRepository.AttributeKey<T>
The key of the attribute; must not be null.
key
,
T
The value of the attribute; must not be null.
value
)

Implements org.apache.sshd.common.AttributeStore.setAttribute.

Sets a user-defined attribute.

public void
public void
public void
public void
public void
public void
protected void
signalDisconnect(int code, String msg, String lang, boolean initiator)

protected void
signalDisconnect(SessionListener listener, int code, String msg, String lang, boolean initiator)

protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
signalSendIdentification(SessionListener listener, String version, List<String> extraLines)

protected void
protected void
protected void
protected void
protected void
protected void
protected void
signalSessionEvent(SessionListener.Event
The event to send
event
)

Sends a session event to all currently registered session listeners

protected void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.apache.sshd.common.kex.AbstractKexFactoryManager:
getCipherFactoriesgetCompressionFactoriesgetDelegategetKexExtensionHandlergetKeyExchangeFactoriesgetMacFactoriesgetSignatureFactoriesresolveEffectiveFactoriesresolveEffectiveProvidersetCipherFactoriessetCompressionFactoriessetKexExtensionHandlersetKeyExchangeFactoriessetMacFactoriessetSignatureFactories