0

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..

canmuratt
  • 51
  • 1
  • 8

1 Answers1

3

You only allow the user you defined in the "admin" rule to register an account. You did not post how you defined "admin". However, given your example, I expect you want to allow anyone to register an account. Maybe, the following is what you want ?

{access, register_from, [{allow, all}]}.
Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44
  • i didn't defined anything about 'admin' user ..i can post u about 'admin' user if you say where is the information about... i get registration code from [this post](http://stackoverflow.com/questions/17125459/using-asmack-xmpp-create-new-user-on-ejabberd-from-android) . i did what they said.. now i also changed that line in cfg file as you said but it's giving same error . what do you offer ? – canmuratt Dec 01 '14 at 22:22
  • Yes, but what they say is incomplete. You are referring here to an "admin" rule. If it does not exist, then it does not do anything. – Mickaël Rémond Dec 01 '14 at 22:50
  • okey , how i can define an admin rule and let him allowed to register someone ? i will do what u say . – canmuratt Dec 02 '14 at 10:52
  • This is shown in example ejabberd config file. Something like {acl, admin, {user, "aleksey", "localhost"}}. However, as mentioned previously, I think you misunderstand what it will do and it will not do what you want. It will allow admin user to register its own account. As I mentioned I think you want "allow all". Please read the original reply. – Mickaël Rémond Dec 02 '14 at 10:58
  • This is my admin rule {acl, admin, {user, "admin", "mehmetcan"}}. i want to register some new users with different user names . they are not needed to define with 'admin' rule in cfg . i want to add them for communicute with each other with my app . – canmuratt Dec 02 '14 at 11:49
  • i use asmack-android-8-0.8.10.jar . version could be problem ? what do you offer what changes should i do .. – canmuratt Dec 02 '14 at 21:38