public abstract class AbstractSession extends CloseableUtils.AbstractInnerCloseable implements Session
handleMessage(org.apache.sshd.common.util.Buffer)
method, which is dependant on the state and side of this session.
TODO: if there is any very big packet, decoderBuffer and uncompressBuffer will get quite big
and they won't be resized down at any time. Though the packet size is really limited
by the channel max packet size| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractSession.PendingWriteFuture
Future holding a packet pending key exchange termination.
|
Session.AttributeKey<T>| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<Session.AttributeKey<?>,java.lang.Object> |
attributes |
protected boolean |
authed
Boolean indicating if this session has been authenticated or not
|
protected java.lang.String[] |
clientProposal |
protected java.lang.String |
clientVersion |
protected Service |
currentService |
protected java.lang.Object |
decodeLock |
protected Buffer |
decoderBuffer |
protected int |
decoderLength |
protected int |
decoderState |
protected java.lang.Object |
encodeLock |
protected FactoryManager |
factoryManager
The factory manager used to retrieve factories of Ciphers, Macs and other objects
|
protected byte[] |
I_C |
protected byte[] |
I_S |
protected long |
inBytes |
protected Cipher |
inCipher |
protected int |
inCipherSize |
protected Compression |
inCompression |
protected Mac |
inMac |
protected byte[] |
inMacResult |
protected long |
inPackets |
protected IoSession |
ioSession
The underlying MINA session
|
protected boolean |
isServer
Client or server side
|
protected KeyExchange |
kex |
protected static int |
KEX_STATE_DONE |
protected static int |
KEX_STATE_INIT |
protected static int |
KEX_STATE_KEYS |
protected static int |
KEX_STATE_RUN |
protected java.util.concurrent.atomic.AtomicInteger |
kexState |
protected long |
lastKeyTime |
protected java.util.List<SessionListener> |
listeners
Session listener
|
protected java.lang.String[] |
negotiated |
protected long |
outBytes |
protected Cipher |
outCipher |
protected int |
outCipherSize |
protected Compression |
outCompression |
protected Mac |
outMac |
protected long |
outPackets |
protected java.util.Queue<AbstractSession.PendingWriteFuture> |
pendingPackets |
protected Random |
random
The pseudo random generator
|
protected DefaultSshFuture |
reexchangeFuture |
protected java.lang.Object |
requestLock |
protected java.util.concurrent.atomic.AtomicReference<Buffer> |
requestResult |
protected long |
seqi |
protected long |
seqo |
protected java.lang.String[] |
serverProposal |
protected java.lang.String |
serverVersion |
static java.lang.String |
SESSION
Name of the property where this session is stored in the attributes of the
underlying MINA session.
|
protected byte[] |
sessionId |
protected Buffer |
uncompressBuffer |
protected java.lang.String |
username
The name of the authenticated useer
|
CLOSED, closeFuture, GRACEFUL, IMMEDIATE, lock, log, OPENED, state| Constructor and Description |
|---|
AbstractSession(boolean isServer,
FactoryManager factoryManager,
IoSession ioSession)
Create a new session.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(SessionListener listener)
Add a session |listener|.
|
static void |
attachSession(IoSession ioSession,
AbstractSession session)
Attach a session to the MINA session
|
protected abstract void |
checkKeys() |
protected void |
checkRekey() |
Buffer |
createBuffer(byte cmd)
Create a new buffer for the specified SSH packet and reserve the needed space
(5 bytes) for the packet header.
|
Buffer |
createBuffer(byte cmd,
int len)
Create a new buffer for the specified SSH packet and reserve the needed space
(5 bytes) for the packet header.
|
protected java.lang.String[] |
createProposal(java.lang.String hostKeyTypes)
Create our proposal for SSH negotiation
|
protected void |
decode()
Decode the incoming buffer and handle packets as needed.
|
void |
disconnect(int reason,
java.lang.String msg)
Send a disconnect packet with the given reason and message.
|
protected void |
doHandleMessage(Buffer buffer) |
protected java.lang.String |
doReadIdentification(Buffer buffer)
Read the remote identification from this buffer.
|
protected IoWriteFuture |
doWritePacket(Buffer buffer) |
void |
exceptionCaught(java.lang.Throwable t)
Handle any exceptions that occured on this session.
|
<T> T |
getAttribute(Session.AttributeKey<T> key)
Returns the value of the user-defined attribute of this session.
|
java.lang.String |
getClientVersion()
Retrieve the client version for this session.
|
FactoryManager |
getFactoryManager()
Retrieve the factory manager
|
protected Closeable |
getInnerCloseable() |
int |
getIntProperty(java.lang.String name,
int defaultValue)
Retrieve a configuration property as an integer
|
IoSession |
getIoSession()
Retrieve the mina session
|
KeyExchange |
getKex() |
java.lang.Object |
getLock() |
long |
getLongProperty(java.lang.String name,
long defaultValue) |
java.lang.String |
getServerVersion()
Retrieve the server version for this session.
|
protected Service[] |
getServices() |
static AbstractSession |
getSession(IoSession ioSession)
Retrieve the session from the MINA session.
|
static AbstractSession |
getSession(IoSession ioSession,
boolean allowNull)
Retrieve the session from the MINA session.
|
byte[] |
getSessionId() |
java.lang.String |
getUsername()
Retrieve the name of the user authenticated on this session
or null if the session has not been authenticated yet.
|
protected void |
handleMessage(Buffer buffer)
Abstract method for processing incoming decoded packets.
|
boolean |
isAuthenticated() |
void |
messageReceived(Readable buffer)
Main input point for the MINA framework.
|
protected void |
negotiate()
Compute the negotiated proposals by merging the client and
server proposal.
|
protected void |
notImplemented()
Send an unimplemented packet.
|
protected void |
postClose() |
protected abstract boolean |
readIdentification(Buffer buffer)
Read the other side identification.
|
protected abstract void |
receiveKexInit(Buffer buffer) |
protected byte[] |
receiveKexInit(Buffer buffer,
java.lang.String[] proposal)
Receive the remote key exchange init message.
|
protected void |
receiveNewKeys()
Put new keys into use.
|
SshFuture |
reExchangeKeys()
Initiate a new key exchange.
|
void |
removeListener(SessionListener listener)
Remove a session |listener|.
|
Buffer |
request(Buffer buffer)
Send a global request and wait for the response.
|
protected void |
requestFailure(Buffer buffer) |
protected void |
requestSuccess(Buffer buffer) |
abstract void |
resetIdleTimeout() |
protected void |
sendEvent(SessionListener.Event event) |
protected void |
sendIdentification(java.lang.String ident)
Send our identification.
|
protected abstract void |
sendKexInit() |
protected byte[] |
sendKexInit(java.lang.String[] proposal)
Send the key exchange initialization packet.
|
protected void |
sendNewKeys()
Send a message to put new keys into use.
|
protected void |
serviceAccept() |
<T,E extends T> |
setAttribute(Session.AttributeKey<T> key,
E value)
Sets a user-defined attribute.
|
void |
setAuthenticated() |
void |
setUsername(java.lang.String username) |
abstract void |
startService(java.lang.String name) |
java.lang.String |
toString() |
IoWriteFuture |
writePacket(Buffer buffer)
Encode and send the given buffer.
|
doCloseGracefully, doCloseImmediatelyclosepublic static final java.lang.String SESSION
getSession(IoSession, boolean)
and attachSession(IoSession, AbstractSession).protected static final int KEX_STATE_INIT
protected static final int KEX_STATE_RUN
protected static final int KEX_STATE_KEYS
protected static final int KEX_STATE_DONE
protected final boolean isServer
protected final FactoryManager factoryManager
protected final IoSession ioSession
protected final Random random
protected boolean authed
protected java.lang.String username
protected final java.util.List<SessionListener> listeners
protected byte[] sessionId
protected java.lang.String serverVersion
protected java.lang.String clientVersion
protected java.lang.String[] serverProposal
protected java.lang.String[] clientProposal
protected java.lang.String[] negotiated
protected byte[] I_C
protected byte[] I_S
protected KeyExchange kex
protected final java.util.concurrent.atomic.AtomicInteger kexState
protected DefaultSshFuture reexchangeFuture
protected Cipher outCipher
protected Cipher inCipher
protected int outCipherSize
protected int inCipherSize
protected Mac outMac
protected Mac inMac
protected byte[] inMacResult
protected Compression outCompression
protected Compression inCompression
protected long seqi
protected long seqo
protected Buffer decoderBuffer
protected Buffer uncompressBuffer
protected int decoderState
protected int decoderLength
protected final java.lang.Object encodeLock
protected final java.lang.Object decodeLock
protected final java.lang.Object requestLock
protected final java.util.concurrent.atomic.AtomicReference<Buffer> requestResult
protected final java.util.Map<Session.AttributeKey<?>,java.lang.Object> attributes
protected volatile long inPackets
protected volatile long outPackets
protected volatile long inBytes
protected volatile long outBytes
protected volatile long lastKeyTime
protected final java.util.Queue<AbstractSession.PendingWriteFuture> pendingPackets
protected Service currentService
public AbstractSession(boolean isServer,
FactoryManager factoryManager,
IoSession ioSession)
factoryManager - the factory managerioSession - the underlying MINA sessionpublic static AbstractSession getSession(IoSession ioSession)
ioSession - the MINA sessionpublic static AbstractSession getSession(IoSession ioSession, boolean allowNull)
false,
an IllegalStateException will be thrown, else a null will
be returnedioSession - the MINA sessionallowNull - if true, a null value may be
returned if no session is attachednullpublic static void attachSession(IoSession ioSession, AbstractSession session)
ioSession - the MINA sessionsession - the session to attachpublic java.lang.String getServerVersion()
SessiongetServerVersion in interface Sessionpublic java.lang.String getClientVersion()
SessiongetClientVersion in interface Sessionpublic KeyExchange getKex()
public byte[] getSessionId()
public IoSession getIoSession()
public FactoryManager getFactoryManager()
getFactoryManager in interface Sessionpublic boolean isAuthenticated()
public void setUsername(java.lang.String username)
public void setAuthenticated()
throws java.io.IOException
java.io.IOExceptionpublic void messageReceived(Readable buffer) throws java.lang.Exception
decode() method.buffer - the new buffer receivedjava.lang.Exception - if an error occurs while decoding or handling the dataprotected void handleMessage(Buffer buffer) throws java.lang.Exception
buffer - the buffer containing the packetjava.lang.Exception - if an exeption occurs while handling this packet.protected void doHandleMessage(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionpublic void exceptionCaught(java.lang.Throwable t)
SshException.exceptionCaught in interface Sessiont - the exception to processprotected Closeable getInnerCloseable()
getInnerCloseable in class CloseableUtils.AbstractInnerCloseableprotected void postClose()
postClose in class CloseableUtils.AbstractCloseableprotected Service[] getServices()
public IoWriteFuture writePacket(Buffer buffer) throws java.io.IOException
writePacket in interface Sessionbuffer - the buffer to encode and sendjava.io.IOException - if an error occured when encoding sending the packetprotected IoWriteFuture doWritePacket(Buffer buffer) throws java.io.IOException
java.io.IOExceptionpublic Buffer request(Buffer buffer) throws java.io.IOException
public Buffer createBuffer(byte cmd)
SessioncreateBuffer in interface Sessioncmd - the SSH commandpublic Buffer createBuffer(byte cmd, int len)
createBuffer in interface Sessioncmd - the SSH commandlen - estimated number of bytes the buffer will hold, 0 if unknown.protected void decode()
throws java.lang.Exception
java.lang.Exceptionprotected void sendIdentification(java.lang.String ident)
ident - our identification to sendprotected abstract boolean readIdentification(Buffer buffer) throws java.io.IOException
doReadIdentification(org.apache.sshd.common.util.Buffer) and
store the result in the needed property.buffer - the buffer containing the remote identificationtrue if the identification has been fully read or
false if more data is neededjava.io.IOException - if an error occurs such as a bad protocol versionprotected java.lang.String doReadIdentification(Buffer buffer)
null value will be returned. Else the identification
string will be returned and the data read will be consumed from the buffer.buffer - the buffer containing the identification stringnull if more data is neededprotected java.lang.String[] createProposal(java.lang.String hostKeyTypes)
hostKeyTypes - the list of supported host key typesprotected byte[] sendKexInit(java.lang.String[] proposal)
throws java.io.IOException
proposal - our proposal for key exchange negotiationjava.io.IOException - if an error occurred sending the packetprotected byte[] receiveKexInit(Buffer buffer, java.lang.String[] proposal)
buffer - the buffer containing the key exchange init packetproposal - the remote proposal to fillprotected void sendNewKeys()
throws java.io.IOException
java.io.IOException - if an error occurs sending the messageprotected void receiveNewKeys()
throws java.lang.Exception
java.lang.Exception - if an error occurspublic void disconnect(int reason,
java.lang.String msg)
throws java.io.IOException
reason - the reason code for this disconnectmsg - the text messagejava.io.IOException - if an error occured sending the packetprotected void notImplemented()
throws java.io.IOException
java.io.IOException - if an error occurred sending the packetprotected void negotiate()
negotiated property.protected void requestSuccess(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionprotected void requestFailure(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionpublic int getIntProperty(java.lang.String name,
int defaultValue)
getIntProperty in interface Sessionname - the name of the propertydefaultValue - the default valuepublic long getLongProperty(java.lang.String name,
long defaultValue)
public <T> T getAttribute(Session.AttributeKey<T> key)
getAttribute in interface Sessionkey - the key of the attribute; must not be null.public <T,E extends T> T setAttribute(Session.AttributeKey<T> key, E value)
setAttribute in interface Sessionkey - the key of the attribute; must not be null.value - the value of the attribute; must not be null.public java.lang.String getUsername()
SessiongetUsername in interface Sessionpublic java.lang.Object getLock()
public void addListener(SessionListener listener)
addListener in interface Sessionlistener - the session listener to addpublic void removeListener(SessionListener listener)
removeListener in interface Sessionlistener - the session listener to removeprotected void sendEvent(SessionListener.Event event) throws java.io.IOException
java.io.IOExceptionpublic SshFuture reExchangeKeys() throws java.io.IOException
reExchangeKeys in interface Sessionjava.io.IOExceptionprotected void checkRekey()
throws java.io.IOException
java.io.IOExceptionprotected abstract void sendKexInit()
throws java.io.IOException
java.io.IOExceptionprotected abstract void checkKeys()
throws java.io.IOException
java.io.IOExceptionprotected abstract void receiveKexInit(Buffer buffer) throws java.io.IOException
java.io.IOExceptionprotected void serviceAccept()
throws java.io.IOException
java.io.IOExceptionpublic abstract void startService(java.lang.String name)
throws java.lang.Exception
java.lang.Exceptionpublic abstract void resetIdleTimeout()
public java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2008-2014 The Apache Software Foundation. All Rights Reserved.