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
  • Field Details

    • address

      @Nonnull 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 Details

    • 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 Details

    • isDetached

      public boolean isDetached()
      Description copied from interface: Session
      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).
      Specified by:
      isDetached in interface Session
      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

      @Nonnull public org.xmpp.packet.JID getAddress()
      Obtain the address of the 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).
      Specified by:
      getAddress in interface RoutableChannelHandler
      Specified by:
      getAddress in interface Session
      Returns:
      the address of the packet handler.
    • setAddress

      public void setAddress(@Nonnull 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.
      Specified by:
      getStatus in interface Session
      Returns:
      The status code for 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 interface Session
      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 interface Session
      Returns:
      the server name.
    • getCreationDate

      public Date getCreationDate()
      Obtain the date the session was created.
      Specified by:
      getCreationDate in interface Session
      Returns:
      the session's creation date.
    • getLastActiveDate

      public Date getLastActiveDate()
      Obtain the time the session last had activity.
      Specified by:
      getLastActiveDate in interface Session
      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 interface Session
      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 interface Session
      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 - a String value of stored data key ID.
      value - a Object value of data stored in session.
      Returns:
      the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
      See Also:
    • 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 see setSessionData(String, Object) description for more details.
      Parameters:
      key - a String value of stored data ID.
      Returns:
      a Object value of data for given key.
      See Also:
    • removeSessionData

      public Object removeSessionData(String key)
      Removes session data. Please see setSessionData(String, Object) description for more details.
      Parameters:
      key - a String value of stored data ID.
      Returns:
      the previous value associated with key, or null if there was no mapping for key.
      See Also:
    • 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 interface ChannelHandler<org.xmpp.packet.Packet>
      Specified by:
      process in interface Session
      Parameters:
      packet - a packet to process.
    • deliverRawText

      public void deliverRawText(String text)
      Description copied from interface: Session
      Delivers raw text to the remote XMPP entity. 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 using Session.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 interface Session
      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(s) where appropriate. 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 underlying connection(s) (eg: socket).
      Implementations should ensure that after invocation, the result of Session.getStatus() will be CLOSED.
      Specified by:
      close in interface Session
    • validate

      public boolean validate()
      Description copied from interface: Session
      Verifies that the session is still live. Typically this is done by sending a whitespace character between packets. // TODO No one is sending this message now. Delete it?
      Specified by:
      validate in interface Session
      Returns:
      true if the socket remains valid, false otherwise.
    • isEncrypted

      public boolean isEncrypted()
      Description copied from interface: Session
      Returns true if this session uses encrypted communication paths when exchanging data with the remote XMPP entity.
      Specified by:
      isEncrypted in interface Session
      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 interface Session
      Returns:
      certificates, possibly empty or null.
    • isClosed

      public boolean isClosed()
      Description copied from interface: Session
      Returns true if the link to the remote XMPP entity (the session) is closed.
      Specified by:
      isClosed in interface Session
      Returns:
      true if the 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 interface Session
      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 interface Session
      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:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 verifying 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 underlying connection(s) of the session, if any. Always returns a valid string, though the string may be "NONE"
      Specified by:
      getTLSProtocolName in interface Session
      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 underlying connection(s) of the session, if any. Always returns a valid string, though the string may be "NONE"
      Specified by:
      getCipherSuiteName in interface Session
      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 interface Session
      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 interface Session
      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 - a String value of stored data key ID.
      value - a String value of data stored in session.