SASLException not authorized using smack 4.1.1

954 views Asked by At

I´ve got a problem to log in to jabber server using Smack 4.1.1. I am successfully connected to the jabber server, but at the time I try to login, it fails with exception. I googled a lot for days, but it seems that no solution on SO or anywhere else works.

XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();                        builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
   // builder.setUsernameAndPassword(myUserName,password);
    builder.setServiceName(jabberServer);
    builder.setHost(jabberServer);
    builder.setPort(5222)
    builder.setDebuggerEnabled(true);

    AbstractXMPPConnection connection = new XMPPTCPConnection(builder.build());
    connection.connect();
    connection.login(myUserName,password);
    //connection.login();

I tried both ways, once with setting username and password to builder and once setting it at login. Nothing works, login allways will fail with the following exception:

SASLErrorException: SASLError using PLAIN: not-authorized

Please note, the rest of stacktrace is not important here, so I don´t post it.

what I´ve tried:

  • using server and service name jabber.org, also tried with jabber.de

  • set username for example as simple string userName, also with [email protected] (or @jabber.de)

  • setDebuggerEnabled(false), setCompressionEnabled(false), setCompressionEnabled(true) on my builder.

  • also configure SASL mechanism:

    SASLAuthentication.unBlacklistSASLMechanism("PLAIN"); SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");

BEFORE connect() and BEFORE login()

  • setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
  • setSecurityMode(ConnectionConfiguration.SecurityMode.required);
  • setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);

all these tries I also commentet out completely.

I have googled a lot, found out that this was a bug on older Smack libraries, but should be fixed in the new Smack release above 4.0 . So I have to assume that this error is not a bug in Smack.

I assumed that this error could come because the account that I use is not registered, so I tried to register new Account before login with smacks AccountManager. I have set allowEmptyOrNullUserNames() on my builder(), but register new account throws service not available exception, so I just assume, that registration with AccountManager is not available on jabber.org or jabber,de .

I also exactly followed the documentation steps and the README Guide from Smack:

https://www.igniterealtime.org/builds/smack/docs/latest/documentation/

https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide

Question

  1. What I am missing?
  2. Is it still a bug, if yes, how to solve it by myself?
  3. Must an Account be registered by AccountManager or is this automatically done if the user does not exist at the jabber servers?
  4. Could somebody guide me to the right direction (code example?) maybe with other free XMPP servers from https://xmpp.org/xmpp-software/servers/?
  5. I read about using better some nightly builds like smack-SNAPSHOT-2015-06-07 from download on ignite realtime, but how should I integrate a nightly build into my Android Studio project? Using dependencies (if yes how?), using import module?

Is there anybody out there in this whole wide developer-universe who has successfully fixed this issue? I am grateful for any information...

UPDATE

I now just make a try and registered on jabber.de over the internet. Then I used my account to log in via my app and IT WORKS! . So it seems that the problem really is that no account is registered. I saw that registration jabber.org is disabled since 2013 because of some attacks and since this time nothing happened. I assume the service of jabber.org is not available anymore. With jabber.de I now had successfully loged in.

I had registered new account like this:

AccountManager accountManager = AccountManager.getInstance(connection);
Map<String, String> map = new HashMap<String, String>();
map.put("username", myUserName);
map.put("password", myPassword);
map.put("email", myEmail);
accountManager.createAccount(myUserName, myPassword, map);

and another way:

AccountManager accountManager = AccountManager.getInstance(connection);
accountManager.createAccount(myUserName, myPassword);

Both I tried with configuring connection without userName and password by setting allowEmptyOrNullUsernames() (connection was successfull), but there is service not available exception thrown.

So, the new question is, how to register successfull new Account? Had I missed something in the configuration for example something like allowing to register an account?

2nd Update

It turns out that the most free servers has disabled In-Band-Registration, because of too many Spam violence. So it is not possible anymore on the most open free xmpp servers. Now the question is, how to register via app with this situation? I read something about web services, would that be a solution?

2

There are 2 answers

1
user5006585 On

I had the same execption by two different reasons:

  1. incorrect service name
  2. I was trying to run the connection and login in the "main thread", try creating a new thread:

Inside your connection method:

Thread t = new Thread(new Runnable() {

    @Override
    public void run() {
       //code for connection here

    }
});
t.start();
0
Opiatefuchs On

I have found out by contacting the jabber.de provider team, that they disabled the In-Band registration. Which means, it is not possible to create a new Account from within an app (maybe only if theyself would develop an app and put some security mechanism inside). Also found out that the most free xmpp servers don´t allow In-Band registration, they have done it because of too many spam violence and attacks from apps that try to register.

At servers with disabled In-Band registration, You have to lead the user to the server website and they have to register via web. Everything I have done in the examples above is the correct way and works with servers that don´t have disabled the In-Band registration.

But a warning for all who try similar things: Don´t rely on the In-Band registration, if You want to provide a open free server that is not Your own, You have to take care of this registration. Servers who are not In-Band disabled could do this in the future and if You want to let the user registrate there, You must have a second possibility if registration fails.