Class LocalSession
- java.lang.Object
-
- org.jivesoftware.openfire.session.LocalSession
-
- All Implemented Interfaces:
ChannelHandler<org.xmpp.packet.Packet>
,RoutableChannelHandler
,Session
- Direct Known Subclasses:
LocalClientSession
,LocalComponentSession
,LocalConnectionMultiplexerSession
,LocalServerSession
public abstract class LocalSession extends Object implements Session
The session represents a connection between the server and a client (c2s) or another server (s2s) as well as a connection with a component. Authentication and user accounts are associated with c2s connections while s2s has an optional authentication association but no single user. Obtain object managers from the session in order to access server resources.- Author:
- Gaston Dombiak
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.session.Session
Session.Status
-
-
Field Summary
Fields Modifier and Type Field Description protected org.xmpp.packet.JID
address
The Address this session is authenticated as.protected Connection
conn
The connection that this session represents.protected String
serverName
protected SessionManager
sessionManager
protected long
startDate
protected Session.Status
status
The current session status.protected StreamID
streamID
The stream id for this session (random and unique).protected StreamManager
streamManager
XEP-0198 Stream Manager-
Fields inherited from interface org.jivesoftware.openfire.session.Session
MAJOR_VERSION, MINOR_VERSION, STATUS_AUTHENTICATED, STATUS_CLOSED, STATUS_CONNECTED
-
-
Constructor Summary
Constructors Constructor Description LocalSession(String serverName, Connection connection, StreamID streamID, Locale language)
Creates a session with an underlying connection and permission protection.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
Close this session including associated socket connection.protected static int[]
decodeVersion(String version)
Deprecated.Replaced bySession.decodeVersion(String)
void
deliverRawText(String text)
Delivers raw text to this connection.org.xmpp.packet.JID
getAddress()
Obtain the address of the user.abstract List<org.dom4j.Element>
getAvailableStreamFeatures()
Returns a text with the available stream features.String
getCipherSuiteName()
Returns the TLS cipher suite name used by the connection of the session, if any.Connection
getConnection()
Returns the connection associated with this Session.Date
getCreationDate()
Obtain the date the session was created.String
getHostAddress()
Returns the IP address string in textual presentation.String
getHostName()
Gets the host name for this IP address.Locale
getLanguage()
Returns the locale that is used for this session (e.g.Date
getLastActiveDate()
Obtain the time the session last had activity.long
getNumClientPackets()
Obtain the number of packets sent from the client to the server.long
getNumServerPackets()
Obtain the number of packets sent from the server to the client.Certificate[]
getPeerCertificates()
Returns the peer certificates associated with this session, if any.String
getServerName()
Obtain the name of the server this session belongs to.Object
getSessionData(String key)
Retrieves session data.Map<String,String>
getSoftwareVersion()
Retrieves Software Version data.Session.Status
getStatus()
Obtain the current status of this session.StreamID
getStreamID()
Obtain the stream ID associated with this sesison.StreamManager
getStreamManager()
Get XEP-0198 Stream manager for sessionString
getTLSProtocolName()
Returns the TLS protocol name used by the connection of the session, if any.void
incrementClientPacketCount()
Increments the number of packets sent from the client to the server.void
incrementServerPacketCount()
Increments the number of packets sent from the server to the client.boolean
isClosed()
Returns true if the connection/session is closed.boolean
isDetached()
Returns true if the session is detached (that is, if the underlying connection has been closed while the session instance itself has not been closed).boolean
isEncrypted()
Returns true if this session uses encrypted connections.boolean
isSecure()
Deprecated.boolean
isUsingSelfSignedCertificate()
Returns true if the other peer of this session presented a self-signed certificate.void
process(org.xmpp.packet.Packet packet)
Process an XMPP packet.void
reattach(LocalSession connectionProvider, long h)
Reattach the (existing) session to the connection provided by a new session (a session that will be replaced by the older, pre-existing session).Object
removeSessionData(String key)
Removes session data.void
setAddress(org.xmpp.packet.JID address)
Sets the new address of this session.void
setDetached()
Set the session to detached mode, indicating that the underlying connection has been closed.Object
setSessionData(String key, Object value)
Saves given session data.void
setSoftwareVersionData(String key, String value)
Saves given session data.void
setStatus(Session.Status status)
Set the new status of this session.String
toString()
boolean
validate()
Verifies that the connection is still live.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.openfire.session.Session
isAuthenticated
-
-
-
-
Field Detail
-
address
protected org.xmpp.packet.JID address
The Address this session is authenticated as.
-
streamID
protected final StreamID streamID
The stream id for this session (random and unique).
-
status
protected Session.Status status
The current session status.
-
conn
protected Connection conn
The connection that this session represents.
-
sessionManager
protected SessionManager sessionManager
-
serverName
protected final String serverName
-
startDate
protected final long startDate
-
streamManager
protected final StreamManager streamManager
XEP-0198 Stream Manager
-
-
Constructor Detail
-
LocalSession
public LocalSession(String serverName, Connection connection, StreamID streamID, Locale language)
Creates a session with an underlying connection and permission protection.- Parameters:
serverName
- domain of the XMPP server where the new session belongs.connection
- The connection we are proxying.streamID
- unique identifier for this session.language
- The language to use for this session.
-
-
Method Detail
-
isDetached
public boolean isDetached()
Returns true if the session is detached (that is, if the underlying connection has been closed while the session instance itself has not been closed).- Returns:
- true if session detached
-
setDetached
public void setDetached()
Set the session to detached mode, indicating that the underlying connection has been closed.
-
reattach
public void reattach(LocalSession connectionProvider, long h)
Reattach the (existing) session to the connection provided by a new session (a session that will be replaced by the older, pre-existing session). The connection must already be initialized as a running XML Stream, normally by having run through XEP-0198 resumption.- Parameters:
connectionProvider
- Session from which to obtain the connection from.h
- the sequence number of the last handled stanza sent over the former stream
-
getAddress
public org.xmpp.packet.JID getAddress()
Obtain the address of the user. The address is used by services like the core server packet router to determine if a packet should be sent to the handler. Handlers that are working on behalf of the server should use the generic server hostname address (e.g. server.com).- Specified by:
getAddress
in interfaceRoutableChannelHandler
- Specified by:
getAddress
in interfaceSession
- Returns:
- the address of the packet handler.
-
setAddress
public void setAddress(org.xmpp.packet.JID address)
Sets the new address of this session. The address is used by services like the core server packet router to determine if a packet should be sent to the handler. Handlers that are working on behalf of the server should use the generic server hostname address (e.g. server.com).- Parameters:
address
- the new address of this session.
-
getConnection
@Nullable public Connection getConnection()
Returns the connection associated with this Session. Note that null can be returned, for example when the session is detached.- Returns:
- The connection for this session
-
getStatus
public Session.Status getStatus()
Obtain the current status of this session.
-
setStatus
public void setStatus(Session.Status status)
Set the new status of this session. Setting a status may trigger certain events to occur (setting a closed status will close this session).- Parameters:
status
- The new status code for this session
-
getStreamID
public StreamID getStreamID()
Obtain the stream ID associated with this sesison. Stream ID's are generated by the server and should be unique and random.- Specified by:
getStreamID
in interfaceSession
- Returns:
- This session's assigned stream ID
-
getServerName
public String getServerName()
Obtain the name of the server this session belongs to.- Specified by:
getServerName
in interfaceSession
- Returns:
- the server name.
-
getCreationDate
public Date getCreationDate()
Obtain the date the session was created.- Specified by:
getCreationDate
in interfaceSession
- Returns:
- the session's creation date.
-
getLastActiveDate
public Date getLastActiveDate()
Obtain the time the session last had activity.- Specified by:
getLastActiveDate
in interfaceSession
- Returns:
- The last time the session received activity.
-
incrementClientPacketCount
public void incrementClientPacketCount()
Increments the number of packets sent from the client to the server.
-
incrementServerPacketCount
public void incrementServerPacketCount()
Increments the number of packets sent from the server to the client.
-
getNumClientPackets
public long getNumClientPackets()
Obtain the number of packets sent from the client to the server.- Specified by:
getNumClientPackets
in interfaceSession
- Returns:
- The number of packets sent from the client to the server.
-
getNumServerPackets
public long getNumServerPackets()
Obtain the number of packets sent from the server to the client.- Specified by:
getNumServerPackets
in interfaceSession
- Returns:
- The number of packets sent from the server to the client.
-
setSessionData
public Object setSessionData(String key, Object value)
Saves given session data. Data are saved to temporary storage only and are accessible during this session life only and only from this session instance.- Parameters:
key
- aString
value of stored data key ID.value
- aObject
value of data stored in session.- Returns:
- the previous value associated with
key
, ornull
if there was no mapping forkey
. (Anull
return can also indicate that the map previously associatednull
withkey
.) - See Also:
getSessionData(String)
-
getSessionData
public Object getSessionData(String key)
Retrieves session data. This method gives access to temporary session data only. You can retrieve earlier saved data giving key ID to receive needed value. Please seesetSessionData(String, Object)
description for more details.- Parameters:
key
- aString
value of stored data ID.- Returns:
- a
Object
value of data for given key. - See Also:
setSessionData(String, Object)
-
removeSessionData
public Object removeSessionData(String key)
Removes session data. Please seesetSessionData(String, Object)
description for more details.- Parameters:
key
- aString
value of stored data ID.- Returns:
- the previous value associated with
key
, ornull
if there was no mapping forkey
. - See Also:
setSessionData(String, Object)
-
getStreamManager
public StreamManager getStreamManager()
Get XEP-0198 Stream manager for session- Returns:
- The StreamManager for the session.
-
process
public void process(org.xmpp.packet.Packet packet)
Description copied from interface:ChannelHandler
Process an XMPP packet.- Specified by:
process
in interfaceChannelHandler<org.xmpp.packet.Packet>
- Specified by:
process
in interfaceSession
- Parameters:
packet
- a packet to process.
-
deliverRawText
public void deliverRawText(String text)
Description copied from interface:Session
Delivers raw text to this connection. This is a very low level way for sending XML stanzas to the client. This method should not be used unless you have very good reasons for not usingSession.process(Packet)
.This method avoids having to get the writer of this connection and mess directly with the writer. Therefore, this method ensures a correct delivery of the stanza even if other threads were sending data concurrently.
- Specified by:
deliverRawText
in interfaceSession
- Parameters:
text
- the XML stanzas represented kept in a String.
-
getAvailableStreamFeatures
public abstract List<org.dom4j.Element> getAvailableStreamFeatures()
Returns a text with the available stream features. Each subclass may return different values depending whether the session has been authenticated or not.- Returns:
- a text with the available stream features or
null
to add nothing.
-
close
public void close()
Description copied from interface:Session
Close this session including associated socket connection. The order of events for closing the session is:- Set closing flag to prevent redundant shutdowns.
- Call notifyEvent all listeners that the channel is shutting down.
- Close the socket.
Session.getStatus()
will be CLOSED.
-
validate
public boolean validate()
Description copied from interface:Session
Verifies that the connection is still live. Typically this is done by sending a whitespace character between packets. // TODO No one is sending this message now. Delete it?
-
isSecure
@Deprecated public boolean isSecure()
Deprecated.Description copied from interface:Session
Returns true if this connection is secure.
-
isEncrypted
public boolean isEncrypted()
Description copied from interface:Session
Returns true if this session uses encrypted connections.- Specified by:
isEncrypted
in interfaceSession
- Returns:
- true if the session is encrypted (e.g. TLS)
-
getPeerCertificates
public Certificate[] getPeerCertificates()
Description copied from interface:Session
Returns the peer certificates associated with this session, if any.- Specified by:
getPeerCertificates
in interfaceSession
- Returns:
- certificates, possibly empty or null.
-
isClosed
public boolean isClosed()
Description copied from interface:Session
Returns true if the connection/session is closed.
-
getHostAddress
public String getHostAddress() throws UnknownHostException
Description copied from interface:Session
Returns the IP address string in textual presentation.- Specified by:
getHostAddress
in interfaceSession
- Returns:
- the raw IP address in a string format.
- Throws:
UnknownHostException
- if IP address of host could not be determined.
-
getHostName
public String getHostName() throws UnknownHostException
Description copied from interface:Session
Gets the host name for this IP address.If this InetAddress was created with a host name, this host name will be remembered and returned; otherwise, a reverse name lookup will be performed and the result will be returned based on the system configured name lookup service. If a lookup of the name service is required, call
getCanonicalHostName
.If there is a security manager, its
checkConnect
method is first called with the hostname and-1
as its arguments to see if the operation is allowed. If the operation is not allowed, it will return the textual representation of the IP address.- Specified by:
getHostName
in interfaceSession
- Returns:
- the host name for this IP address, or if the operation is not allowed by the security check, the textual representation of the IP address.
- Throws:
UnknownHostException
- if IP address of host could not be determined.- See Also:
InetAddress.getCanonicalHostName()
,SecurityManager.checkConnect(java.lang.String, int)
-
decodeVersion
@Deprecated protected static int[] decodeVersion(String version)
Deprecated.Replaced bySession.decodeVersion(String)
-
isUsingSelfSignedCertificate
public boolean isUsingSelfSignedCertificate()
Returns true if the other peer of this session presented a self-signed certificate. When using self-signed certificate for server-2-server sessions then SASL EXTERNAL will not be used and instead server-dialback will be preferred for vcerifying the identify of the remote server.- Returns:
- true if the other peer of this session presented a self-signed certificate.
-
getTLSProtocolName
@Nonnull public String getTLSProtocolName()
Description copied from interface:Session
Returns the TLS protocol name used by the connection of the session, if any. Always returns a valid string, though the string may be "NONE"- Specified by:
getTLSProtocolName
in interfaceSession
- Returns:
- a TLS protocol (version) name.
-
getCipherSuiteName
@Nonnull public String getCipherSuiteName()
Description copied from interface:Session
Returns the TLS cipher suite name used by the connection of the session, if any. Always returns a valid string, though the string may be "NONE"- Specified by:
getCipherSuiteName
in interfaceSession
- Returns:
- cipher suite name.
-
getLanguage
public final Locale getLanguage()
Description copied from interface:Session
Returns the locale that is used for this session (e.g.Locale.ENGLISH
).- Specified by:
getLanguage
in interfaceSession
- Returns:
- The language for the session.
-
getSoftwareVersion
public Map<String,String> getSoftwareVersion()
Retrieves Software Version data. This method gives access to temporary Software Version data only.- Specified by:
getSoftwareVersion
in interfaceSession
- Returns:
- a Map collection value of data .
-
setSoftwareVersionData
public void setSoftwareVersionData(String key, String value)
Saves given session data. Data is saved to temporary storage only and is accessible during this session life only and only from this session instance.- Parameters:
key
- aString
value of stored data key ID.value
- aString
value of data stored in session.
-
-