private static void authenticationFailed(LocalSession session, Failure failure) {
        final Element reply = DocumentHelper.createElement(QName.get("failure", "urn:ietf:params:xml:ns:xmpp-sasl"));
        reply.addElement(failure.toString());
        session.deliverRawText(reply.asXML());
        // Give a number of retries before closing the connection
        Integer retries = (Integer) session.getSessionData("authRetries");
        if (retries == null) {
            retries = 1;
        }
        else {
            retries = retries + 1;
        }
        session.setSessionData("authRetries", retries);
        if (retries >= JiveGlobals.getIntProperty("xmpp.auth.retries", 3) ) {
            // Close the connection
            Log.debug( "Closing session that failed to authenticate {} times: {}", retries, session );
            session.close();
        }
    }
Handles the SASL authentication packet. The entity may be sending an initial
authentication request or a response to a challenge made by the server. The returned
value indicates whether the authentication has finished either successfully or not or
if the entity is expected to send a response to a challenge.

@param session the session that is authenticating with the server.
@param doc the stanza sent by the authenticating entity.
@return value that indicates whether the authentication has finished either successfully
        or not or if the entity is expected to send a response to a challenge.
xmppserver/src/main/java/org/jivesoftware/openfire/net/SASLAuthentication.java