|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.sshd.common.session.AbstractSession
public abstract class AbstractSession
The AbstractSession handles all the basic SSH protocol such as key exchange, authentication,
encoding and decoding. Both server side and client side sessions should inherit from this
abstract class. Some basic packet processing methods are defined but the actual call to these
methods should be done from the 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
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.apache.sshd.common.Session |
|---|
Session.AttributeKey<T> |
| Field Summary | |
|---|---|
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.util.Map<java.lang.Integer,Channel> |
channels
Map of channels keyed by the identifier |
protected java.lang.String[] |
clientProposal
|
protected java.lang.String |
clientVersion
|
protected CloseFuture |
closeFuture
A future that will be set 'closed' when the connection is closed. |
protected boolean |
closing
The session is being closed |
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 Cipher |
inCipher
|
protected int |
inCipherSize
|
protected Compression |
inCompression
|
protected Mac |
inMac
|
protected byte[] |
inMacResult
|
protected org.apache.mina.core.session.IoSession |
ioSession
The underlying MINA session |
protected KeyExchange |
kex
|
protected java.util.List<SessionListener> |
listeners
Session listener |
protected java.lang.Object |
lock
Lock object for this session state |
protected org.slf4j.Logger |
log
Our logger |
protected java.lang.String[] |
negociated
|
protected int |
nextChannelId
Next channel identifier |
protected Cipher |
outCipher
|
protected int |
outCipherSize
|
protected Compression |
outCompression
|
protected Mac |
outMac
|
protected Random |
random
The pseudo random generator |
protected java.lang.Object |
requestLock
|
protected java.util.concurrent.atomic.AtomicBoolean |
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
|
| Constructor Summary | |
|---|---|
AbstractSession(FactoryManager factoryManager,
org.apache.mina.core.session.IoSession ioSession)
Create a new session. |
|
| Method Summary | ||
|---|---|---|
void |
addListener(SessionListener listener)
Add a session |listener|. |
|
static void |
attachSession(org.apache.mina.core.session.IoSession ioSession,
AbstractSession session)
Attach a session to the MINA session |
|
protected void |
channelClose(Buffer buffer)
Close a channel due to a close packet received |
|
protected void |
channelData(Buffer buffer)
Process incoming data on a channel |
|
protected void |
channelEof(Buffer buffer)
Process end of file on a channel |
|
protected void |
channelExtendedData(Buffer buffer)
Process incoming extended data on a channel |
|
protected void |
channelFailure(Buffer buffer)
Process a failure on a channel |
|
protected void |
channelOpenConfirmation(Buffer buffer)
|
|
protected void |
channelOpenFailure(Buffer buffer)
|
|
protected void |
channelRequest(Buffer buffer)
Service a request on a channel |
|
protected void |
channelWindowAdjust(Buffer buffer)
Process a window adjust packet on a channel |
|
CloseFuture |
close(boolean immediately)
Close this session. |
|
Buffer |
createBuffer(SshConstants.Message 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 negociation |
|
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 java.lang.String |
doReadIdentification(Buffer buffer)
Read the remote identification from this buffer. |
|
void |
exceptionCaught(java.lang.Throwable t)
Handle any exceptions that occured on this session. |
|
|
getAttribute(Session.AttributeKey<T> key)
Returns the value of the user-defined attribute of this session. |
|
protected Channel |
getChannel(Buffer buffer)
Retrieve the channel designated by the given packet |
|
FactoryManager |
getFactoryManager()
Retrieve the factory manager |
|
int |
getIntProperty(java.lang.String name,
int defaultValue)
Retrieve a configuration property as an integer |
|
org.apache.mina.core.session.IoSession |
getIoSession()
Retrieve the mina session |
|
protected int |
getNextChannelId()
|
|
static AbstractSession |
getSession(org.apache.mina.core.session.IoSession ioSession)
Retrieve the session from the MINA session. |
|
static AbstractSession |
getSession(org.apache.mina.core.session.IoSession ioSession,
boolean allowNull)
Retrieve the session from the MINA session. |
|
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 abstract void |
handleMessage(Buffer buffer)
Abstract method for processing incoming decoded packets. |
|
void |
messageReceived(org.apache.mina.core.buffer.IoBuffer buffer)
Main input point for the MINA framework. |
|
protected void |
negociate()
Compute the negociated proposals by merging the client and server proposal. |
|
protected void |
notImplemented()
Send an unimplemented packet. |
|
protected abstract boolean |
readIdentification(Buffer buffer)
Read the other side identification. |
|
protected byte[] |
receiveKexInit(Buffer buffer,
java.lang.String[] proposal)
Receive the remote key exchange init message. |
|
protected void |
receiveNewKeys(boolean isServer)
Put new keys into use. |
|
int |
registerChannel(Channel channel)
Register a newly created channel with a new unique identifier |
|
void |
removeListener(SessionListener listener)
Remove a session |listener|. |
|
boolean |
request(Buffer buffer)
Send a global request and wait for the response. |
|
protected void |
requestFailure(Buffer buffer)
|
|
protected void |
requestSuccess(Buffer buffer)
|
|
protected void |
sendIdentification(java.lang.String ident)
Send our identification. |
|
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. |
|
|
setAttribute(Session.AttributeKey<T> key,
E value)
Sets a user-defined attribute. |
|
void |
unregisterChannel(Channel channel)
Remove this channel from the list of managed channels |
|
org.apache.mina.core.future.WriteFuture |
writePacket(Buffer buffer)
Encode and send the given buffer. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String SESSION
getSession(IoSession, boolean)
and attachSession(IoSession, AbstractSession).
protected final org.slf4j.Logger log
protected final FactoryManager factoryManager
protected final org.apache.mina.core.session.IoSession ioSession
protected final Random random
protected final java.lang.Object lock
protected final CloseFuture closeFuture
protected volatile boolean closing
protected boolean authed
protected final java.util.Map<java.lang.Integer,Channel> channels
protected int nextChannelId
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[] negociated
protected byte[] I_C
protected byte[] I_S
protected KeyExchange kex
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.AtomicBoolean requestResult
protected final java.util.Map<Session.AttributeKey<?>,java.lang.Object> attributes
protected java.lang.String username
| Constructor Detail |
|---|
public AbstractSession(FactoryManager factoryManager,
org.apache.mina.core.session.IoSession ioSession)
factoryManager - the factory managerioSession - the underlying MINA session| Method Detail |
|---|
public static final AbstractSession getSession(org.apache.mina.core.session.IoSession ioSession)
ioSession - the MINA session
public static final AbstractSession getSession(org.apache.mina.core.session.IoSession ioSession,
boolean allowNull)
false,
an IllegalStateException will be thrown, else a null will
be returned
ioSession - the MINA sessionallowNull - if true, a null value may be
returned if no session is attached
null
public static final void attachSession(org.apache.mina.core.session.IoSession ioSession,
AbstractSession session)
ioSession - the MINA sessionsession - the session to attachpublic org.apache.mina.core.session.IoSession getIoSession()
public FactoryManager getFactoryManager()
getFactoryManager in interface Session
public void messageReceived(org.apache.mina.core.buffer.IoBuffer buffer)
throws java.lang.Exception
decode() method.
buffer - the new buffer received
java.lang.Exception - if an error occurs while decoding or handling the data
protected abstract void handleMessage(Buffer buffer)
throws java.lang.Exception
buffer - the buffer containing the packet
java.lang.Exception - if an exeption occurs while handling this packet.public void exceptionCaught(java.lang.Throwable t)
SshException.
exceptionCaught in interface Sessiont - the exception to process
java.io.IOExceptionpublic CloseFuture close(boolean immediately)
public org.apache.mina.core.future.WriteFuture writePacket(Buffer buffer)
throws java.io.IOException
writePacket in interface Sessionbuffer - the buffer to encode and send
java.io.IOException - if an error occured when encoding sending the packet
public boolean request(Buffer buffer)
throws java.io.IOException
buffer - the buffer containing the global request
true if the request was successful, false otherwise.
java.io.IOException - if an error occured when encoding sending the packet
public Buffer createBuffer(SshConstants.Message 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 send
protected 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 identification
true if the identification has been fully read or
false if more data is needed
java.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 string
null if more data is neededprotected java.lang.String[] createProposal(java.lang.String hostKeyTypes)
hostKeyTypes - the list of supported host key types
protected byte[] sendKexInit(java.lang.String[] proposal)
throws java.io.IOException
proposal - our proposal for key exchange negociation
java.io.IOException - if an error occured sending the packet
protected byte[] receiveKexInit(Buffer buffer,
java.lang.String[] proposal)
buffer - the buffer containing the key exchange init packetproposal - the remote proposal to fill
protected void sendNewKeys()
throws java.io.IOException
java.io.IOException - if an error occurs sending the message
protected void receiveNewKeys(boolean isServer)
throws java.lang.Exception
isServer - boolean indicating if this session is on the server or the client side
java.lang.Exception - if an error occurs
public void disconnect(int reason,
java.lang.String msg)
throws java.io.IOException
reason - the reason code for this disconnectmsg - the text message
java.io.IOException - if an error occured sending the packet
protected void notImplemented()
throws java.io.IOException
java.io.IOException - if an error occured sending the packetprotected void negociate()
negociated property.
protected void requestSuccess(Buffer buffer)
throws java.lang.Exception
java.lang.Exception
protected void requestFailure(Buffer buffer)
throws java.lang.Exception
java.lang.Exceptionprotected int getNextChannelId()
public int registerChannel(Channel channel)
throws java.lang.Exception
Session
registerChannel in interface Sessionchannel - the channel to register
java.lang.Exception
protected void channelOpenConfirmation(Buffer buffer)
throws java.io.IOException
java.io.IOException
protected void channelOpenFailure(Buffer buffer)
throws java.io.IOException
java.io.IOException
protected void channelData(Buffer buffer)
throws java.lang.Exception
buffer - the buffer containing the data
java.lang.Exception - if an error occurs
protected void channelExtendedData(Buffer buffer)
throws java.lang.Exception
buffer - the buffer containing the data
java.lang.Exception - if an error occurs
protected void channelWindowAdjust(Buffer buffer)
throws java.lang.Exception
buffer - the buffer containing the window adjustement parameters
java.lang.Exception - if an error occurs
protected void channelEof(Buffer buffer)
throws java.lang.Exception
buffer - the buffer containing the packet
java.lang.Exception - if an error occurs
protected void channelClose(Buffer buffer)
throws java.lang.Exception
buffer - the buffer containing the packet
java.lang.Exception - if an error occurspublic void unregisterChannel(Channel channel)
unregisterChannel in interface Sessionchannel - the channel
protected void channelRequest(Buffer buffer)
throws java.io.IOException
buffer - the buffer containing the request
java.lang.Exception - if an error occurs
java.io.IOException
protected void channelFailure(Buffer buffer)
throws java.lang.Exception
buffer - the buffer containing the packet
java.lang.Exception - if an error occurs
protected Channel getChannel(Buffer buffer)
throws java.io.IOException
buffer - the incoming packet
java.io.IOException - if the channel does not exists
public int getIntProperty(java.lang.String name,
int defaultValue)
getIntProperty in interface Sessionname - the name of the propertydefaultValue - the default value
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()
Session
getUsername in interface Sessionpublic 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 remove
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||