Creating a new user using Smack on ejabberd throws XMPP Exception: forbidden (403)

Hi, I am working on ejabberd and I am completely new to this technology.

I am trying to add a user to my ejabberd server using this code:

try { conf.setSASLAuthenticationEnabled(true); connection.connect(); Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual); Log.i("XMPPClient", "Connected to " +connection.getHost()); createUser("tester","testerpass"); } } catch (XMPPException e1) { Log.e("XMPPClient", e1.toString()); xmppClient.setConnection(null); } public void createUser(String user, String pass) { try { //Admin login connection.login(user, pass); } catch (XMPPException e) { e.printStackTrace(); } Log.i("connection.isAuthenticated() : ",""+connection.isAuthenticated() ); if (connection.isAuthenticated()) { AccountManager manager = connection.getAccountManager(); try { manager.createAccount(user, pass); } 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(); } } } 

Its connection to the server and administrator login is excellent, but when creating a new account it gives a forbidden error 403:

 06-15 20:01:40.092: I/XMPPClient(1300):Connected to 68.178.255.136 06-15 20:01:41.952: I/connection.isAuthenticated() :(1300): true 06-15 20:01:42.562: W/[create_user] Cannot create new user: XMPP Exception.(1300): 0 06-15 20:01:42.562: W/System.err(1300): forbidden(403) 06-15 20:01:42.562: W/System.err(1300): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:246) 

I would be very grateful if anyone could suggest a desktop for this.

+4
source share
3 answers

Go to the C: \ Program Files (x86) \ ejabberd-2.1.8 \ conf folder (in my case) and open the ejabberd.cfg file with Notepad ++ (it's easy to edit with).

In the file, make the following changes:

 %% Put this in the section ACCESS RULES {access, register_from, [{allow, admin}]}. %% Change mod_register so it contains the new access rule: {mod_register, [ {access_from, register_from}, ... ] ... 
+3
source

I want to update the answer to reflect the change in version 4.0 of Asmack. Connection.getAccountManager () is now AccountManager.getInstance (XMPPConnection)

 AccountManager accountManager=AccountManager.getInstance(connection); try { accountManager.createAccount("username", "password"); } catch (XMPPException e1) { Log.d(e1.getMessage(), e1); } 
+3
source

In my case, I need to edit the EJABERD_HOME / conf / ejabberd.yml file, change the mod_register change options to:

 ip_access : all access_from : all access: register 

So that users can register from another host

0
source

All Articles