I'm creating a chat application with Ejabberd Server and Xmpp. in this app , i want to add new users with Android code. i use asmack-android-8-0.8.10.jar . i checked other questions in stackoverflow.com about this problem , i did what they say but i couldn't solve problem...
i try add new user with this code like someone said:
HashMap<String, String> attr = new HashMap<String, String>();
attr.put("user", username);
attr.put("password", password);
try {
// Admin login
connection.login(username, password);
} catch (XMPPException e) {
e.printStackTrace();
}
Log.i("connection.isAuthenticated() : ","" + connection.isAuthenticated());
if (connection.isAuthenticated()) {
AccountManager manager = new AccountManager(connection);
try {
if (manager.supportsAccountCreation())
{
manager.createAccount(username, password, attr);
}
} catch (XMPPException e) {
Log.w("[create_user] Cannot create new user: XMPP Exception.","0");
e.printStackTrace();
} catch (IllegalStateException e) {
Log.w("[create_user] Cannot create new user: not logged in.", "0");
e.printStackTrace();
}
}
But it gives me this error :
12-01 17:12:32.436: D/SMACK(16442): 05:12:32 PM SENT (1101049376): <iq id="44B8E-6" to="mehmetcan" type="set"><query xmlns="jabber:iq:register"><password>can123</password> <user>user2fasf</user><username>user2fasf</username></query></iq>
12-01 17:12:32.626: D/SMACK(16442): 05:12:32 PM RCV (1101049376): <iq from='mehmetcan' to='admin@mehmetcan/Smack' id='44B8E-6' type='error'><query xmlns='jabber:iq:register'><password>can123</password><user>user2fasf</user><username>user2fasf</username></query><error code='403' type='auth'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
12-01 17:12:32.626: W/[create_user] Cannot create new user: XMPP Exception.(16442): 0
12-01 17:12:32.626: W/System.err(16442): forbidden(403)
12-01 17:12:32.626: W/System.err(16442): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:243)
12-01 17:12:32.626: W/System.err(16442): at org.apache.android.xmppClient.XmppUserCreateTask.doInBackground(XmppUserCreateTask.java:66)
12-01 17:12:32.626: W/System.err(16442): at org.apache.android.xmppClient.XmppUserCreateTask.doInBackground(XmppUserCreateTask.java:1)
12-01 17:12:32.626: W/System.err(16442): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-01 17:12:32.626: W/System.err(16442): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-01 17:12:32.626: W/System.err(16442): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-01 17:12:32.626: W/System.err(16442): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-01 17:12:32.626: W/System.err(16442): at java.lang.Thread.run(Thread.java:856)
Then like people said , In ejabberd.cfg file , i made this changes :
%% Put this in the section ACCESS RULES
{access, register_from, [{allow, admin}]}.
and changed mod_register as access to access_from and register to register_from :
{mod_register, [
%%
%% After successful registration, the user receives
%% a message with this subject and body.
%%
{welcome_message, {"Welcome!",
"Welcome to this Jabber server."}},
%%
%% When a user registers, send a notification to
%% these Jabber accounts.
%%
%%{registration_watchers, ["admin1@example.org"]},
{access_from, register_from}
]},
And it still gives me same error :
Cannot create new user: XMPP Exception.(16442): 0 forbidden (403)
How to solve this problem ? is this because some of updates of ejabberd ? Pls help..