Class ClientSessionImpl
java.lang.Object
- All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ClientAuthenticationManager, ClientProxyConnectorHolder, ClientSession, AttributeRepository, AttributeStore, MutableUserHolder, UserAuthFactoriesManager<ClientSession, UserAuth, UserAuthFactory>, UsernameHolder, ChannelListenerManager, ChannelStreamWriterResolver, ChannelStreamWriterResolverManager, Closeable, FactoryManagerHolder, PortForwardingEventListenerManager, PortForwardingInformationProvider, PortForwardingManager, KexExtensionHandlerManager, KexFactoryManager, KeyIdentityProviderHolder, PropertyResolver, ReservedSessionMessagesManager, Session, SessionContext, SessionDisconnectHandlerManager, SessionHeartbeatController, SessionListenerManager, UnknownChannelReferenceHandlerManager, SignatureFactoriesHolder, SignatureFactoriesManager, ConnectionEndpointsIndicator
The default implementation of a
ClientSession-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classEncapsulates and protects against concurrent access the service switching.Nested classes/interfaces inherited from class AbstractSession
AbstractSession.MessageCodingSettingsNested classes/interfaces inherited from class AbstractCloseable
AbstractCloseable.StateNested classes/interfaces inherited from interface AttributeRepository
AttributeRepository.AttributeKey<T>Nested classes/interfaces inherited from interface ClientSession
ClientSession.ClientSessionEventNested classes/interfaces inherited from interface SessionHeartbeatController
SessionHeartbeatController.HeartbeatType -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicReference<Throwable> Also guards setting an earlyError and the authFuture together.private AuthFutureprivate final AtomicReference<Throwable> private final AtomicBooleanFor clients to store their own metadataFields inherited from class AbstractClientSession
sendImmediateClientIdentification, sendImmediateKexInitFields inherited from class AbstractSession
channelListenerProxy, channelListeners, clientProposal, clientVersion, currentService, decodeLock, decoderBuffer, decoderLength, decoderState, discarding, encodeLock, firstKexPacketFollows, ignorePacketDataLength, ignorePacketsCount, ignorePacketsFrequency, ignorePacketsVariance, inBlocksCount, inBytesCount, inCipher, inCipherSize, inCompression, initialKexDone, initialKexInitSequenceNumber, inMac, inMacResult, inMacSize, inPacketsCount, inSettings, kex, kexFutureHolder, kexHandler, kexInitializedFuture, kexState, lastKeyTimeValue, maxRekeyBlocks, maxRekeyBytes, maxRekeyInterval, maxRekyPackets, negotiationResult, outBlocksCount, outBytesCount, outCipher, outCipherSize, outCompression, outMac, outMacSize, outPacketsCount, outSettings, random, requestLock, seqi, seqo, serverProposal, serverVersion, SESSION, sessionId, sessionListenerProxy, sessionListeners, strictKex, tunnelListenerProxy, tunnelListeners, uncompressBuffer, unmodClientProposal, unmodNegotiationResult, unmodServerProposalFields inherited from class SessionHelper
authStart, idleStart, initialKexProposalFields inherited from class AbstractCloseable
closeFuture, futureLock, stateFields inherited from class AbstractLoggingBean
logFields inherited from interface ChannelStreamWriterResolver
NONEFields inherited from interface ClientSession
REMOTE_COMMAND_WAIT_EVENTSFields inherited from interface PropertyResolver
EMPTYFields inherited from interface SessionContext
DEFAULT_SSH_VERSION_PREFIX, FALLBACK_SSH_VERSION_PREFIX, MAX_VERSION_LINE_LENGTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauth()Starts the authentication process.voidHandle any exceptions that occurred on this session.private ClientSessionImpl.ServicesAccess to the metadata.protected voidhandleDisconnect(int code, String msg, String lang, Buffer buffer) protected CurrentServiceCreates a newCurrentServiceinstance managing this session's current SSH service.protected Stringprotected voidpreClose()preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.protected voidprotected voidprotected voidSends a session event to all currently registered session listenersvoidstart()Starts the SSH protocol.voidprotected <C extends Collection<ClientSession.ClientSessionEvent>>
CupdateCurrentSessionState(C state) waitFor(Collection<ClientSession.ClientSessionEvent> mask, long timeout) Wait for any one of a specific state to be signaled.Methods inherited from class AbstractClientSession
addPasswordIdentity, addPublicKeyIdentity, checkKeys, createChannel, createChannel, createDirectTcpipChannel, createExecChannel, createExecChannel, createShellChannel, createSubsystemChannel, getClientProxyConnector, getConnectAddress, getConnectionContext, getConnectionService, getFactoryManager, getForwarder, getHostBasedAuthenticationReporter, getKeyIdentityProvider, getPasswordAuthenticationReporter, getPasswordIdentityProvider, getPublicKeyAuthenticationReporter, getRegisteredIdentities, getServerKey, getServerKeyVerifier, getUserAuthFactories, getUserAuthService, getUserInteraction, initializeKeyExchangePhase, initializeProxyConnector, readIdentification, receiveKexInit, receiveKexInit, removePasswordIdentity, removePublicKeyIdentity, resolveAvailableSignaturesProposal, sendClientIdentification, sendKexInit, setClientProxyConnector, setConnectAddress, setHostBasedAuthenticationReporter, setKexSeed, setKeyIdentityProvider, setPasswordAuthenticationReporter, setPasswordIdentityProvider, setPublicKeyAuthenticationReporter, setServerKey, setServerKeyVerifier, setUserAuthFactories, setUserInteraction, signalExtraServerVersionInfo, startDynamicPortForwarding, startLocalPortForwarding, startRemotePortForwarding, startService, stopDynamicPortForwarding, stopLocalPortForwarding, stopRemotePortForwarding, switchToNoneCipherMethods inherited from class AbstractSession
addChannelListener, addPortForwardingEventListener, addSessionListener, aeadOutgoingBuffer, appendOutgoingMac, attachSession, calculatePadLength, checkRekey, comparePreferredKexProposalOption, createBuffer, decode, determineRekeyBlockLimit, doHandleMessage, doInvokeUnimplementedMessageHandler, doKexNegotiation, doStrictKexProposal, doWritePacket, encode, encryptOutgoingBuffer, failStrictKex, getChannelListenerProxy, getCipherInformation, getClientKexData, getClientKexProposals, getClientVersion, getCompressionInformation, getInnerCloseable, getKex, getKexNegotiationResult, getKexState, getMacInformation, getNegotiatedKexParameter, getPortForwardingEventListenerProxy, getServerKexData, getServerKexProposals, getServerVersion, getService, getSession, getSession, getSessionId, getSessionListenerProxy, handleFirstKexPacketFollows, handleKexExtension, handleKexInit, handleKexMessage, handleMessage, handleNewCompression, handleNewKeys, handleServiceAccept, handleServiceAccept, handleServiceRequest, handleServiceRequest, initializeKeyExchangeMessageHandler, isRekeyBlocksCountExceeded, isRekeyDataSizeExceeded, isRekeyPacketCountsExceeded, isRekeyRequired, isRekeyTimeIntervalExceeded, messageReceived, negotiate, notImplemented, performKexNegotiation, prepareBuffer, prepareNewKeys, preProcessEncodeBuffer, receiveKexInit, reExchangeKeys, refreshConfiguration, removeChannelListener, removePortForwardingEventListener, removeSessionListener, removeValue, request, request, requestFailure, requestNewKeysExchange, requestSuccess, resolveIgnoreBufferDataLength, resolveOutputPacket, resolveSessionKexProposal, sendKexInit, sendNewKeys, setClientKexData, setInputEncoding, setNegotiationResult, setOutputEncoding, setServerKexData, validateIncomingMac, validateKexState, validateServiceKexState, validateTargetBuffer, writePacket, writePacketMethods inherited from class SessionHelper
attributeKeys, calculateNextIgnorePacketCount, checkAuthenticationTimeout, checkForTimeouts, checkIdleTimeout, clearAttributes, computeAttributeIfAbsent, createProposal, disconnect, doInvokeDebugMessageHandler, doInvokeIgnoreMessageHandler, doReadIdentification, getAttribute, getAttributesCount, getAuthTimeout, getAuthTimeoutStart, getBoundLocalPortForwards, getBoundRemotePortForward, getChannelStreamWriterResolver, getIdleTimeout, getIdleTimeoutStart, getIoSession, getKexProposal, getLocalForwardsBindings, getParentPropertyResolver, getProperties, getRemoteForwardsBindings, getReservedSessionMessagesHandler, getSessionDisconnectHandler, getStartedLocalPortForwards, getStartedRemotePortForwards, getTimeoutStatus, getUnknownChannelReferenceHandler, getUsername, handleDebug, handleDisconnect, handleIgnore, handleUnimplemented, invokeSessionSignaller, isAuthenticated, isLocalPortForwardingStartedForPort, isRemotePortForwardingStartedForPort, isServerSession, mergeProposals, removeAttribute, resetAuthTimeout, resetIdleTimeout, resizeKey, resolveAvailableSignaturesProposal, resolveChannelStreamWriterResolver, resolveIdentificationString, resolvePeerAddress, resolveReservedSessionMessagesHandler, resolveUnknownChannelReferenceHandler, sendDebugMessage, sendIdentification, sendIgnoreMessage, sendNotImplemented, setAttribute, setAuthenticated, setChannelStreamWriterResolver, setReservedSessionMessagesHandler, setSessionDisconnectHandler, setUnknownChannelReferenceHandler, setUsername, signalDisconnect, signalDisconnect, signalExceptionCaught, signalExceptionCaught, signalNegotiationEnd, signalNegotiationEnd, signalNegotiationOptionsCreated, signalNegotiationOptionsCreated, signalNegotiationStart, signalNegotiationStart, signalPeerIdentificationReceived, signalPeerIdentificationReceived, signalReadPeerIdentificationLine, signalReadPeerIdentificationLine, signalSendIdentification, signalSendIdentification, signalSessionClosed, signalSessionClosed, signalSessionCreated, signalSessionCreated, signalSessionEstablished, signalSessionEstablished, signalSessionEvent, toStringMethods inherited from class AbstractKexFactoryManager
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactoriesMethods inherited from class AbstractInnerCloseable
doCloseGracefully, doCloseImmediatelyMethods inherited from class AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenerMethods inherited from class AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface AttributeRepository
attributeKeys, getAttribute, getAttributesCountMethods inherited from interface AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeMethods inherited from interface ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolverMethods inherited from interface ClientAuthenticationManager
setUserAuthFactoriesNamesMethods inherited from interface ClientSession
createDynamicPortForwardingTracker, createExecChannel, createExecChannel, createLocalPortForwardingTracker, createLocalPortForwardingTracker, createRemotePortForwardingTracker, createShellChannel, executeRemoteCommand, executeRemoteCommand, executeRemoteCommand, executeRemoteCommand, executeRemoteCommand, executeRemoteCommand, waitForMethods inherited from interface Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListenerMethods inherited from interface KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandlerMethods inherited from interface 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 MutableUserHolder
setUsernameMethods inherited from interface PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListenerMethods inherited from interface PortForwardingInformationProvider
getBoundLocalPortForwards, getBoundRemotePortForward, getLocalForwardsBindings, getRemoteForwardsBindings, getStartedLocalPortForwards, getStartedRemotePortForwards, isLocalPortForwardingStartedForPort, isRemotePortForwardingStartedForPortMethods inherited from interface PortForwardingManager
startLocalPortForwardingMethods inherited from interface PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmptyMethods inherited from interface ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandlerMethods inherited from interface Session
createBuffer, createBuffer, disconnect, getAuthTimeout, getAuthTimeoutStart, getIdleTimeout, getIdleTimeoutStart, getIoSession, getKex, getLocalAddress, getRemoteAddress, getService, getTimeoutStatus, prepareBuffer, reExchangeKeys, request, request, request, request, resetAuthTimeout, resetIdleTimeout, resolveAttribute, sendDebugMessage, sendIgnoreMessage, setAuthenticated, writePacket, writePacket, writePacket, writePacketMethods inherited from interface SessionContext
getCipherInformation, getClientKexProposals, getClientVersion, getCompressionInformation, getKexNegotiationResult, getKexState, getMacInformation, getNegotiatedKexParameter, getServerKexProposals, getServerVersion, getSessionId, isAuthenticated, isServerSessionMethods inherited from interface SessionDisconnectHandlerManager
getSessionDisconnectHandler, setSessionDisconnectHandlerMethods inherited from interface SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatMethods inherited from interface SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListenerMethods inherited from interface SignatureFactoriesHolder
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNamesMethods inherited from interface SignatureFactoriesManager
setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNamesMethods inherited from interface UnknownChannelReferenceHandlerManager
getUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandlerMethods inherited from interface UserAuthFactoriesManager
getUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNamesMethods inherited from interface UsernameHolder
getUsername
-
Field Details
-
authFuture
The authentication future created by the last call toauth();nullbefore the first call toauth(). Volatile because of unsynchronized access inupdateCurrentSessionState(Collection). -
beforeAuthErrorHolder
-
authErrorHolder
Also guards setting an earlyError and the authFuture together. -
initialServiceRequestSent
-
metadataMap
-
-
Constructor Details
-
ClientSessionImpl
- Throws:
Exception
-
-
Method Details
-
start
Description copied from class:AbstractSessionStarts the SSH protocol. Invoked by the framework after the session object was fully created, and afterSessionListener.sessionCreated(org.apache.sshd.common.session.Session)has been invoked.- Specified by:
startin classAbstractSession- Throws:
Exception- on errors
-
initializeCurrentService
Description copied from class:AbstractSessionCreates a newCurrentServiceinstance managing this session's current SSH service.This initialization method is invoked once from the
AbstractSessionconstructor. Do not rely on subclass fields being initialized.- Overrides:
initializeCurrentServicein classAbstractSession- Returns:
- a new
CurrentServiceinstance for the session
-
getCurrentServices
-
getServices
- Overrides:
getServicesin classAbstractSession
-
auth
Description copied from interface:ClientSessionStarts the authentication process. User identities will be tried until the server successfully authenticate the user. User identities must be provided before calling this method usingClientAuthenticationManager.addPasswordIdentity(String)orClientAuthenticationManager.addPublicKeyIdentity(java.security.KeyPair).- Returns:
- the authentication future
- Throws:
IOException- if failed to generate the future- See Also:
-
exceptionCaught
Description copied from class:SessionHelperHandle 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.- Specified by:
exceptionCaughtin interfaceSession- Overrides:
exceptionCaughtin classSessionHelper- Parameters:
t- the exception to process
-
preClose
protected void preClose()Description copied from class:AbstractCloseablepreClose is guaranteed to be called before doCloseGracefully or doCloseImmediately. When preClose() is called, isClosing() == true- Overrides:
preClosein classAbstractSession
-
handleDisconnect
- Overrides:
handleDisconnectin classSessionHelper- Throws:
Exception
-
signalAuthFailure
-
nextServiceName
-
switchToNextService
- Throws:
IOException
-
signalSessionEvent
Description copied from class:SessionHelperSends a session event to all currently registered session listeners- Overrides:
signalSessionEventin classSessionHelper- Parameters:
event- The event to send- Throws:
Exception- If any of the registered listeners threw an exception.
-
sendInitialServiceRequest
- Throws:
IOException
-
waitFor
public Set<ClientSession.ClientSessionEvent> waitFor(Collection<ClientSession.ClientSessionEvent> mask, long timeout) Description copied from interface:ClientSessionWait for any one of a specific state to be signaled.- Parameters:
mask- The requestClientSession.ClientSessionEvents masktimeout- Wait time in milliseconds - non-positive means forever- Returns:
- The actual state that was detected either due to the mask yielding one of the states or due to
timeout (in which case the
ClientSession.ClientSessionEvent.TIMEOUTvalue is set)
-
getSessionState
- Returns:
- A snapshot of the current session state
- See Also:
-
updateCurrentSessionState
protected <C extends Collection<ClientSession.ClientSessionEvent>> C updateCurrentSessionState(C state) -
getMetadataMap
Description copied from interface:ClientSessionAccess to the metadata.- Returns:
- The metadata
Map- Note: access to the map is notsynchronizedin any way - up to the user to take care of mutual exclusion if necessary
-