powered by Jive Software

Smack & Account Creation

I’'m trying to use a Smack-based program to create new accounts on a Jive 2.3.0 (beta 1) server.

In the “registration and login” section of the server admin pages I’'ve got “inband account registration” enabled.

The code looks like this:

XMPPConnection connection = new XMPPConnection(“xmpp.bar.com”);

connection.login(“bofh”, “lart”);

AccountManager accountManager = connection.getAccountManager();

accountManager.createAccount(“luser”, “smack”);

I get an exception thrown, “Server does not support account creation.”

Am I missing something on the server config side?

Hey Don McGregor,

The problem is that you can’'t login if the account does not exist yet. Try removing the login line. You can also take a look at the JUnit test cases provided in Smack to see how we are creating and destroying accounts.

Regards,

– Gato

You can also take a look at the JUnit test cases provided

in Smack to see how we are creating and destroying accounts.

What JUnit test cases are you referring to? I downloaded the source distribution and did a full-text search for “createAccount” but came up with nothing. I can’‘t get account creation to work, and I can find no examples of this in the JUnit tests. The odd thing is I’'m using Jive software on both ends: smack-dev-2.1.0 against Wildfire 2.4.0.

I have enabled Inband Account Registration and Anonymous Login (in Wildfire -> Server -> Registration & Login).

I’‘ve tried with and without the loginAnonymously() line but either way it doesn’'t work.

private void connectIfNecessary() throws XMPPException {

try {

connection.login(getUsername(), getPassword(), getResource());

} catch (XMPPException xe) {

//if first login failed, try to create an account and then login

//connection.loginAnonymously(); //tried with and without this line

AccountManager accountMgr = connection.getAccountManager();

accountMgr.createAccount(getUsername(), getPassword());

connection.login(getUsername(), getPassword(), getResource());

}

}

/code

The error message is: Unable to connect to Jabber Server. Server does not support account creation.[/b]

Furthermore, if I add code like the following, Smack reports that account creation is unsupported.

if(!accountMgr.supportsAccountCreation()) {

//account creation not supported!

}

/code

Surely it must be supported because Spark (and other clients) have no problem registering accounts with Wildfire…

OK, not sure if this is the preferred method for auto-account-creation, but here’'s what worked:

try {

connection.login(getUsername(), getPassword(), getResource());

} catch (XMPPException xe) {

//if first login failed, try to create an account and then login

connection.close(); //must close and recreate connection first

connection = new XMPPConnection(getServer(), getPort());

connection.getAccountManager().createAccount(getUsername(), getPassword());

connection.login(getUsername(), getPassword(), getResource());

}

/code

Note to other readers: The unqualified getters are there because I’‘m operating inside a javabean. They’'re unrelated to the Smack API.

Note to Smack developers: it would be nice if createAccount provided a different message after a failed login than just Server does not support account creation[/b]. At a minimum, a note in the javadoc for createAccount could mention that it may require a fresh connection in order to work properly. (Better yet, if it could detect a previously failed login and recover…).