Top Description Inners Fields Constructors Methods
org.apache.sshd.server.channel

public Class ChannelSession

extends AbstractServerChannel
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.time.Duration, java.util.Collection, .Collections, .HashMap, .List, .Map, .Objects, .TimerTask, java.util.concurrent.ScheduledExecutorService, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean, org.apache.sshd.agent.SshAgent, .SshAgentFactory, org.apache.sshd.agent.common.AgentForwardSupport, org.apache.sshd.common.Closeable, .FactoryManager, .PropertyResolverUtils, .RuntimeSshException, .SshConstants, org.apache.sshd.common.channel.Channel, .ChannelAsyncOutputStream, .ChannelOutputStream, .ChannelRequestHandler, .LocalWindow, .PtyMode, .RemoteWindow, .RequestHandler, org.apache.sshd.common.file.FileSystemAware, .FileSystemFactory, org.apache.sshd.common.future.CloseFuture, .DefaultCloseFuture, .SshFutureListener, org.apache.sshd.common.io.IoWriteFuture, org.apache.sshd.common.session.Session, org.apache.sshd.common.util.GenericUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.Buffer, .ByteArrayBuffer, org.apache.sshd.common.util.closeable.IoBaseCloseable, org.apache.sshd.common.util.io.IoUtils, org.apache.sshd.common.util.io.output.LoggingFilterOutputStream, org.apache.sshd.core.CoreModuleProperties, org.apache.sshd.server.Environment, .ServerFactoryManager, .Signal, .StandardEnvironment, org.apache.sshd.server.command.AsyncCommandInputStreamAware, .AsyncCommandStreamsAware, .Command, .CommandFactory, org.apache.sshd.server.forward.AgentForwardingFilter, .X11ForwardingFilter, org.apache.sshd.server.session.ServerSession, .ServerSessionAware, org.apache.sshd.server.shell.ShellFactory, org.apache.sshd.server.subsystem.SubsystemFactory, org.apache.sshd.server.x11.X11ForwardSupport

Server side channel session
Author
Apache MINA SSHD Project

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class

Field Summary

Modifier and TypeField and Description
protected ChannelAsyncOutputStream
protected ChannelAsyncOutputStream
protected final CloseFuture
protected Command
protected final AtomicBoolean
public static final List<ChannelRequestHandler>
protected final StandardEnvironment
protected OutputStream
protected Buffer
protected ChannelDataReceiver
protected OutputStream
protected ChannelDataReceiver
protected Buffer
protected String
Inherited from org.apache.sshd.server.channel.AbstractServerChannel:
exitStatusSent

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
protected void
closeShell(int exitValue, boolean closeImmediately)

protected void
doWriteData(byte[] data, int off, long len)

Implements abstract org.apache.sshd.common.channel.AbstractChannel.doWriteData.

protected void
public StandardEnvironment
protected Closeable
protected int
public ServerSession
protected RequestHandler.Result
handleAgentForwarding(String requestType, Buffer buffer, boolean wantReply)

protected RequestHandler.Result
protected RequestHandler.Result
handleBreak(Buffer buffer, boolean wantReply)

protected RequestHandler.Result
handleBreakParsed(long breakLength)

protected RequestHandler.Result
handleEnv(Buffer buffer, boolean wantReply)

protected RequestHandler.Result
public void
protected RequestHandler.Result
handleExec(String request, Buffer buffer, boolean wantReply)

protected RequestHandler.Result
handleExecParsed(String request, String commandLine)

protected RequestHandler.Result
handleInternalRequest(String
The request type
requestType
,
boolean
Whether reply is requested
wantReply
,
Buffer
The Buffer containing extra request-specific data
buffer
)

Overrides org.apache.sshd.common.channel.AbstractChannel.handleInternalRequest.

Called by 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
protected RequestHandler.Result
handleSignal(Buffer buffer, boolean wantReply)

protected RequestHandler.Result
protected RequestHandler.Result
handleSubsystem(String request, Buffer buffer, boolean wantReply)

protected RequestHandler.Result
handleSubsystemParsed(String request, String subsystem)

public void
handleWindowAdjust(Buffer
The rest of the message data Buffer after decoding the channel identifiers
buffer
)

Overrides org.apache.sshd.common.channel.AbstractChannel.handleWindowAdjust.

Implements org.apache.sshd.common.channel.Channel.handleWindowAdjust.

Invoked when SSH_MSG_CHANNEL_WINDOW_ADJUST received

protected 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
protected boolean
protected RequestHandler.Result
protected Command

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.

prepareCommand
(String
The request that caused the command to be created
requestType
,
Command
The created Command - may be null
command
)

Called by prepareChannelCommand(String, Command) in order to set up the command's streams, session, file-system, exit callback, etc..

protected IoWriteFuture
public void
public void
setExtendedDataWriter(ChannelDataReceiver extendedDataWriter)

A special ChannelDataReceiver 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).

Inherited from org.apache.sshd.server.channel.AbstractServerChannel:
doInithandleOpenFailurehandleOpenSuccessopensendExitStatus

Field Detail

asyncErrback to summary
protected ChannelAsyncOutputStream asyncErr
asyncOutback to summary
protected ChannelAsyncOutputStream asyncOut
commandExitFutureback to summary
protected final CloseFuture commandExitFuture
commandInstanceback to summary
protected Command commandInstance
commandStartedback to summary
protected final AtomicBoolean commandStarted
DEFAULT_HANDLERSback to summary
public static final List<ChannelRequestHandler> DEFAULT_HANDLERS
envback to summary
protected final StandardEnvironment env
errback to summary
protected OutputStream err
extendedDataBufferback to summary
protected Buffer extendedDataBuffer
extendedDataWriterback to summary
protected ChannelDataReceiver extendedDataWriter
outback to summary
protected OutputStream out
receiverback to summary
protected ChannelDataReceiver receiver
receiverBufferback to summary
protected Buffer receiverBuffer
typeback to summary
protected String type

Constructor Detail

ChannelSessionback to summary
public ChannelSession()
ChannelSessionback to summary
public ChannelSession(Collection<? extends RequestHandler<Channel>> handlers)

Method Detail

addEnvVariableback to summary
protected void addEnvVariable(String name, String value)
closeImmediately0back to summary
protected void closeImmediately0()
closeShellback to summary
protected void closeShell(int exitValue, boolean closeImmediately) throws IOException
doWriteDataback to summary
protected void doWriteData(byte[] data, int off, long len) throws IOException

Implements abstract org.apache.sshd.common.channel.AbstractChannel.doWriteData.

Annotations
@Override
doWriteExtendedDataback to summary
protected void doWriteExtendedData(byte[] data, int off, long len) throws IOException

Implements abstract org.apache.sshd.common.channel.AbstractChannel.doWriteExtendedData.

Annotations
@Override
getEnvironmentback to summary
public StandardEnvironment getEnvironment()
getInnerCloseableback to summary
protected Closeable getInnerCloseable()

Overrides org.apache.sshd.common.channel.AbstractChannel.getInnerCloseable.

Annotations
@Override
getPtyModeValueback to summary
protected int getPtyModeValue(PtyMode mode)
getSessionback to summary
public ServerSession getSession()

Overrides org.apache.sshd.common.channel.AbstractChannel.getSession.

Implements org.apache.sshd.common.session.SessionHolder.getSession.

Annotations
@Override
handleAgentForwardingback to summary
protected RequestHandler.Result handleAgentForwarding(String requestType, Buffer buffer, boolean wantReply) throws IOException
handleAgentForwardingParsedback to summary
protected RequestHandler.Result handleAgentForwardingParsed(String requestType) throws IOException
handleBreakback to summary
protected RequestHandler.Result handleBreak(Buffer buffer, boolean wantReply) throws IOException
handleBreakParsedback to summary
protected RequestHandler.Result handleBreakParsed(long breakLength) throws IOException
handleEnvback to summary
protected RequestHandler.Result handleEnv(Buffer buffer, boolean wantReply) throws IOException
handleEnvParsedback to summary
protected RequestHandler.Result handleEnvParsed(String name, String value) throws IOException
handleEofback to summary
public void handleEof() throws IOException

Overrides org.apache.sshd.common.channel.AbstractChannel.handleEof.

Implements org.apache.sshd.common.channel.Channel.handleEof.

Doc from org.apache.sshd.common.channel.Channel.handleEof.

Invoked when SSH_MSG_CHANNEL_EOF received

Annotations
@Override
Exceptions
IOException:
If failed to handle the message
handleExecback to summary
protected RequestHandler.Result handleExec(String request, Buffer buffer, boolean wantReply) throws IOException
handleExecParsedback to summary
protected RequestHandler.Result handleExecParsed(String request, String commandLine) throws IOException
handleInternalRequestback to summary
protected RequestHandler.Result handleInternalRequest(String requestType, boolean wantReply, Buffer buffer) throws IOException

Overrides org.apache.sshd.common.channel.AbstractChannel.handleInternalRequest.

Doc from org.apache.sshd.common.channel.AbstractChannel.handleInternalRequest.

Called by handleUnknownChannelRequest(String, boolean, Buffer) in order to allow channel request handling if none of the registered handlers processed the request - last chance.

Parameters
requestType:String

The request type

wantReply:boolean

Whether reply is requested

buffer:Buffer

The Buffer containing extra request-specific data

Returns:RequestHandler.Result

The handling result - if null or Unsupported and reply is required then a failure message will be sent

Annotations
@Override
Exceptions
IOException:
If failed to process the request internally
handlePtyReqback to summary
protected RequestHandler.Result handlePtyReq(Buffer buffer, boolean wantReply) throws IOException
handlePtyReqParsedback to summary
protected RequestHandler.Result handlePtyReqParsed(String term, int tColumns, int tRows, int tWidth, int tHeight, Map<PtyMode, Integer> ptyModes) throws IOException
handleShellback to summary
protected RequestHandler.Result handleShell(String request, Buffer buffer, boolean wantReply) throws IOException
handleShellParsedback to summary
protected RequestHandler.Result handleShellParsed(String request) throws IOException
handleSignalback to summary
protected RequestHandler.Result handleSignal(Buffer buffer, boolean wantReply) throws IOException
handleSignalParsedback to summary
protected RequestHandler.Result handleSignalParsed(String name) throws IOException
handleSubsystemback to summary
protected RequestHandler.Result handleSubsystem(String request, Buffer buffer, boolean wantReply) throws IOException
handleSubsystemParsedback to summary
protected RequestHandler.Result handleSubsystemParsed(String request, String subsystem) throws IOException
handleWindowAdjustback to summary
public void handleWindowAdjust(Buffer buffer) throws IOException

Overrides org.apache.sshd.common.channel.AbstractChannel.handleWindowAdjust.

Implements org.apache.sshd.common.channel.Channel.handleWindowAdjust.

Doc from org.apache.sshd.common.channel.Channel.handleWindowAdjust.

Invoked when SSH_MSG_CHANNEL_WINDOW_ADJUST received

Parameters
buffer:Buffer

The rest of the message data Buffer after decoding the channel identifiers

Annotations
@Override
Exceptions
IOException:
If failed to handle the message
handleWindowChangeback to summary
protected RequestHandler.Result handleWindowChange(Buffer buffer, boolean wantReply) throws IOException
handleWindowChangeParsedback to summary
protected RequestHandler.Result handleWindowChangeParsed(int tColumns, int tRows, int tWidth, int tHeight) throws IOException
handleX11Forwardingback to summary
protected RequestHandler.Result handleX11Forwarding(String requestType, Buffer buffer, boolean wantReply) throws IOException
handleX11ForwardingParsedback to summary
protected RequestHandler.Result handleX11ForwardingParsed(String requestType, ServerSession session, boolean singleConnection, String authProtocol, String authCookie, int screenId) throws IOException
isValidXauthback to summary
protected boolean isValidXauth(String auth)
mayWriteback to summary
protected boolean mayWrite()

Overrides org.apache.sshd.common.channel.AbstractChannel.mayWrite.

Annotations
@Override
prepareChannelCommandback to summary
protected RequestHandler.Result prepareChannelCommand(String request, Command cmd) throws IOException
prepareCommandback to summary
protected Command prepareCommand(String requestType, Command command) throws IOException

Called by prepareChannelCommand(String, Command) in order to set up the command's streams, session, file-system, exit callback, etc..

Parameters
requestType:String

The request that caused the command to be created

command:Command

The created Command - may be null

Returns:Command

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.

Exceptions
IOException:
If failed to prepare the command
sendResponseback to summary
protected IoWriteFuture sendResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException

Overrides org.apache.sshd.common.channel.AbstractChannel.sendResponse.

Annotations
@Override
setDataReceiverback to summary
public void setDataReceiver(ChannelDataReceiver receiver)

For Command to install ChannelDataReceiver. When you do this, Command#setInputStream(java.io.InputStream) or org.apache.sshd.server.command.AsyncCommand#setIoInputStream(org.apache.sshd.common.io.IoInputStream) will no longer be invoked. If you call this method from Command#start(ChannelSession, Environment), the input stream you received in Command#setInputStream(java.io.InputStream) will not read any data.

Parameters
receiver:ChannelDataReceiver

The ChannelDataReceiver instance

setExtendedDataWriterback to summary
public void setExtendedDataWriter(ChannelDataReceiver extendedDataWriter)

A special ChannelDataReceiver 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 implement ChannelSessionAware.

Parameters
extendedDataWriter:ChannelDataReceiver

The ChannelDataReceiver.

org.apache.sshd.server.channel back to summary

public Class ChannelSession.CommandCloseable

extends IoBaseCloseable
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addCloseFutureListener(SshFutureListener<CloseFuture>
The notification SshFutureListener - never null
listener
)

Implements org.apache.sshd.common.Closeable.addCloseFutureListener.

Pre-register a listener to be informed when resource is closed.

public CloseFuture
close(boolean
true if the resource should be shut down abruptly, false for a graceful close
immediately
)

Implements org.apache.sshd.common.Closeable.close.

Close this resource asynchronously and return a future.

public boolean
isClosed()

Implements org.apache.sshd.common.Closeable.isClosed.

Returns true if this object has been closed.

public boolean
isClosing()

Implements org.apache.sshd.common.Closeable.isClosing.

Returns true if the close(boolean) method has been called.

public void
removeCloseFutureListener(SshFutureListener<CloseFuture>
The register SshFutureListener - never null. Ignored if not registered or resource already closed
listener
)

Implements org.apache.sshd.common.Closeable.removeCloseFutureListener.

Remove a pre-registered close event listener

Constructor Detail

CommandCloseableback to summary
public CommandCloseable()

Method Detail

addCloseFutureListenerback to summary
public void addCloseFutureListener(SshFutureListener<CloseFuture> listener)

Implements org.apache.sshd.common.Closeable.addCloseFutureListener.

Doc from org.apache.sshd.common.Closeable.addCloseFutureListener.

Pre-register a listener to be informed when resource is closed. If resource is already closed, the listener will be invoked immediately and not registered for future notification

Parameters
listener:SshFutureListener<CloseFuture>

The notification SshFutureListener - never null

Annotations
@Override
closeback to summary
public CloseFuture close(boolean immediately)

Implements org.apache.sshd.common.Closeable.close.

Doc from org.apache.sshd.common.Closeable.close.

Close this resource asynchronously and return a future. Resources support two closing modes: a graceful mode which will cleanly close the resource and an immediate mode which will close the resources abruptly.

Parameters
immediately:boolean

true if the resource should be shut down abruptly, false for a graceful close

Returns:CloseFuture

a CloseFuture representing the close request

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Implements org.apache.sshd.common.Closeable.isClosed.

Doc from org.apache.sshd.common.Closeable.isClosed.

Returns true if this object has been closed.

Returns:boolean

true if closing

Annotations
@Override
isClosingback to summary
public boolean isClosing()

Implements org.apache.sshd.common.Closeable.isClosing.

Doc from org.apache.sshd.common.Closeable.isClosing.

Returns true if the close(boolean) method has been called. Note that this method will return true even if this isClosed() returns true.

Returns:boolean

true if closing

Annotations
@Override
removeCloseFutureListenerback to summary
public void removeCloseFutureListener(SshFutureListener<CloseFuture> listener)

Implements org.apache.sshd.common.Closeable.removeCloseFutureListener.

Doc from org.apache.sshd.common.Closeable.removeCloseFutureListener.

Remove a pre-registered close event listener

Parameters
listener:SshFutureListener<CloseFuture>

The register SshFutureListener - never null. Ignored if not registered or resource already closed

Annotations
@Override