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.JIDaddressThe Address this session is authenticated as.protected ConnectionconnThe connection that this session represents.protected StringserverNameprotected SessionManagersessionManagerprotected longstartDateprotected Session.StatusstatusThe current session status.protected StreamIDstreamIDThe stream id for this session (random and unique).protected StreamManagerstreamManagerXEP-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 voidclose()Close this session including associated socket connection.protected static int[]decodeVersion(String version)Deprecated.Replaced bySession.decodeVersion(String)voiddeliverRawText(String text)Delivers raw text to this connection.org.xmpp.packet.JIDgetAddress()Obtain the address of the user.abstract List<org.dom4j.Element>getAvailableStreamFeatures()Returns a text with the available stream features.StringgetCipherSuiteName()Returns the TLS cipher suite name used by the connection of the session, if any.ConnectiongetConnection()Returns the connection associated with this Session.DategetCreationDate()Obtain the date the session was created.StringgetHostAddress()Returns the IP address string in textual presentation.StringgetHostName()Gets the host name for this IP address.LocalegetLanguage()Returns the locale that is used for this session (e.g.DategetLastActiveDate()Obtain the time the session last had activity.longgetNumClientPackets()Obtain the number of packets sent from the client to the server.longgetNumServerPackets()Obtain the number of packets sent from the server to the client.Certificate[]getPeerCertificates()Returns the peer certificates associated with this session, if any.StringgetServerName()Obtain the name of the server this session belongs to.ObjectgetSessionData(String key)Retrieves session data.Map<String,String>getSoftwareVersion()Retrieves Software Version data.Session.StatusgetStatus()Obtain the current status of this session.StreamIDgetStreamID()Obtain the stream ID associated with this sesison.StreamManagergetStreamManager()Get XEP-0198 Stream manager for sessionStringgetTLSProtocolName()Returns the TLS protocol name used by the connection of the session, if any.voidincrementClientPacketCount()Increments the number of packets sent from the client to the server.voidincrementServerPacketCount()Increments the number of packets sent from the server to the client.booleanisClosed()Returns true if the connection/session is closed.booleanisDetached()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).booleanisEncrypted()Returns true if this session uses encrypted connections.booleanisSecure()Deprecated.booleanisUsingSelfSignedCertificate()Returns true if the other peer of this session presented a self-signed certificate.voidprocess(org.xmpp.packet.Packet packet)Process an XMPP packet.voidreattach(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).ObjectremoveSessionData(String key)Removes session data.voidsetAddress(org.xmpp.packet.JID address)Sets the new address of this session.voidsetDetached()Set the session to detached mode, indicating that the underlying connection has been closed.ObjectsetSessionData(String key, Object value)Saves given session data.voidsetSoftwareVersionData(String key, String value)Saves given session data.voidsetStatus(Session.Status status)Set the new status of this session.StringtoString()booleanvalidate()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:
getAddressin interfaceRoutableChannelHandler- Specified by:
getAddressin 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:
getStreamIDin interfaceSession- Returns:
- This session's assigned stream ID
-
getServerName
public String getServerName()
Obtain the name of the server this session belongs to.- Specified by:
getServerNamein interfaceSession- Returns:
- the server name.
-
getCreationDate
public Date getCreationDate()
Obtain the date the session was created.- Specified by:
getCreationDatein interfaceSession- Returns:
- the session's creation date.
-
getLastActiveDate
public Date getLastActiveDate()
Obtain the time the session last had activity.- Specified by:
getLastActiveDatein 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:
getNumClientPacketsin 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:
getNumServerPacketsin 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- aStringvalue of stored data key ID.value- aObjectvalue of data stored in session.- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the map previously associatednullwithkey.) - 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- aStringvalue of stored data ID.- Returns:
- a
Objectvalue 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- aStringvalue of stored data ID.- Returns:
- the previous value associated with
key, ornullif 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:ChannelHandlerProcess an XMPP packet.- Specified by:
processin interfaceChannelHandler<org.xmpp.packet.Packet>- Specified by:
processin interfaceSession- Parameters:
packet- a packet to process.
-
deliverRawText
public void deliverRawText(String text)
Description copied from interface:SessionDelivers 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:
deliverRawTextin 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
nullto add nothing.
-
close
public void close()
Description copied from interface:SessionClose 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:SessionVerifies 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:SessionReturns true if this connection is secure.
-
isEncrypted
public boolean isEncrypted()
Description copied from interface:SessionReturns true if this session uses encrypted connections.- Specified by:
isEncryptedin interfaceSession- Returns:
- true if the session is encrypted (e.g. TLS)
-
getPeerCertificates
public Certificate[] getPeerCertificates()
Description copied from interface:SessionReturns the peer certificates associated with this session, if any.- Specified by:
getPeerCertificatesin interfaceSession- Returns:
- certificates, possibly empty or null.
-
isClosed
public boolean isClosed()
Description copied from interface:SessionReturns true if the connection/session is closed.
-
getHostAddress
public String getHostAddress() throws UnknownHostException
Description copied from interface:SessionReturns the IP address string in textual presentation.- Specified by:
getHostAddressin 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:SessionGets 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
checkConnectmethod is first called with the hostname and-1as 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:
getHostNamein 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:SessionReturns 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:
getTLSProtocolNamein interfaceSession- Returns:
- a TLS protocol (version) name.
-
getCipherSuiteName
@Nonnull public String getCipherSuiteName()
Description copied from interface:SessionReturns 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:
getCipherSuiteNamein interfaceSession- Returns:
- cipher suite name.
-
getLanguage
public final Locale getLanguage()
Description copied from interface:SessionReturns the locale that is used for this session (e.g.Locale.ENGLISH).- Specified by:
getLanguagein 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:
getSoftwareVersionin 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- aStringvalue of stored data key ID.value- aStringvalue of data stored in session.
-
-