Package org.apache.sshd.server.channel
Class ChannelSession
java.lang.Object
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,AttributeRepository,AttributeStore,Channel,ChannelIdentifier,ChannelListenerManager,ChannelStreamWriterResolver,ChannelStreamWriterResolverManager,Closeable,PropertyResolver,SessionContextHolder,SessionHolder<Session>,ExecutorServiceCarrier,ServerChannel,ServerSessionHolder
Server side channel session
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.sshd.common.channel.AbstractChannel
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulState, AbstractChannel.PacketValidatorNested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.StateNested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ChannelAsyncOutputStreamprotected ChannelAsyncOutputStreamprotected final CloseFutureprotected Commandprotected final AtomicBooleanstatic final List<ChannelRequestHandler> protected final StandardEnvironmentprotected OutputStreamprotected Bufferprotected ChannelDataReceiverprotected OutputStreamprotected ChannelDataReceiverprotected Bufferprotected StringFields inherited from class org.apache.sshd.server.channel.AbstractServerChannel
exitStatusSentFields inherited from class org.apache.sshd.common.channel.AbstractChannel
channelListenerProxy, channelListeners, closeSignaled, DEFAULT_PACKET_VALIDATOR, eofReceived, eofSent, gracefulFuture, gracefulState, initialized, RESPONSE_BUFFER_GROWTH_FACTOR, service, unregisterSignaledFields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, stateFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.common.channel.Channel
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMFields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONEFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddEnvVariable(String name, String value) protected voidprotected voidcloseShell(int exitValue, boolean closeImmediately) protected voiddoWriteData(byte[] data, int off, long len) protected voiddoWriteExtendedData(byte[] data, int off, long len) protected Closeableprotected intgetPtyModeValue(PtyMode mode) protected RequestHandler.ResulthandleAgentForwarding(String requestType, Buffer buffer, boolean wantReply) protected RequestHandler.ResulthandleAgentForwardingParsed(String requestType) protected RequestHandler.ResulthandleBreak(Buffer buffer, boolean wantReply) protected RequestHandler.ResulthandleBreakParsed(long breakLength) protected RequestHandler.Resultprotected RequestHandler.ResulthandleEnvParsed(String name, String value) voidInvoked whenSSH_MSG_CHANNEL_EOFreceivedprotected RequestHandler.ResulthandleExec(String request, Buffer buffer, boolean wantReply) protected RequestHandler.ResulthandleExecParsed(String request, String commandLine) protected RequestHandler.ResulthandleInternalRequest(String requestType, boolean wantReply, Buffer buffer) Called byAbstractChannel.handleUnknownChannelRequest(String, boolean, Buffer)in order to allow channel request handling if none of the registered handlers processed the request - last chance.protected RequestHandler.ResulthandlePtyReq(Buffer buffer, boolean wantReply) protected RequestHandler.ResulthandlePtyReqParsed(String term, int tColumns, int tRows, int tWidth, int tHeight, Map<PtyMode, Integer> ptyModes) protected RequestHandler.ResulthandleShell(String request, Buffer buffer, boolean wantReply) protected RequestHandler.ResulthandleShellParsed(String request) protected RequestHandler.ResulthandleSignal(Buffer buffer, boolean wantReply) protected RequestHandler.ResulthandleSignalParsed(String name) protected RequestHandler.ResulthandleSubsystem(String request, Buffer buffer, boolean wantReply) protected RequestHandler.ResulthandleSubsystemParsed(String request, String subsystem) voidhandleWindowAdjust(Buffer buffer) Invoked whenSSH_MSG_CHANNEL_WINDOW_ADJUSTreceivedprotected RequestHandler.ResulthandleWindowChange(Buffer buffer, boolean wantReply) protected RequestHandler.ResulthandleWindowChangeParsed(int tColumns, int tRows, int tWidth, int tHeight) protected RequestHandler.ResulthandleX11Forwarding(String requestType, Buffer buffer, boolean wantReply) protected RequestHandler.ResulthandleX11ForwardingParsed(String requestType, ServerSession session, boolean singleConnection, String authProtocol, String authCookie, int screenId) protected booleanmayWrite()protected RequestHandler.ResultprepareChannelCommand(String request, Command cmd) protected CommandprepareCommand(String requestType, Command command) Called byprepareChannelCommand(String, Command)in order to set up the command's streams, session, file-system, exit callback, etc..protected IoWriteFuturesendResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) voidsetDataReceiver(ChannelDataReceiver receiver) ForCommandto installChannelDataReceiver.voidsetExtendedDataWriter(ChannelDataReceiver extendedDataWriter) A specialChannelDataReceiverthat can be used to receive data sent as "extended" - usually STDERR.Methods inherited from class org.apache.sshd.server.channel.AbstractServerChannel
doInit, handleOpenFailure, handleOpenSuccess, open, sendExitStatusMethods inherited from class org.apache.sshd.common.channel.AbstractChannel
addChannelListener, addPendingRequest, addRequestHandler, attributeKeys, clearAttributes, computeAttributeIfAbsent, configureWindow, getAttribute, getAttributesCount, getChannelId, getChannelListenerProxy, getChannelStreamWriterResolver, getExecutorService, getLocalWindow, getPacketValidator, getParentPropertyResolver, getProperties, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelRequest, handleChannelUnregistration, handleClose, handleData, handleExtendedData, handleFailure, handleRequest, handleSuccess, handleUnknownChannelRequest, init, invokeChannelSignaller, isEofSent, isEofSignalled, isInitialized, notifyStateChanged, notifyStateChanged, preClose, removeAttribute, removeChannelListener, removePendingRequest, removeRequestHandler, resolveChannelStreamWriterResolver, sendEof, sendWindowAdjust, setAttribute, setChannelStreamWriterResolver, setPacketValidator, setRecipient, signalChannelClosed, signalChannelClosed, signalChannelInitialized, signalChannelInitialized, signalChannelOpenFailure, signalChannelOpenFailure, signalChannelOpenSuccess, signalChannelOpenSuccess, toString, validateIncomingDataSize, writePacketMethods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediatelyMethods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenerMethods 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, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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.Channel
addRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, writePacketMethods inherited from interface org.apache.sshd.common.channel.ChannelIdentifier
getChannelIdMethods 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.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmptyMethods inherited from interface org.apache.sshd.server.channel.ServerChannel
getServerSessionMethods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
Field Details
-
DEFAULT_HANDLERS
-
type
-
asyncOut
-
asyncErr
-
out
-
err
-
commandInstance
-
receiver
-
extendedDataWriter
-
receiverBuffer
-
extendedDataBuffer
-
commandStarted
-
env
-
commandExitFuture
-
-
Constructor Details
-
ChannelSession
public ChannelSession() -
ChannelSession
-
-
Method Details
-
getSession
- Specified by:
getSessionin interfaceSessionHolder<Session>- Overrides:
getSessionin classAbstractChannel
-
handleWindowAdjust
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_WINDOW_ADJUSTreceived- Specified by:
handleWindowAdjustin interfaceChannel- Overrides:
handleWindowAdjustin classAbstractChannel- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
IOException- If failed to handle the message
-
mayWrite
protected boolean mayWrite()- Overrides:
mayWritein classAbstractChannel
-
getInnerCloseable
- Overrides:
getInnerCloseablein classAbstractChannel
-
closeImmediately0
protected void closeImmediately0() -
handleEof
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_EOFreceived- Specified by:
handleEofin interfaceChannel- Overrides:
handleEofin classAbstractChannel- Throws:
IOException- If failed to handle the message
-
doWriteData
- Specified by:
doWriteDatain classAbstractChannel- Throws:
IOException
-
doWriteExtendedData
- Specified by:
doWriteExtendedDatain classAbstractChannel- Throws:
IOException
-
handleInternalRequest
protected RequestHandler.Result handleInternalRequest(String requestType, boolean wantReply, Buffer buffer) throws IOException Description copied from class:AbstractChannelCalled byAbstractChannel.handleUnknownChannelRequest(String, boolean, Buffer)in order to allow channel request handling if none of the registered handlers processed the request - last chance.- Overrides:
handleInternalRequestin classAbstractChannel- Parameters:
requestType- The request typewantReply- Whether reply is requestedbuffer- TheBuffercontaining extra request-specific data- Returns:
- The handling result - if
nullorUnsupportedand reply is required then a failure message will be sent - Throws:
IOException- If failed to process the request internally
-
sendResponse
protected IoWriteFuture sendResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException - Overrides:
sendResponsein classAbstractChannel- Throws:
IOException
-
handleEnv
- Throws:
IOException
-
handleEnvParsed
- Throws:
IOException
-
handlePtyReq
- Throws:
IOException
-
handlePtyReqParsed
protected RequestHandler.Result handlePtyReqParsed(String term, int tColumns, int tRows, int tWidth, int tHeight, Map<PtyMode, Integer> ptyModes) throws IOException- Throws:
IOException
-
handleWindowChange
protected RequestHandler.Result handleWindowChange(Buffer buffer, boolean wantReply) throws IOException - Throws:
IOException
-
handleWindowChangeParsed
protected RequestHandler.Result handleWindowChangeParsed(int tColumns, int tRows, int tWidth, int tHeight) throws IOException - Throws:
IOException
-
handleSignal
- Throws:
IOException
-
handleSignalParsed
- Throws:
IOException
-
handleBreak
- Throws:
IOException
-
handleBreakParsed
- Throws:
IOException
-
handleShell
protected RequestHandler.Result handleShell(String request, Buffer buffer, boolean wantReply) throws IOException - Throws:
IOException
-
handleShellParsed
- Throws:
IOException
-
handleExec
protected RequestHandler.Result handleExec(String request, Buffer buffer, boolean wantReply) throws IOException - Throws:
IOException
-
handleExecParsed
protected RequestHandler.Result handleExecParsed(String request, String commandLine) throws IOException - Throws:
IOException
-
handleSubsystem
protected RequestHandler.Result handleSubsystem(String request, Buffer buffer, boolean wantReply) throws IOException - Throws:
IOException
-
handleSubsystemParsed
protected RequestHandler.Result handleSubsystemParsed(String request, String subsystem) throws IOException - Throws:
IOException
-
prepareChannelCommand
protected RequestHandler.Result prepareChannelCommand(String request, Command cmd) throws IOException - Throws:
IOException
-
setDataReceiver
ForCommandto installChannelDataReceiver. When you do this,CommandDirectInputStreamAware.setInputStream(java.io.InputStream)orAsyncCommandInputStreamAware.setIoInputStream(org.apache.sshd.common.io.IoInputStream)will no longer be invoked. If you call this method fromCommand#start(ChannelSession, Environment), the input stream you received inCommandDirectInputStreamAware.setInputStream(java.io.InputStream)will not read any data.- Parameters:
receiver- TheChannelDataReceiverinstance
-
setExtendedDataWriter
A specialChannelDataReceiverthat can be used to receive data sent as "extended" - usually STDERR. Note: by default any such data sent to the channel session causes an exception, but specific implementations may choose to register such a receiver (e.g., for custom usage of the STDERR stream). A good place in the code to register such a writer would be in commands that also implementChannelSessionAware.- Parameters:
extendedDataWriter- TheChannelDataReceiver.
-
prepareCommand
Called byprepareChannelCommand(String, Command)in order to set up the command's streams, session, file-system, exit callback, etc..- Parameters:
requestType- The request that caused the command to be createdcommand- The createdCommand- may benull- Returns:
- The updated command instance - if
nullthen the request that initially caused the creation of the command is failed and the original command (if any) destroyed (eventually). Note: if a different command instance than the input one is returned, then it is up to the implementor to take care of the wrapping or destruction of the original command instance. - Throws:
IOException- If failed to prepare the command
-
getPtyModeValue
-
handleAgentForwarding
protected RequestHandler.Result handleAgentForwarding(String requestType, Buffer buffer, boolean wantReply) throws IOException - Throws:
IOException
-
handleAgentForwardingParsed
- Throws:
IOException
-
handleX11Forwarding
protected RequestHandler.Result handleX11Forwarding(String requestType, Buffer buffer, boolean wantReply) throws IOException - Throws:
IOException
-
handleX11ForwardingParsed
protected RequestHandler.Result handleX11ForwardingParsed(String requestType, ServerSession session, boolean singleConnection, String authProtocol, String authCookie, int screenId) throws IOException - Throws:
IOException
-
addEnvVariable
-
getEnvironment
-
closeShell
- Throws:
IOException
-