|
||||||||||
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 Map<Session.AttributeKey<?>,Object> |
attributes
|
protected boolean |
authed
Boolean indicating if this session has been authenticated or not |
protected Map<Integer,Channel> |
channels
Map of channels keyed by the identifier |
protected String[] |
clientProposal
|
protected 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 Object |
decodeLock
|
protected Buffer |
decoderBuffer
|
protected int |
decoderLength
|
protected int |
decoderState
|
protected 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 List<SessionListener> |
listeners
Session listener |
protected Object |
lock
Lock object for this session state |
protected org.slf4j.Logger |
log
Our logger |
protected 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 long |
seqi
|
protected long |
seqo
|
protected String[] |
serverProposal
|
protected String |
serverVersion
|
static 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 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 String[] |
createProposal(String hostKeyTypes)
Create our proposal for SSH negociation |
|
protected void |
decode()
Decode the incoming buffer and handle packets as needed. |
|
void |
disconnect(int reason,
String msg)
Send a disconnect packet with the given reason and message. |
|
protected String |
doReadIdentification(Buffer buffer)
Read the remote identification from this buffer. |
|
void |
exceptionCaught(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(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. |
|
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,
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|. |
|
protected void |
sendIdentification(String ident)
Send our identification. |
|
protected byte[] |
sendKexInit(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 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 Object lock
protected final CloseFuture closeFuture
protected volatile boolean closing
protected boolean authed
protected final Map<Integer,Channel> channels
protected int nextChannelId
protected final List<SessionListener> listeners
protected byte[] sessionId
protected String serverVersion
protected String clientVersion
protected String[] serverProposal
protected String[] clientProposal
protected 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 Object encodeLock
protected final Object decodeLock
protected final Map<Session.AttributeKey<?>,Object> attributes
protected String username
Constructor Detail |
---|
public AbstractSession(FactoryManager factoryManager, org.apache.mina.core.session.IoSession ioSession)
factoryManager
- the factory managerioSession
- the underlying MINA sessionMethod 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 Exception
decode()
method.
buffer
- the new buffer received
Exception
- if an error occurs while decoding or handling the dataprotected abstract void handleMessage(Buffer buffer) throws Exception
buffer
- the buffer containing the packet
Exception
- if an exeption occurs while handling this packet.public void exceptionCaught(Throwable t)
SshException
.
exceptionCaught
in interface Session
t
- the exception to process
IOException
public CloseFuture close(boolean immediately)
public org.apache.mina.core.future.WriteFuture writePacket(Buffer buffer) throws IOException
writePacket
in interface Session
buffer
- the buffer to encode and send
IOException
- if an error occured when encoding sending the packetpublic Buffer createBuffer(SshConstants.Message cmd, int len)
createBuffer
in interface Session
cmd
- the SSH commandlen
- estimated number of bytes the buffer will hold, 0 if unknown.
protected void decode() throws Exception
Exception
protected void sendIdentification(String ident)
ident
- our identification to sendprotected abstract boolean readIdentification(Buffer buffer) throws 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
IOException
- if an error occurs such as a bad protocol versionprotected 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 String[] createProposal(String hostKeyTypes)
hostKeyTypes
- the list of supported host key types
protected byte[] sendKexInit(String[] proposal) throws IOException
proposal
- our proposal for key exchange negociation
IOException
- if an error occured sending the packetprotected byte[] receiveKexInit(Buffer buffer, String[] proposal)
buffer
- the buffer containing the key exchange init packetproposal
- the remote proposal to fill
protected void sendNewKeys() throws IOException
IOException
- if an error occurs sending the messageprotected void receiveNewKeys(boolean isServer) throws Exception
isServer
- boolean indicating if this session is on the server or the client side
Exception
- if an error occurspublic void disconnect(int reason, String msg) throws IOException
reason
- the reason code for this disconnectmsg
- the text message
IOException
- if an error occured sending the packetprotected void notImplemented() throws IOException
IOException
- if an error occured sending the packetprotected void negociate()
negociated
property.
protected int getNextChannelId()
public int registerChannel(Channel channel) throws Exception
Session
registerChannel
in interface Session
channel
- the channel to register
Exception
protected void channelOpenConfirmation(Buffer buffer) throws IOException
IOException
protected void channelOpenFailure(Buffer buffer) throws IOException
IOException
protected void channelData(Buffer buffer) throws Exception
buffer
- the buffer containing the data
Exception
- if an error occursprotected void channelExtendedData(Buffer buffer) throws Exception
buffer
- the buffer containing the data
Exception
- if an error occursprotected void channelWindowAdjust(Buffer buffer) throws Exception
buffer
- the buffer containing the window adjustement parameters
Exception
- if an error occursprotected void channelEof(Buffer buffer) throws Exception
buffer
- the buffer containing the packet
Exception
- if an error occursprotected void channelClose(Buffer buffer) throws Exception
buffer
- the buffer containing the packet
Exception
- if an error occurspublic void unregisterChannel(Channel channel)
unregisterChannel
in interface Session
channel
- the channelprotected void channelRequest(Buffer buffer) throws IOException
buffer
- the buffer containing the request
Exception
- if an error occurs
IOException
protected void channelFailure(Buffer buffer) throws Exception
buffer
- the buffer containing the packet
Exception
- if an error occursprotected Channel getChannel(Buffer buffer) throws IOException
buffer
- the incoming packet
IOException
- if the channel does not existspublic int getIntProperty(String name, int defaultValue)
getIntProperty
in interface Session
name
- the name of the propertydefaultValue
- the default value
public <T> T getAttribute(Session.AttributeKey<T> key)
getAttribute
in interface Session
key
- 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 Session
key
- the key of the attribute; must not be null.value
- the value of the attribute; must not be null.
public String getUsername()
Session
getUsername
in interface Session
public void addListener(SessionListener listener)
addListener
in interface Session
listener
- the session listener to addpublic void removeListener(SessionListener listener)
removeListener
in interface Session
listener
- the session listener to remove
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |