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.PacketValidator
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>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ChannelAsyncOutputStream
protected ChannelAsyncOutputStream
protected final CloseFuture
protected Command
protected final AtomicBoolean
static final List
<ChannelRequestHandler> protected final StandardEnvironment
protected OutputStream
protected Buffer
protected ChannelDataReceiver
protected OutputStream
protected ChannelDataReceiver
protected Buffer
protected String
Fields inherited from class org.apache.sshd.server.channel.AbstractServerChannel
exitStatusSent
Fields 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, unregisterSignaled
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.Channel
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEM
Fields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONE
Fields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addEnvVariable
(String name, String value) protected void
protected void
closeShell
(int exitValue, boolean closeImmediately) protected void
doWriteData
(byte[] data, int off, long len) protected void
doWriteExtendedData
(byte[] data, int off, long len) protected Closeable
protected int
getPtyModeValue
(PtyMode mode) protected RequestHandler.Result
handleAgentForwarding
(String requestType, Buffer buffer, boolean wantReply) protected RequestHandler.Result
handleAgentForwardingParsed
(String requestType) protected RequestHandler.Result
handleBreak
(Buffer buffer, boolean wantReply) protected RequestHandler.Result
handleBreakParsed
(long breakLength) protected RequestHandler.Result
protected RequestHandler.Result
handleEnvParsed
(String name, String value) void
Invoked whenSSH_MSG_CHANNEL_EOF
receivedprotected RequestHandler.Result
handleExec
(String request, Buffer buffer, boolean wantReply) protected RequestHandler.Result
handleExecParsed
(String request, String commandLine) protected RequestHandler.Result
handleInternalRequest
(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.Result
handlePtyReq
(Buffer buffer, boolean wantReply) protected RequestHandler.Result
handlePtyReqParsed
(String term, int tColumns, int tRows, int tWidth, int tHeight, Map<PtyMode, Integer> ptyModes) protected RequestHandler.Result
handleShell
(String request, Buffer buffer, boolean wantReply) protected RequestHandler.Result
handleShellParsed
(String request) protected RequestHandler.Result
handleSignal
(Buffer buffer, boolean wantReply) protected RequestHandler.Result
handleSignalParsed
(String name) protected RequestHandler.Result
handleSubsystem
(String request, Buffer buffer, boolean wantReply) protected RequestHandler.Result
handleSubsystemParsed
(String request, String subsystem) void
handleWindowAdjust
(Buffer buffer) Invoked whenSSH_MSG_CHANNEL_WINDOW_ADJUST
receivedprotected RequestHandler.Result
handleWindowChange
(Buffer buffer, boolean wantReply) protected RequestHandler.Result
handleWindowChangeParsed
(int tColumns, int tRows, int tWidth, int tHeight) protected RequestHandler.Result
handleX11Forwarding
(String requestType, Buffer buffer, boolean wantReply) protected RequestHandler.Result
handleX11ForwardingParsed
(String requestType, ServerSession session, boolean singleConnection, String authProtocol, String authCookie, int screenId) protected boolean
isValidXauth
(String auth) protected boolean
mayWrite()
protected RequestHandler.Result
prepareChannelCommand
(String request, Command cmd) protected Command
prepareCommand
(String requestType, Command command) Called byprepareChannelCommand(String, Command)
in order to set up the command's streams, session, file-system, exit callback, etc..protected IoWriteFuture
sendResponse
(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) void
setDataReceiver
(ChannelDataReceiver receiver) ForCommand
to installChannelDataReceiver
.void
setExtendedDataWriter
(ChannelDataReceiver extendedDataWriter) A specialChannelDataReceiver
that 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, sendExitStatus
Methods 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, writePacket
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.Channel
addRequestHandler, addRequestHandlers, getLocalWindow, getRecipient, getRemoteWindow, getRequestHandlers, handleChannelRegistrationResult, handleChannelUnregistration, handleClose, handleData, handleExtendedData, handleFailure, handleRequest, handleSuccess, init, isEofSignalled, isInitialized, removeRequestHandler, removeRequestHandlers, resolveAttribute, writePacket
Methods inherited from interface org.apache.sshd.common.channel.ChannelIdentifier
getChannelId
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.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
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.server.channel.ServerChannel
getServerSession
Methods 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:
getSession
in interfaceSessionHolder<Session>
- Overrides:
getSession
in classAbstractChannel
-
handleWindowAdjust
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_WINDOW_ADJUST
received- Specified by:
handleWindowAdjust
in interfaceChannel
- Overrides:
handleWindowAdjust
in classAbstractChannel
- Parameters:
buffer
- The rest of the message dataBuffer
after decoding the channel identifiers- Throws:
IOException
- If failed to handle the message
-
mayWrite
protected boolean mayWrite()- Overrides:
mayWrite
in classAbstractChannel
-
getInnerCloseable
- Overrides:
getInnerCloseable
in classAbstractChannel
-
closeImmediately0
protected void closeImmediately0() -
handleEof
Description copied from interface:Channel
Invoked whenSSH_MSG_CHANNEL_EOF
received- Specified by:
handleEof
in interfaceChannel
- Overrides:
handleEof
in classAbstractChannel
- Throws:
IOException
- If failed to handle the message
-
doWriteData
- Specified by:
doWriteData
in classAbstractChannel
- Throws:
IOException
-
doWriteExtendedData
- Specified by:
doWriteExtendedData
in classAbstractChannel
- Throws:
IOException
-
handleInternalRequest
protected RequestHandler.Result handleInternalRequest(String requestType, boolean wantReply, Buffer buffer) throws IOException Description copied from class:AbstractChannel
Called byAbstractChannel.handleUnknownChannelRequest(String, boolean, Buffer)
in order to allow channel request handling if none of the registered handlers processed the request - last chance.- Overrides:
handleInternalRequest
in classAbstractChannel
- Parameters:
requestType
- The request typewantReply
- Whether reply is requestedbuffer
- TheBuffer
containing extra request-specific data- Returns:
- The handling result - if
null
orUnsupported
and 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:
sendResponse
in 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
ForCommand
to 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
- TheChannelDataReceiver
instance
-
setExtendedDataWriter
A specialChannelDataReceiver
that 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
null
then 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
-
isValidXauth
-
addEnvVariable
-
getEnvironment
-
closeShell
- Throws:
IOException
-