Package org.apache.sshd.client.session
Class ClientSessionImpl
- java.lang.Object
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.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
public class ClientSessionImpl extends AbstractClientSession
The default implementation of aClientSession
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classClientSessionImpl.ServicesEncapsulates and protects against concurrent access the service switching.-
Nested classes/interfaces inherited from class org.apache.sshd.common.session.helpers.AbstractSession
AbstractSession.MessageCodingSettings
-
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T>
-
Nested classes/interfaces inherited from interface org.apache.sshd.client.session.ClientSession
ClientSession.ClientSessionEvent
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
SessionHeartbeatController.HeartbeatType
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<java.lang.Throwable>authErrorHolderAlso guards setting an earlyError and the authFuture together.private AuthFutureauthFutureprivate java.util.concurrent.atomic.AtomicReference<java.lang.Throwable>beforeAuthErrorHolderprivate java.util.concurrent.atomic.AtomicBooleaninitialServiceRequestSentprivate java.util.Map<java.lang.Object,java.lang.Object>metadataMapFor clients to store their own metadata-
Fields inherited from class org.apache.sshd.client.session.AbstractClientSession
sendImmediateClientIdentification, sendImmediateKexInit
-
Fields inherited from class org.apache.sshd.common.session.helpers.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, unmodServerProposal
-
Fields inherited from class org.apache.sshd.common.session.helpers.SessionHelper
authStart, idleStart, initialKexProposal
-
Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, state
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONE
-
Fields inherited from interface org.apache.sshd.client.session.ClientSession
REMOTE_COMMAND_WAIT_EVENTS
-
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
-
-
Constructor Summary
Constructors Constructor Description ClientSessionImpl(ClientFactoryManager client, IoSession ioSession)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AuthFutureauth()Starts the authentication process.voidexceptionCaught(java.lang.Throwable t)Handle any exceptions that occurred on this session.private ClientSessionImpl.ServicesgetCurrentServices()java.util.Map<java.lang.Object,java.lang.Object>getMetadataMap()Access to the metadata.protected java.util.List<Service>getServices()java.util.Set<ClientSession.ClientSessionEvent>getSessionState()protected voidhandleDisconnect(int code, java.lang.String msg, java.lang.String lang, Buffer buffer)protected CurrentServiceinitializeCurrentService()Creates a newCurrentServiceinstance managing this session's current SSH service.protected java.lang.StringnextServiceName()protected voidpreClose()preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.protected voidsendInitialServiceRequest()protected voidsignalAuthFailure(java.lang.Throwable t)protected voidsignalSessionEvent(SessionListener.Event event)Sends a session event to all currently registered session listenersvoidstart()Starts the SSH protocol.voidswitchToNextService()protected <C extends java.util.Collection<ClientSession.ClientSessionEvent>>
CupdateCurrentSessionState(C state)java.util.Set<ClientSession.ClientSessionEvent>waitFor(java.util.Collection<ClientSession.ClientSessionEvent> mask, long timeout)Wait for any one of a specific state to be signaled.-
Methods inherited from class org.apache.sshd.client.session.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, switchToNoneCipher
-
Methods inherited from class org.apache.sshd.common.session.helpers.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, writePacket
-
Methods inherited from class org.apache.sshd.common.session.helpers.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, toString
-
Methods inherited from class org.apache.sshd.common.kex.AbstractKexFactoryManager
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactories
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediately
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
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.client.ClientAuthenticationManager
setUserAuthFactoriesNames
-
Methods inherited from interface org.apache.sshd.client.session.ClientSession
createDynamicPortForwardingTracker, createExecChannel, createExecChannel, createLocalPortForwardingTracker, createLocalPortForwardingTracker, createRemotePortForwardingTracker, createShellChannel, executeRemoteCommand, executeRemoteCommand, executeRemoteCommand, executeRemoteCommand, executeRemoteCommand, executeRemoteCommand, waitFor
-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
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.forward.PortForwardingManager
startLocalPortForwarding
-
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.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, writePacket
-
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.UserAuthFactoriesManager
getUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNames
-
Methods inherited from interface org.apache.sshd.common.auth.UsernameHolder
getUsername
-
-
-
-
Field Detail
-
authFuture
private volatile AuthFuture authFuture
The authentication future created by the last call toauth();nullbefore the first call toauth(). Volatile because of unsynchronized access inupdateCurrentSessionState(Collection).
-
beforeAuthErrorHolder
private final java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> beforeAuthErrorHolder
-
authErrorHolder
private final java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> authErrorHolder
Also guards setting an earlyError and the authFuture together.
-
initialServiceRequestSent
private final java.util.concurrent.atomic.AtomicBoolean initialServiceRequestSent
-
metadataMap
private java.util.Map<java.lang.Object,java.lang.Object> metadataMap
For clients to store their own metadata
-
-
Constructor Detail
-
ClientSessionImpl
public ClientSessionImpl(ClientFactoryManager client, IoSession ioSession) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-
Method Detail
-
start
public void start() throws java.lang.ExceptionDescription 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:
java.lang.Exception- on errors
-
initializeCurrentService
protected CurrentService 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
private ClientSessionImpl.Services getCurrentServices()
-
getServices
protected java.util.List<Service> getServices()
- Overrides:
getServicesin classAbstractSession
-
auth
public AuthFuture auth() throws java.io.IOException
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:
java.io.IOException- if failed to generate the future- See Also:
ClientAuthenticationManager.addPasswordIdentity(String),ClientAuthenticationManager.addPublicKeyIdentity(java.security.KeyPair)
-
exceptionCaught
public void exceptionCaught(java.lang.Throwable t)
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
protected void handleDisconnect(int code, java.lang.String msg, java.lang.String lang, Buffer buffer) throws java.lang.Exception- Overrides:
handleDisconnectin classSessionHelper- Throws:
java.lang.Exception
-
signalAuthFailure
protected void signalAuthFailure(java.lang.Throwable t)
-
nextServiceName
protected java.lang.String nextServiceName()
-
switchToNextService
public void switchToNextService() throws java.io.IOException- Throws:
java.io.IOException
-
signalSessionEvent
protected void signalSessionEvent(SessionListener.Event event) throws java.lang.Exception
Description copied from class:SessionHelperSends a session event to all currently registered session listeners- Overrides:
signalSessionEventin classSessionHelper- Parameters:
event- The event to send- Throws:
java.lang.Exception- If any of the registered listeners threw an exception.
-
sendInitialServiceRequest
protected void sendInitialServiceRequest() throws java.io.IOException- Throws:
java.io.IOException
-
waitFor
public java.util.Set<ClientSession.ClientSessionEvent> waitFor(java.util.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
public java.util.Set<ClientSession.ClientSessionEvent> getSessionState()
- Returns:
- A snapshot of the current session state
- See Also:
ClientSession.waitFor(Collection, long)
-
updateCurrentSessionState
protected <C extends java.util.Collection<ClientSession.ClientSessionEvent>> C updateCurrentSessionState(C state)
-
getMetadataMap
public java.util.Map<java.lang.Object,java.lang.Object> 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
-
-