public class ClientSessionImpl extends AbstractSession implements ClientSession
CloseableUtils.AbstractCloseable.StateSession.AttributeKey<T>, Session.TimeoutStatus| Modifier and Type | Field and Description |
|---|---|
protected AuthFuture |
authFuture |
static Comparator<Object> |
KEYPAIR_IDENTITY_COMPARATOR
|
static Comparator<Object> |
PASSWORD_IDENTITY_COMPARATOR
Compares 2 password identities - returns zero ONLY if both compared
objects are
Strings and equal to each other |
attributes, authed, authTimeoutMs, authTimeoutTimestamp, clientProposal, clientVersion, currentService, decodeLock, decoderBuffer, decoderLength, decoderState, DEFAULT_SSH_VERSION_PREFIX, disconnectTimeoutMs, encodeLock, factoryManager, i_c, i_s, idleTimeoutMs, idleTimeoutTimestamp, inBytesCount, inCipher, inCipherSize, inCompression, inMac, inMacResult, inPacketsCount, ioSession, isServer, kex, kexState, lastKeyTimeValue, listeners, negotiationResult, outBytesCount, outCipher, outCipherSize, outCompression, outMac, outPacketsCount, pendingPackets, random, reexchangeFuture, requestLock, requestResult, seqi, seqo, serverProposal, serverVersion, SESSION, sessionId, sessionListenerProxy, timeoutStatus, uncompressBuffer, usernamecloseFuture, lock, statelogAUTHED, CLOSED, TIMEOUT, WAIT_AUTH| Constructor and Description |
|---|
ClientSessionImpl(ClientFactoryManager client,
IoSession session) |
| Modifier and Type | Method and Description |
|---|---|
void |
addPasswordIdentity(String password) |
void |
addPublicKeyIdentity(KeyPair kp) |
AuthFuture |
auth()
Starts the authentication process.
|
protected void |
checkKeys() |
ClientChannel |
createChannel(String type)
Create a channel of the given type.
|
ClientChannel |
createChannel(String type,
String subType)
Create a channel of the given type and sub-type.
|
ChannelDirectTcpip |
createDirectTcpipChannel(SshdSocketAddress local,
SshdSocketAddress remote)
Create a direct tcp-ip channel which can be used to stream data to a remote port from the server.
|
ChannelExec |
createExecChannel(String command)
Create a channel to execute a command.
|
ScpClient |
createScpClient()
Create an SCP client from this session.
|
ScpClient |
createScpClient(ScpTransferEventListener listener)
Create an SCP client from this session.
|
SftpClient |
createSftpClient()
Create an SFTP client from this session.
|
SftpClient |
createSftpClient(SftpVersionSelector selector) |
FileSystem |
createSftpFileSystem() |
FileSystem |
createSftpFileSystem(int readBufferSize,
int writeBufferSize) |
FileSystem |
createSftpFileSystem(SftpVersionSelector selector) |
FileSystem |
createSftpFileSystem(SftpVersionSelector selector,
int readBufferSize,
int writeBufferSize) |
ChannelShell |
createShellChannel()
Create a channel to start a shell.
|
ChannelSubsystem |
createSubsystemChannel(String subsystem)
Create a subsystem channel.
|
protected int |
findIdentityIndex(Comparator<? super Object> comp,
Object target) |
ClientFactoryManager |
getFactoryManager() |
Map<Object,Object> |
getMetadataMap()
Access to the metadata.
|
ScpTransferEventListener |
getScpTransferEventListener() |
protected Service[] |
getServices() |
UserInteraction |
getUserInteraction() |
protected void |
handleMessage(Buffer buffer)
Abstract method for processing incoming decoded packets.
|
protected boolean |
readIdentification(Buffer buffer)
Read the other side identification.
|
protected void |
receiveKexInit(Map<KexProposalOption,String> proposal,
byte[] seed) |
String |
removePasswordIdentity(String password) |
KeyPair |
removePublicKeyIdentity(KeyPair kp) |
protected String |
resolveAvailableSignaturesProposal(FactoryManager manager) |
protected void |
sendClientIdentification() |
protected void |
sendEvent(SessionListener.Event event) |
protected void |
sendInitialServiceRequest() |
protected byte[] |
sendKexInit(Map<KexProposalOption,String> proposal)
Send the key exchange initialization packet.
|
protected void |
setKexSeed(byte... seed) |
void |
setScpTransferEventListener(ScpTransferEventListener listener) |
void |
setUserInteraction(UserInteraction userInteraction) |
SshdSocketAddress |
startDynamicPortForwarding(SshdSocketAddress local)
Start dynamic local port forwarding using a SOCKS proxy.
|
SshdSocketAddress |
startLocalPortForwarding(SshdSocketAddress local,
SshdSocketAddress remote)
Start forwarding the given local address on the client to the given address on the server.
|
SshdSocketAddress |
startRemotePortForwarding(SshdSocketAddress remote,
SshdSocketAddress local)
Start forwarding tcpip from the given address on the server to the
given address on the client.
|
void |
startService(String name) |
void |
stopDynamicPortForwarding(SshdSocketAddress local)
Stop a previously started dynamic port forwarding.
|
void |
stopLocalPortForwarding(SshdSocketAddress local)
Stop forwarding the given local address.
|
void |
stopRemotePortForwarding(SshdSocketAddress remote)
Stop forwarding of the given remote address.
|
void |
switchToNextService() |
SshFuture |
switchToNoneCipher()
Switch to a none cipher for performance.
|
int |
waitFor(int mask,
long timeout)
Wait for a specific state.
|
addListener, attachSession, checkForTimeouts, checkRekey, createBuffer, createBuffer, createProposal, decode, disconnect, doCloseImmediately, doHandleMessage, doReadIdentification, doWritePacket, exceptionCaught, getAttribute, getAuthTimeout, getClientVersion, getIdleTimeout, getInnerCloseable, getIntProperty, getIoSession, getKex, getLock, getLongProperty, getNegotiatedKexParameter, getServerVersion, getService, getSession, getSession, getSessionId, getTimeoutStatus, getUsername, isAuthenticated, mergeProposals, messageReceived, negotiate, notImplemented, receiveKexInit, receiveKexInit, receiveNewKeys, reExchangeKeys, removeListener, request, requestFailure, requestSuccess, resetIdleTimeout, resolveAvailableSignaturesProposal, sendIdentification, sendKexInit, sendNewKeys, serviceAccept, setAttribute, setAuthenticated, setNegotiationResult, setUsername, toString, validateKexState, writePacket, writePacketdoCloseGracefullybuilder, close, isClosed, isClosing, preCloseclose, isOpenclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddListener, createBuffer, createBuffer, disconnect, exceptionCaught, getAttribute, getAuthTimeout, getClientVersion, getIdleTimeout, getIntProperty, getIoSession, getKex, getNegotiatedKexParameter, getServerVersion, getService, getSessionId, getTimeoutStatus, getUsername, isAuthenticated, reExchangeKeys, removeListener, request, resetIdleTimeout, setAttribute, setAuthenticated, setUsername, writePacket, writePacketpublic static final Comparator<Object> PASSWORD_IDENTITY_COMPARATOR
Strings and equal to each otherpublic static final Comparator<Object> KEYPAIR_IDENTITY_COMPARATOR
protected AuthFuture authFuture
public ClientSessionImpl(ClientFactoryManager client, IoSession session) throws Exception
Exceptionprotected Service[] getServices()
getServices in class AbstractSessionpublic ClientFactoryManager getFactoryManager()
getFactoryManager in interface ClientSessiongetFactoryManager in interface SessiongetFactoryManager in class AbstractSessionFactoryManager that has created this session, can not be nullpublic void addPasswordIdentity(String password)
addPasswordIdentity in interface ClientSessionpassword - Password to be added - may not be null/emptypublic String removePasswordIdentity(String password)
removePasswordIdentity in interface ClientSessionpassword - The password to remove - ignored if null/emptyClientSession.addPasswordIdentity(String) - or null if no
match foundpublic void addPublicKeyIdentity(KeyPair kp)
addPublicKeyIdentity in interface ClientSessionkp - The KeyPair to add - may not be nullpublic KeyPair removePublicKeyIdentity(KeyPair kp)
removePublicKeyIdentity in interface ClientSessionkp - The KeyPair to remove - ignored if nullKeyPair - same one that was added via
ClientSession.addPublicKeyIdentity(KeyPair) - or null if no
match foundprotected int findIdentityIndex(Comparator<? super Object> comp, Object target)
public UserInteraction getUserInteraction()
getUserInteraction in interface ClientSessionpublic void setUserInteraction(UserInteraction userInteraction)
setUserInteraction in interface ClientSessionpublic AuthFuture auth() throws IOException
ClientSessionClientSession.addPasswordIdentity(String) or ClientSession.addPublicKeyIdentity(java.security.KeyPair).auth in interface ClientSessionIOException - if failed to generate the futureClientSession.addPasswordIdentity(String),
ClientSession.addPublicKeyIdentity(java.security.KeyPair)public void switchToNextService()
throws IOException
IOExceptionpublic SshFuture switchToNoneCipher() throws IOException
ClientSessionSwitch to a none cipher for performance.
This should be done after the authentication phase has been performed. After such a switch, interactive channels are not allowed anymore. Both client and server must have been configured to support the none cipher. If that's not the case, the returned future will be set with an exception.
switchToNoneCipher in interface ClientSessionSshFuture that can be used to wait for the exchange
to be finishedIOException - if a key exchange is already runningpublic ClientChannel createChannel(String type) throws IOException
ClientSessioncreateChannel(type, null).createChannel in interface ClientSessiontype - The channel typeClientChannelIOException - If failed to create the requested channelpublic ClientChannel createChannel(String type, String subType) throws IOException
ClientSessioncreateChannel in interface ClientSessiontype - The channel typesubType - The channel sub-typeClientChannelIOException - If failed to create the requested channelpublic ChannelShell createShellChannel() throws IOException
ClientSessioncreateShellChannel in interface ClientSessionChannelShellIOException - If failed to create the requested channelpublic ChannelExec createExecChannel(String command) throws IOException
ClientSessioncreateExecChannel in interface ClientSessioncommand - The command to executeChannelExecIOException - If failed to create the requested channelpublic ChannelSubsystem createSubsystemChannel(String subsystem) throws IOException
ClientSessioncreateSubsystemChannel in interface ClientSessionsubsystem - The subsystem nameChannelSubsystemIOException - If failed to create the requested channelpublic ChannelDirectTcpip createDirectTcpipChannel(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
ClientSessioncreateDirectTcpipChannel in interface ClientSessionlocal - The local addressremote - The remote addressChannelDirectTcpipIOException - If failed to create the requested channelpublic ScpTransferEventListener getScpTransferEventListener()
getScpTransferEventListener in interface ClientSessionScpTransferEventListener set via
ClientSession.setScpTransferEventListener(ScpTransferEventListener)public void setScpTransferEventListener(ScpTransferEventListener listener)
setScpTransferEventListener in interface ClientSessionlistener - A default ScpTransferEventListener that can be used
to receive information about the SCP operations - may be null
to indicate no more events are requiredClientSession.createScpClient(ScpTransferEventListener)public ScpClient createScpClient()
ClientSessioncreateScpClient in interface ClientSessionScpClient instance. Note: uses the currently
registered ScpTransferEventListener if anyClientSession.setScpTransferEventListener(ScpTransferEventListener)public ScpClient createScpClient(ScpTransferEventListener listener)
ClientSessioncreateScpClient in interface ClientSessionlistener - A ScpTransferEventListener that can be used
to receive information about the SCP operations - may be null
to indicate no more events are required. Note: this listener
is used instead of any listener set via ClientSession.setScpTransferEventListener(ScpTransferEventListener)ScpClient instancepublic SftpClient createSftpClient() throws IOException
ClientSessioncreateSftpClient in interface ClientSessionSftpClientIOException - if failed to create the clientpublic SftpClient createSftpClient(SftpVersionSelector selector) throws IOException
createSftpClient in interface ClientSessionselector - The SftpVersionSelector to use - Note:
if the server does not support versions re-negotiation then the
selector will be presented with only one "choice" - the
current versionSftpClientIOException - If failed to create the client or re-negotiatepublic FileSystem createSftpFileSystem() throws IOException
createSftpFileSystem in interface ClientSessionIOExceptionpublic FileSystem createSftpFileSystem(SftpVersionSelector selector) throws IOException
createSftpFileSystem in interface ClientSessionIOExceptionpublic FileSystem createSftpFileSystem(int readBufferSize, int writeBufferSize) throws IOException
createSftpFileSystem in interface ClientSessionIOExceptionpublic FileSystem createSftpFileSystem(SftpVersionSelector selector, int readBufferSize, int writeBufferSize) throws IOException
createSftpFileSystem in interface ClientSessionIOExceptionpublic SshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
ClientSessionstartLocalPortForwarding in interface ClientSessionlocal - The local addressremote - The remote addressSshdSocketAddressIOException - If failed to create the requested bindingpublic void stopLocalPortForwarding(SshdSocketAddress local) throws IOException
ClientSessionstopLocalPortForwarding in interface ClientSessionlocal - The local addressIOException - If failed to cancel the requested bindingpublic SshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws IOException
ClientSessionStart forwarding tcpip from the given address on the server to the given address on the client.
The remote host name is the address to bind to on the server:startRemotePortForwarding in interface ClientSessionremote - The remote addresslocal - The local addressSshdSocketAddressIOException - If failed to create the requested bindingpublic void stopRemotePortForwarding(SshdSocketAddress remote) throws IOException
ClientSessionstopRemotePortForwarding in interface ClientSessionremote - The remote addressIOException - If failed to cancel the requested bindingpublic SshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws IOException
ClientSessionstartDynamicPortForwarding in interface ClientSessionlocal - The local addressSshdSocketAddressIOException - If failed to create the requested bindingpublic void stopDynamicPortForwarding(SshdSocketAddress local) throws IOException
ClientSessionstopDynamicPortForwarding in interface ClientSessionlocal - The local addressIOException - If failed to cancel the requested bindingprotected void handleMessage(Buffer buffer) throws Exception
AbstractSessionhandleMessage in class AbstractSessionbuffer - the buffer containing the packetException - if an exeption occurs while handling this packet.public int waitFor(int mask,
long timeout)
ClientSessionwaitFor in interface ClientSessionmask - The request masktimeout - Wait time in milliseconds - non-positive means foreverClientSession.TIMEOUT
bit is set)protected boolean readIdentification(Buffer buffer) throws IOException
AbstractSessionAbstractSession.doReadIdentification(org.apache.sshd.common.util.buffer.Buffer, boolean) and
store the result in the needed property.readIdentification in class AbstractSessionbuffer - the buffer containing the remote identificationtrue if the identification has been fully read or
false if more data is neededIOException - if an error occurs such as a bad protocol versionprotected void sendClientIdentification()
protected byte[] sendKexInit(Map<KexProposalOption,String> proposal) throws IOException
AbstractSessionsendKexInit in class AbstractSessionproposal - our proposal for key exchange negotiationIOException - if an error occurred sending the packetprotected void setKexSeed(byte... seed)
setKexSeed in class AbstractSessionseed - The result of the KEXINIT handshake - required for correct
session key establishmentprotected String resolveAvailableSignaturesProposal(FactoryManager manager)
resolveAvailableSignaturesProposal in class AbstractSessionmanager - The FactoryManagernull/empty if no proposalprotected void receiveKexInit(Map<KexProposalOption,String> proposal, byte[] seed) throws IOException
receiveKexInit in class AbstractSessionIOExceptionprotected void checkKeys()
throws SshException
checkKeys in class AbstractSessionSshExceptionprotected void sendEvent(SessionListener.Event event) throws IOException
sendEvent in class AbstractSessionIOExceptionprotected void sendInitialServiceRequest()
throws IOException
IOExceptionpublic void startService(String name) throws Exception
startService in interface Sessionname - Service nameException - If failed to start itpublic Map<Object,Object> getMetadataMap()
ClientSessiongetMetadataMap in interface ClientSessionMapCopyright © 2008–2015 The Apache Software Foundation. All rights reserved.