Class LocalIncomingServerSession

  • All Implemented Interfaces:
    ChannelHandler<org.xmpp.packet.Packet>, RoutableChannelHandler, IncomingServerSession, ServerSession, Session

    public class LocalIncomingServerSession
    extends LocalServerSession
    implements IncomingServerSession
    Server-to-server communication is done using two TCP connections between the servers. One connection is used for sending packets while the other connection is used for receiving packets. The IncomingServerSession represents the connection to a remote server that will only be used for receiving packets.

    Currently only the Server Dialback method is being used for authenticating the remote server. Once the remote server has been authenticated incoming packets will be processed by this server. It is also possible for remote servers to authenticate more domains once the session has been established. For optimization reasons the existing connection is used between the servers. Therefore, the incoming server session holds the list of authenticated domains which are allowed to send packets to this server.

    Using the Server Dialback method it is possible that this server may also act as the Authoritative Server. This implies that an incoming connection will be established with this server for authenticating a domain. This incoming connection will only last for a brief moment and after the domain has been authenticated the connection will be closed and no session will exist.

    Author:
    Gaston Dombiak
    • Constructor Detail

      • LocalIncomingServerSession

        public LocalIncomingServerSession​(String serverName,
                                          Connection connection,
                                          StreamID streamID,
                                          String fromDomain)
    • Method Detail

      • createSession

        public static LocalIncomingServerSession createSession​(String serverName,
                                                               XMPPPacketReader reader,
                                                               SocketConnection connection,
                                                               boolean directTLS)
                                                        throws org.xmlpull.v1.XmlPullParserException,
                                                               IOException
        Creates a new session that will receive packets. The new session will be authenticated before being returned. If the authentication process fails then the answer will be null.

        Parameters:
        serverName - hostname of this server.
        reader - reader on the new established connection with the remote server.
        connection - the new established connection with the remote server.
        directTLS - true of connections are immediately encrypted (as opposed to plain text / startls).
        Returns:
        a new session that will receive packets or null if a problem occured while authenticating the remote server or when acting as the Authoritative Server during a Server Dialback authentication process.
        Throws:
        org.xmlpull.v1.XmlPullParserException - if an error occurs while parsing the XML.
        IOException - if an input/output error occurs while using the connection.
      • getDefaultIdentity

        public String getDefaultIdentity()
      • validateSubsequentDomain

        public boolean validateSubsequentDomain​(org.dom4j.Element dbResult)
        Returns true if the request of a new domain was valid. Sessions may receive subsequent domain validation request. If the validation of the new domain fails then the session and the underlying TCP connection will be closed.

        For optimization reasons, the same session may be servicing several domains of a remote server.

        Parameters:
        dbResult - the DOM stanza requesting the domain validation.
        Returns:
        true if the requested domain was valid.
      • isValidDomain

        public boolean isValidDomain​(String domain)
        Returns true if the specified domain has been validated for this session. The remote server should send a "db:result" packet for registering new subdomains or even virtual hosts.

        In the spirit of being flexible we allow remote servers to not register subdomains and even so consider subdomains that include the server domain in their domain part as valid domains.

        Parameters:
        domain - the domain to validate.
        Returns:
        true if the specified domain has been validated for this session.
      • getValidatedDomains

        public Collection<String> getValidatedDomains()
        Returns a collection with all the domains, subdomains and virtual hosts that where validated. The remote server is allowed to send packets from any of these domains, subdomains and virtual hosts.
        Specified by:
        getValidatedDomains in interface IncomingServerSession
        Returns:
        domains, subdomains and virtual hosts that where validated.
      • addValidatedDomain

        public void addValidatedDomain​(String domain)
        Adds a new validated domain, subdomain or virtual host to the list of validated domains for the remote server.
        Parameters:
        domain - the new validated domain, subdomain or virtual host to add.
      • removeValidatedDomain

        public void removeValidatedDomain​(String domain)
        Removes the previously validated domain from the list of validated domains. The remote server will no longer be able to send packets from the removed domain, subdomain or virtual host.
        Parameters:
        domain - the domain, subdomain or virtual host to remove from the list of validated domains.
      • getLocalDomain

        public String getLocalDomain()
        Returns the domain or subdomain of the local server used by the remote server when validating the session. This information is only used to prevent many connections from the same remote server to the same domain or subdomain of the local server.
        Specified by:
        getLocalDomain in interface IncomingServerSession
        Returns:
        the domain or subdomain of the local server used by the remote server when validating the session.
      • setLocalDomain

        public void setLocalDomain​(String domain)
        Sets the domain or subdomain of the local server used by the remote server when asking to validate the session. This information is only used to prevent many connections from the same remote server to the same domain or subdomain of the local server.
        Parameters:
        domain - the domain or subdomain of the local server used when validating the session.
      • verifyReceivedKey

        public void verifyReceivedKey​(org.dom4j.Element doc)
        Verifies the received key sent by the remote server. This server is trying to generate an outgoing connection to the remote server and the remote server is reusing an incoming connection for validating the key.
        Parameters:
        doc - the received Element that contains the key to verify.
      • getAvailableStreamFeatures

        public String getAvailableStreamFeatures()
        Description copied from class: LocalSession
        Returns a text with the available stream features. Each subclass may return different values depending whether the session has been authenticated or not.
        Overrides:
        getAvailableStreamFeatures in class LocalServerSession
        Returns:
        a text with the available stream features or null to add nothing.
      • tlsAuth

        public void tlsAuth()