src/main/java/org/jivesoftware/smack/SASLAuthentication.java
public String authenticateAnonymously() throws XMPPException {
        try {
            currentMechanism = new SASLAnonymous(this);
            currentMechanism.authenticate(null, null, null, "");

            // Wait until SASL negotiation finishes
            synchronized (this) {
                if (!saslNegotiated && !saslFailed) {
                    try {
                        wait(5000);
                    } catch (InterruptedException e) {
                        // Ignore
                    }
                }
            }

            if (saslFailed) {
                // SASL authentication failed and the server may have closed the
                // connection
                // so throw an exception
                if (errorCondition != null) {
                    throw new XMPPException("SASL authentication failed: "
                            + errorCondition);
                } else {
                    throw new XMPPException("SASL authentication failed");
                }
            }

            if (saslNegotiated) {
                // Bind a resource for this connection and
                return bindResourceAndEstablishSession(null);
            } else {
                return new NonSASLAuthentication(connection)
                        .authenticateAnonymously();
            }
        } catch (IOException e) {
            return new NonSASLAuthentication(connection)
                    .authenticateAnonymously();
        }
    }
public String authenticateAnonymously() throws XMPPException {
        try {
            currentMechanism = new SASLAnonymous(this);
            currentMechanism.authenticate(null, null, null, "");

            // Wait until SASL negotiation finishes
            synchronized (this) {
                if (!saslNegotiated && !saslFailed) {
                    try {
                        wait(5000);
                    } catch (InterruptedException e) {
                        // Ignore
                    }
                }
            }

            if (saslFailed) {
                // SASL authentication failed and the server may have closed the
                // connection
                // so throw an exception
                if (errorCondition != null) {
                    throw new XMPPException("SASL authentication failed: "
                            + errorCondition);
                } else {
                    throw new XMPPException("SASL authentication failed");
                }
            }

            if (saslNegotiated) {
                // Bind a resource for this connection and
                return bindResourceAndEstablishSession(null);
            } else {
                return new NonSASLAuthentication(connection)
                        .authenticateAnonymously();
            }
        } catch (IOException e) {
            return new NonSASLAuthentication(connection)
                    .authenticateAnonymously();
        }
    }
Performs ANONYMOUS SASL authentication. If SASL authentication was
successful then resource binding and session establishment will be
performed. This method will return the full JID provided by the server
while binding a resource to the connection.
<p>

The server will assign a full JID with a randomly generated resource and
possibly with no username.

@return the full JID provided by the server while binding a resource to
the connection.
@throws XMPPException
if an error occures while authenticating.