support sasl/temporary-auth-failure

if the server is unable to query the database throwing a temporary-auth-failure
might be more appropriate
This commit is contained in:
Daniel Gultsch 2022-06-14 08:39:55 +02:00
parent d5ac6e35fc
commit a9dd5a3c76
3 changed files with 19 additions and 8 deletions

View file

@ -627,6 +627,7 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
ONLINE(false),
NO_INTERNET(false),
UNAUTHORIZED,
TEMPORARY_AUTH_FAILURE,
SERVER_NOT_FOUND,
REGISTRATION_SUCCESSFUL(false),
REGISTRATION_FAILED(true, false),
@ -732,6 +733,8 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
return R.string.payment_required;
case MISSING_INTERNET_PERMISSION:
return R.string.missing_internet_permission;
case TEMPORARY_AUTH_FAILURE:
return R.string.account_status_temporary_auth_failure;
default:
return R.string.account_status_unknown;
}

View file

@ -12,6 +12,8 @@ import android.util.SparseArray;
import androidx.annotation.NonNull;
import com.google.common.base.Strings;
import org.xmlpull.v1.XmlPullParserException;
import java.io.ByteArrayInputStream;
@ -489,20 +491,25 @@ public class XmppConnection implements Runnable {
} else if (nextTag.isStart("failure")) {
final Element failure = tagReader.readElement(nextTag);
if (Namespace.SASL.equals(failure.getNamespace())) {
if (failure.hasChild("temporary-auth-failure")) {
throw new StateChangingException(Account.State.TEMPORARY_AUTH_FAILURE);
} else if (failure.hasChild("account-disabled")) {
final String text = failure.findChildContent("text");
if (failure.hasChild("account-disabled") && text != null) {
Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(text);
if ( Strings.isNullOrEmpty(text)) {
throw new StateChangingException(Account.State.UNAUTHORIZED);
}
final Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(text);
if (matcher.find()) {
final HttpUrl url;
try {
url = HttpUrl.get(text.substring(matcher.start(), matcher.end()));
} catch (final IllegalArgumentException e) {
throw new StateChangingException(Account.State.UNAUTHORIZED);
}
if (url.isHttps()) {
this.redirectionUrl = url;
throw new StateChangingException(Account.State.PAYMENT_REQUIRED);
}
} catch (IllegalArgumentException e) {
throw new StateChangingException(Account.State.UNAUTHORIZED);
}
}
}
throw new StateChangingException(Account.State.UNAUTHORIZED);

View file

@ -976,5 +976,6 @@
<string name="plain_text_document">Plain text document</string>
<string name="account_registrations_are_not_supported">Account registrations are not supported</string>
<string name="no_xmpp_adddress_found">No XMPP address found</string>
<string name="account_status_temporary_auth_failure">Temporary authentication failure</string>
</resources>