Package org.apache.sshd.server.channel
Class ChannelSession
- java.lang.Object
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.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
-
-
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>
-
-
Field Summary
Fields Modifier and Type Field Description protected ChannelAsyncOutputStreamasyncErrprotected ChannelAsyncOutputStreamasyncOutprotected CloseFuturecommandExitFutureprotected CommandcommandInstanceprotected java.util.concurrent.atomic.AtomicBooleancommandStartedstatic java.util.List<ChannelRequestHandler>DEFAULT_HANDLERSprotected StandardEnvironmentenvprotected java.io.OutputStreamerrprotected BufferextendedDataBufferprotected ChannelDataReceiverextendedDataWriterprotected java.io.OutputStreamoutprotected ChannelDataReceiverreceiverprotected BufferreceiverBufferprotected java.lang.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(java.util.Collection<? extends RequestHandler<Channel>> handlers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddEnvVariable(java.lang.String name, java.lang.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(java.lang.String requestType, Buffer buffer, boolean wantReply)protected RequestHandler.ResulthandleAgentForwardingParsed(java.lang.String requestType)protected RequestHandler.ResulthandleBreak(Buffer buffer, boolean wantReply)protected RequestHandler.ResulthandleBreakParsed(long breakLength)protected RequestHandler.ResulthandleEnv(Buffer buffer, boolean wantReply)protected RequestHandler.ResulthandleEnvParsed(java.lang.String name, java.lang.String value)voidhandleEof()Invoked whenSSH_MSG_CHANNEL_EOFreceivedprotected RequestHandler.ResulthandleExec(java.lang.String request, Buffer buffer, boolean wantReply)protected RequestHandler.ResulthandleExecParsed(java.lang.String request, java.lang.String commandLine)protected RequestHandler.ResulthandleInternalRequest(java.lang.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(java.lang.String term, int tColumns, int tRows, int tWidth, int tHeight, java.util.Map<PtyMode,java.lang.Integer> ptyModes)protected RequestHandler.ResulthandleShell(java.lang.String request, Buffer buffer, boolean wantReply)protected RequestHandler.ResulthandleShellParsed(java.lang.String request)protected RequestHandler.ResulthandleSignal(Buffer buffer, boolean wantReply)protected RequestHandler.ResulthandleSignalParsed(java.lang.String name)protected RequestHandler.ResulthandleSubsystem(java.lang.String request, Buffer buffer, boolean wantReply)protected RequestHandler.ResulthandleSubsystemParsed(java.lang.String request, java.lang.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(java.lang.String requestType, Buffer buffer, boolean wantReply)protected RequestHandler.ResulthandleX11ForwardingParsed(java.lang.String requestType, ServerSession session, boolean singleConnection, java.lang.String authProtocol, java.lang.String authCookie, int screenId)protected booleanisValidXauth(java.lang.String auth)protected booleanmayWrite()protected RequestHandler.ResultprepareChannelCommand(java.lang.String request, Command cmd)protected CommandprepareCommand(java.lang.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, java.lang.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 java.util.List<ChannelRequestHandler> DEFAULT_HANDLERS
-
type
protected java.lang.String type
-
asyncOut
protected ChannelAsyncOutputStream asyncOut
-
asyncErr
protected ChannelAsyncOutputStream asyncErr
-
out
protected java.io.OutputStream out
-
err
protected java.io.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 java.util.concurrent.atomic.AtomicBoolean commandStarted
-
env
protected final StandardEnvironment env
-
commandExitFuture
protected final CloseFuture commandExitFuture
-
-
Constructor Detail
-
ChannelSession
public ChannelSession()
-
ChannelSession
public ChannelSession(java.util.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 java.io.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:
java.io.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 java.io.IOExceptionDescription copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_EOFreceived- Specified by:
handleEofin interfaceChannel- Overrides:
handleEofin classAbstractChannel- Throws:
java.io.IOException- If failed to handle the message
-
doWriteData
protected void doWriteData(byte[] data, int off, long len) throws java.io.IOException- Specified by:
doWriteDatain classAbstractChannel- Throws:
java.io.IOException
-
doWriteExtendedData
protected void doWriteExtendedData(byte[] data, int off, long len) throws java.io.IOException- Specified by:
doWriteExtendedDatain classAbstractChannel- Throws:
java.io.IOException
-
handleInternalRequest
protected RequestHandler.Result handleInternalRequest(java.lang.String requestType, boolean wantReply, Buffer buffer) throws java.io.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:
java.io.IOException- If failed to process the request internally
-
sendResponse
protected IoWriteFuture sendResponse(Buffer buffer, java.lang.String req, RequestHandler.Result result, boolean wantReply) throws java.io.IOException
- Overrides:
sendResponsein classAbstractChannel- Throws:
java.io.IOException
-
handleEnv
protected RequestHandler.Result handleEnv(Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handleEnvParsed
protected RequestHandler.Result handleEnvParsed(java.lang.String name, java.lang.String value) throws java.io.IOException
- Throws:
java.io.IOException
-
handlePtyReq
protected RequestHandler.Result handlePtyReq(Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handlePtyReqParsed
protected RequestHandler.Result handlePtyReqParsed(java.lang.String term, int tColumns, int tRows, int tWidth, int tHeight, java.util.Map<PtyMode,java.lang.Integer> ptyModes) throws java.io.IOException
- Throws:
java.io.IOException
-
handleWindowChange
protected RequestHandler.Result handleWindowChange(Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handleWindowChangeParsed
protected RequestHandler.Result handleWindowChangeParsed(int tColumns, int tRows, int tWidth, int tHeight) throws java.io.IOException
- Throws:
java.io.IOException
-
handleSignal
protected RequestHandler.Result handleSignal(Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handleSignalParsed
protected RequestHandler.Result handleSignalParsed(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
handleBreak
protected RequestHandler.Result handleBreak(Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handleBreakParsed
protected RequestHandler.Result handleBreakParsed(long breakLength) throws java.io.IOException
- Throws:
java.io.IOException
-
handleShell
protected RequestHandler.Result handleShell(java.lang.String request, Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handleShellParsed
protected RequestHandler.Result handleShellParsed(java.lang.String request) throws java.io.IOException
- Throws:
java.io.IOException
-
handleExec
protected RequestHandler.Result handleExec(java.lang.String request, Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handleExecParsed
protected RequestHandler.Result handleExecParsed(java.lang.String request, java.lang.String commandLine) throws java.io.IOException
- Throws:
java.io.IOException
-
handleSubsystem
protected RequestHandler.Result handleSubsystem(java.lang.String request, Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handleSubsystemParsed
protected RequestHandler.Result handleSubsystemParsed(java.lang.String request, java.lang.String subsystem) throws java.io.IOException
- Throws:
java.io.IOException
-
prepareChannelCommand
protected RequestHandler.Result prepareChannelCommand(java.lang.String request, Command cmd) throws java.io.IOException
- Throws:
java.io.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(java.lang.String requestType, Command command) throws java.io.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:
java.io.IOException- If failed to prepare the command
-
getPtyModeValue
protected int getPtyModeValue(PtyMode mode)
-
handleAgentForwarding
protected RequestHandler.Result handleAgentForwarding(java.lang.String requestType, Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handleAgentForwardingParsed
protected RequestHandler.Result handleAgentForwardingParsed(java.lang.String requestType) throws java.io.IOException
- Throws:
java.io.IOException
-
handleX11Forwarding
protected RequestHandler.Result handleX11Forwarding(java.lang.String requestType, Buffer buffer, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
handleX11ForwardingParsed
protected RequestHandler.Result handleX11ForwardingParsed(java.lang.String requestType, ServerSession session, boolean singleConnection, java.lang.String authProtocol, java.lang.String authCookie, int screenId) throws java.io.IOException
- Throws:
java.io.IOException
-
isValidXauth
protected boolean isValidXauth(java.lang.String auth)
-
addEnvVariable
protected void addEnvVariable(java.lang.String name, java.lang.String value)
-
getEnvironment
public StandardEnvironment getEnvironment()
-
closeShell
protected void closeShell(int exitValue, boolean closeImmediately) throws java.io.IOException- Throws:
java.io.IOException
-
-