Class SASLMechanism

    • Field Detail

      • authenticationId

        protected java.lang.String authenticationId
        Then authentication identity (authcid). RFC 6120 § 6.3.7 informs us that some SASL mechanisms use this as a "simple user name". But the exact form is a matter of the mechanism and that it does not necessarily map to an localpart. But it usually is the localpart of the client JID, although sometimes other formats are used (e.g. the full JID).

        Not to be confused with the authzid (see RFC 6120 § 6.3.8).

      • authorizationId

        protected org.jxmpp.jid.EntityBareJid authorizationId
        The authorization identifier (authzid). This is always a bare Jid, but can be null.
      • serviceName

        protected org.jxmpp.jid.DomainBareJid serviceName
        The name of the XMPP service
      • password

        protected java.lang.String password
        The users password
      • host

        protected java.lang.String host
      • sslSession

        protected javax.net.ssl.SSLSession sslSession
        The used SSL/TLS session (if any).
    • Constructor Detail

      • SASLMechanism

        public SASLMechanism()
    • Method Detail

      • authenticate

        public final void authenticate​(java.lang.String username,
                                       java.lang.String host,
                                       org.jxmpp.jid.DomainBareJid serviceName,
                                       java.lang.String password,
                                       org.jxmpp.jid.EntityBareJid authzid,
                                       javax.net.ssl.SSLSession sslSession)
                                throws SmackException.SmackSaslException,
                                       SmackException.NotConnectedException,
                                       java.lang.InterruptedException
        Builds and sends the auth stanza to the server. Note that this method of authentication is not recommended, since it is very inflexible. Use authenticate(String, DomainBareJid, CallbackHandler, EntityBareJid, SSLSession) whenever possible. Explanation of auth stanza: The client authentication stanza needs to include the digest-uri of the form: xmpp/serviceName From RFC-2831: digest-uri = "digest-uri" "=" digest-uri-value digest-uri-value = serv-type "/" host [ "/" serv-name ] digest-uri: Indicates the principal name of the service with which the client wishes to connect, formed from the serv-type, host, and serv-name. For example, the FTP service on "ftp.example.com" would have a "digest-uri" value of "ftp/ftp.example.com"; the SMTP server from the example above would have a "digest-uri" value of "smtp/mail3.example.com/example.com". host: The DNS host name or IP address for the service requested. The DNS host name must be the fully-qualified canonical name of the host. The DNS host name is the preferred form; see notes on server processing of the digest-uri. serv-name: Indicates the name of the service if it is replicated. The service is considered to be replicated if the client's service-location process involves resolution using standard DNS lookup operations, and if these operations involve DNS records (such as SRV, or MX) which resolve one DNS name into a set of other DNS names. In this case, the initial name used by the client is the "serv-name", and the final name is the "host" component. For example, the incoming mail service for "example.com" may be replicated through the use of MX records stored in the DNS, one of which points at an SMTP server called "mail3.example.com"; it's "serv-name" would be "example.com", it's "host" would be "mail3.example.com". If the service is not replicated, or the serv-name is identical to the host, then the serv-name component MUST be omitted digest-uri verification is needed for ejabberd 2.0.3 and higher
        Parameters:
        username - the username of the user being authenticated.
        host - the hostname where the user account resides.
        serviceName - the xmpp service location - used by the SASL client in digest-uri creation serviceName format is: host [ "/" serv-name ] as per RFC-2831
        password - the password for this account.
        authzid - the optional authorization identity.
        sslSession - the optional SSL/TLS session (if one was established)
        Throws:
        SmackException.SmackSaslException - if a SASL related error occurs.
        SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • authenticate

        public void authenticate​(java.lang.String host,
                                 org.jxmpp.jid.DomainBareJid serviceName,
                                 javax.security.auth.callback.CallbackHandler cbh,
                                 org.jxmpp.jid.EntityBareJid authzid,
                                 javax.net.ssl.SSLSession sslSession)
                          throws SmackException.SmackSaslException,
                                 SmackException.NotConnectedException,
                                 java.lang.InterruptedException
        Builds and sends the auth stanza to the server. The callback handler will handle any additional information, such as the authentication ID or realm, if it is needed.
        Parameters:
        host - the hostname where the user account resides.
        serviceName - the xmpp service location
        cbh - the CallbackHandler to obtain user information.
        authzid - the optional authorization identity.
        sslSession - the optional SSL/TLS session (if one was established)
        Throws:
        SmackException.SmackSaslException - if a SASL related error occurs.
        SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • getAuthenticationText

        protected abstract byte[] getAuthenticationText()
                                                 throws SmackException.SmackSaslException
        Should return the initial response of the SASL mechanism. The returned byte array will be send base64 encoded to the server. SASL mechanism are free to return null or an empty array here.
        Returns:
        the initial response or null
        Throws:
        SmackException.SmackSaslException - if a SASL specific error occurred.
      • challengeReceived

        public final void challengeReceived​(java.lang.String challengeString,
                                            boolean finalChallenge)
                                     throws SmackException.SmackSaslException,
                                            java.lang.InterruptedException,
                                            SmackException.NotConnectedException
        The server is challenging the SASL mechanism for the stanza he just sent. Send a response to the server's challenge.
        Parameters:
        challengeString - a base64 encoded string representing the challenge.
        finalChallenge - true if this is the last challenge send by the server within the success stanza
        Throws:
        SmackException.SmackSaslException - if a SASL related error occurs.
        java.lang.InterruptedException - if the connection is interrupted
        SmackException.NotConnectedException - if the XMPP connection is not connected.
      • compareTo

        public final int compareTo​(SASLMechanism other)
        Specified by:
        compareTo in interface java.lang.Comparable<SASLMechanism>
      • getName

        public abstract java.lang.String getName()
        Returns the common name of the SASL mechanism. E.g.: PLAIN, DIGEST-MD5 or GSSAPI.
        Returns:
        the common name of the SASL mechanism.
      • getPriority

        public abstract int getPriority()
        Get the priority of this SASL mechanism. Lower values mean higher priority.
        Returns:
        the priority of this SASL mechanism.
      • authzidSupported

        public boolean authzidSupported()
      • isAuthenticationSuccessful

        public boolean isAuthenticationSuccessful()
      • isFinished

        public boolean isFinished()
      • setException

        public void setException​(java.lang.Exception exception)
      • toBytes

        protected static byte[] toBytes​(java.lang.String string)
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object