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
public class ChannelSession extends AbstractServerChannel
Server side channel session- Author:
- Apache MINA SSHD Project
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classChannelSession.CommandCloseable-
Nested 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 extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected ChannelAsyncOutputStreamasyncErrprotected ChannelAsyncOutputStreamasyncOutprotected CloseFuturecommandExitFutureprotected CommandcommandInstanceprotected AtomicBooleancommandStartedstatic List<ChannelRequestHandler>DEFAULT_HANDLERSprotected StandardEnvironmentenvprotected OutputStreamerrprotected BufferextendedDataBufferprotected ChannelDataReceiverextendedDataWriterprotected OutputStreamoutprotected ChannelDataReceiverreceiverprotected BufferreceiverBufferprotected Stringtype-
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 Constructor Description ChannelSession()ChannelSession(Collection<? extends RequestHandler<Channel>> handlers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddEnvVariable(String name, String value)protected voidcloseImmediately0()protected voidcloseShell(int exitValue, boolean closeImmediately)protected voiddoWriteData(byte[] data, int off, long len)protected voiddoWriteExtendedData(byte[] data, int off, long len)StandardEnvironmentgetEnvironment()protected CloseablegetInnerCloseable()protected intgetPtyModeValue(PtyMode mode)ServerSessiongetSession()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.ResulthandleEnv(Buffer buffer, boolean wantReply)protected RequestHandler.ResulthandleEnvParsed(String name, String value)voidhandleEof()Invoked 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, 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 Detail
-
DEFAULT_HANDLERS
public static final List<ChannelRequestHandler> DEFAULT_HANDLERS
-
type
protected String type
-
asyncOut
protected ChannelAsyncOutputStream asyncOut
-
asyncErr
protected ChannelAsyncOutputStream asyncErr
-
out
protected OutputStream out
-
err
protected OutputStream err
-
commandInstance
protected Command commandInstance
-
receiver
protected ChannelDataReceiver receiver
-
extendedDataWriter
protected ChannelDataReceiver extendedDataWriter
-
receiverBuffer
protected Buffer receiverBuffer
-
extendedDataBuffer
protected Buffer extendedDataBuffer
-
commandStarted
protected final AtomicBoolean commandStarted
-
env
protected final StandardEnvironment env
-
commandExitFuture
protected final CloseFuture commandExitFuture
-
-
Constructor Detail
-
ChannelSession
public ChannelSession()
-
ChannelSession
public ChannelSession(Collection<? extends RequestHandler<Channel>> handlers)
-
-
Method Detail
-
getSession
public ServerSession getSession()
- Specified by:
getSessionin interfaceSessionHolder<Session>- Overrides:
getSessionin classAbstractChannel
-
handleWindowAdjust
public void handleWindowAdjust(Buffer buffer) throws IOException
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
protected Closeable getInnerCloseable()
- Overrides:
getInnerCloseablein classAbstractChannel
-
closeImmediately0
protected void closeImmediately0()
-
handleEof
public void handleEof() throws IOExceptionDescription copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_EOFreceived- Specified by:
handleEofin interfaceChannel- Overrides:
handleEofin classAbstractChannel- Throws:
IOException- If failed to handle the message
-
doWriteData
protected void doWriteData(byte[] data, int off, long len) throws IOException- Specified by:
doWriteDatain classAbstractChannel- Throws:
IOException
-
doWriteExtendedData
protected void doWriteExtendedData(byte[] data, int off, long len) throws IOException- 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
protected RequestHandler.Result handleEnv(Buffer buffer, boolean wantReply) throws IOException
- Throws:
IOException
-
handleEnvParsed
protected RequestHandler.Result handleEnvParsed(String name, String value) throws IOException
- Throws:
IOException
-
handlePtyReq
protected RequestHandler.Result handlePtyReq(Buffer buffer, boolean wantReply) throws IOException
- 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
protected RequestHandler.Result handleSignal(Buffer buffer, boolean wantReply) throws IOException
- Throws:
IOException
-
handleSignalParsed
protected RequestHandler.Result handleSignalParsed(String name) throws IOException
- Throws:
IOException
-
handleBreak
protected RequestHandler.Result handleBreak(Buffer buffer, boolean wantReply) throws IOException
- Throws:
IOException
-
handleBreakParsed
protected RequestHandler.Result handleBreakParsed(long breakLength) throws IOException
- Throws:
IOException
-
handleShell
protected RequestHandler.Result handleShell(String request, Buffer buffer, boolean wantReply) throws IOException
- Throws:
IOException
-
handleShellParsed
protected RequestHandler.Result handleShellParsed(String request) throws IOException
- 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
public void setDataReceiver(ChannelDataReceiver receiver)
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
public void setExtendedDataWriter(ChannelDataReceiver extendedDataWriter)
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
protected Command prepareCommand(String requestType, Command command) throws IOException
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
protected int getPtyModeValue(PtyMode mode)
-
handleAgentForwarding
protected RequestHandler.Result handleAgentForwarding(String requestType, Buffer buffer, boolean wantReply) throws IOException
- Throws:
IOException
-
handleAgentForwardingParsed
protected RequestHandler.Result handleAgentForwardingParsed(String requestType) throws IOException
- 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
-
getEnvironment
public StandardEnvironment getEnvironment()
-
closeShell
protected void closeShell(int exitValue, boolean closeImmediately) throws IOException- Throws:
IOException
-
-