Question

Good people of StackOverflow, please help. I've set up an ejabberd server on my ubuntu machine, added virtual host, set {access, register, [{allow, all}]}. and registered an admin account. I'm not a linux guru, but I've managed to do this basic set up. Now, from my Win 7 machine, using Pidgin, I can login as admin and have access to many administrative features. Most important I can create new users on the server. The problem is that I can't do that with my android client using asmack library. I can establish connection and login, but when I try to register a new user either trough account manager or by sending IQ packets I get forbidden(403) response error.

AccountManager am = new AccountManager(connection);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("username", "my_user_name");
attributes.put("password", "my_password");
attributes.put("email", "foo@foo.com");
attributes.put("name", "my_full_name");
am.createAccount("my_user_name", "my_password", attributes);


Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
//      attributes.put("username", username);
//      attributes.put("password", password);
//      reg.setAttributes(attributes);
reg.addAttribute("username", username);
reg.addAttribute("password", password);
reg.addAttribute("email", email);
reg.addAttribute("name", fullName);
PacketFilter filter = new AndFilter(new PacketIDFilter(
    reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);

Has anyone had similar problems or can tell me what am I doing wrong?

Thanks

Here is my LogCat

10-10 10:00:26.249: DEBUG/StatusBarPolicy(1639): [BRIGHTHY] curNetwork=22003 curHPLMN=22003
10-10 10:00:26.839: INFO/System.out(21277): 10:00:26 AM SENT (1080244736): <iq id="fMJxx-4" to="morena.local" type="get"><query xmlns="jabber:iq:register"></query></iq>
10-10 10:00:26.869: INFO/System.out(21277): 10:00:26 AM RCV  (1080244736): <iq from='morena.local' to='admin@morena.local/Smack' id='fMJxx-4' type='result'><query xmlns='jabber:iq:register'><instructions>Choose a username and password to register with this server</instructions><username>admin</username><password/><registered/></query></iq>
10-10 10:00:26.959: INFO/System.out(21277): 10:00:26 AM SENT (1080244736): <iq id="fMJxx-5" to="morena.local" type="set"><query xmlns="jabber:iq:register"><password>new_user</password><username>new_user@morena.local</username></query></iq>
10-10 10:00:26.969: INFO/System.out(21277): 10:00:26 AM RCV  (1080244736): <iq from='morena.local' to='admin@morena.local/Smack' id='fMJxx-5' type='error'><query xmlns='jabber:iq:register'><password>new_user</password><username>new_user@morena.local</username></query><error code='403' type='auth'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
10-10 10:00:31.659: WARN/System.err(21277): forbidden(403)
10-10 10:00:31.659: WARN/System.err(21277):     at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:246)
10-10 10:00:31.659: WARN/System.err(21277):     at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:207)
10-10 10:00:31.659: WARN/System.err(21277):     at org.me.my_project.FriendProfileActivity.connectToServer(FriendProfileActivity.java:698)
10-10 10:00:31.659: WARN/System.err(21277):     at org.me.my_project.FriendProfileActivity.connectLogin(FriendProfileActivity.java:578)
10-10 10:00:31.659: WARN/System.err(21277):     at org.me.my_project.FriendProfileActivity$2.run(FriendProfileActivity.java:433)
10-10 10:00:31.659: INFO/System.out(21277): 10:00:31 AM SENT (1080244736): <iq id="fMJxx-6" to="morena.local" type="get"><query xmlns="jabber:iq:register"></query></iq>
10-10 10:00:31.679: INFO/System.out(21277): 10:00:31 AM RCV  (1080244736): <iq from='morena.local' to='admin@morena.local/Smack' id='fMJxx-6' type='result'><query xmlns='jabber:iq:register'><instructions>Choose a username and password to register with this server</instructions><username>admin</username><password/><registered/></query></iq>
10-10 10:00:31.689: INFO/System.out(21277): 10:00:31 AM SENT (1080244736): <iq id="fMJxx-7" to="morena.local" type="set"><query xmlns="jabber:iq:register"><email>some@some.com</email><password>new_user1</password><username>new_user1@morena.local</username><name>new_user1@MORENA.LOCAL</name></query></iq>
10-10 10:00:31.699: INFO/System.out(21277): 10:00:31 AM RCV  (1080244736): <iq from='morena.local' to='admin@morena.local/Smack' id='fMJxx-7' type='error'><query xmlns='jabber:iq:register'><email>some@some.com</email><password>new_user1</password><username>new_user1@morena.local</username><name>new_user1@MORENA.LOCAL</name></query><error code='403' type='auth'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
10-10 10:00:31.729: WARN/System.err(21277): forbidden(403)
10-10 10:00:31.729: WARN/System.err(21277):     at org.me.my_project.utilities.CreateChatAccount.createAccount(CreateChatAccount.java:100)
10-10 10:00:31.729: WARN/System.err(21277):     at org.me.my_project.utilities.CreateChatAccount.createAccount(CreateChatAccount.java:143)
10-10 10:00:31.729: WARN/System.err(21277):     at org.me.my_project.FriendProfileActivity.connectToServer(FriendProfileActivity.java:706)
10-10 10:00:31.729: WARN/System.err(21277):     at org.me.my_project.FriendProfileActivity.connectLogin(FriendProfileActivity.java:578)
10-10 10:00:31.729: WARN/System.err(21277):     at org.me.my_project.FriendProfileActivity$2.run(FriendProfileActivity.java:433)
Was it helpful?

Solution

I found it! The problem is in server configuration (but I still don't understand why I could register new user from Pidgin before this change). Setting

%% In-band registration
{access, register, [{allow, all}]}.

doesn't seem to work with new versions of ejabberd. You need to add

{mod_register, [
      {access_from, register},
       ...
                ] ...

if You want to allow all users to register. If You want only admin to have this access, then you need to add new access rule

{access, register_from, [{allow, admin}]}.

and

{mod_register, [
      {access_from, register_from},
       ...
                ] ...

OTHER TIPS

Works for me this code to register a new account:

try
{
    connection.connect ();
    Log.i (TAG, "Connect");
    mAccount = new AccountManager (connection);
    if (mAccount.supportsAccountCreation ())
    {
        mAccount.createAccount ("user", "pass");
    }

with the following settings ejabberd:

{access, register, [{allow, all}]}.

It is a very secure setup because it can record without our authenticated accounts on the server (the method supports.AccountCreation () returns us true).

Had you specified the ip_access option in mod_register? If Pidgin and your ejabberd server are somehow both using the same IP, then a default rule that looks something like this:

{mod_register, [
    ...
    %%
    %% Only clients in the server machine can register accounts
    %%
    {ip_access, [{allow, "127.0.0.0/8"},
                 {deny, "0.0.0.0/0"}]},
    ...
] ...

would allow both of those IPs to register accounts, but not an Android client that was using a different IP.

I've been facing a related problem, and for some reason the {access_from, register_from} solution that worked for you did not work as expected for me. Were you able to restrict the ability to create new accounts to only an admin user?

I came across the same issue and found the solution:

Make changes in server

After loggin in ejabbered from ur admin interface. Go to Virtual Host-Nodes-Modules-mod_register and add:

[{welcome_message,  {"Welcome!", "Welcome to this Jabber server."}}, {access_from, register}]

n u ll b able to create account successfully from your client

To register a new user using smack library after logging in through admin or some other account.

/** * To Register a New Client On Jabber Server */

public void registerUser()
{
    AccountManager manager = connection.getAccountManager();
    try {
        manager.createAccount("Romain Guy","halejag");//username & paswd


    } catch (XMPPException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
    Create user everytime
    Very easy and work everytime


    open ejabberd.cfg file using

    sudo nano /etc/ejabberd/ejabberd.cfg

    change 600 option to infinity

    {registration_timeout, 600}.

    {registration_timeout, infinity}.

Try with following changes in ejabberd.cfg.

%%{ip_access, [
%% {allow, "127.0.0.0/8"},
%% {deny, "0.0.0.0/0"}]}

along with -

%% In-band registration
{access, register, [{allow, all}]}.

&

{mod_register, [
      {access_from, register},
       ...
                ] 

I hope now it will work for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top