asmack XMPP new user registration

时间秒杀一切 提交于 2019-12-03 01:48:19

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},
       ...
                ] ...

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?

Neha Nathani

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!