5

StackOverflow 的好人,请帮忙。我已经在我的 ubuntu 机器上设置了一个 ejabberd 服务器,添加了虚拟主机,设置 {access, register, [{allow, all}]}。并注册了一个管理员帐户。我不是 linux 专家,但我已经设法完成了这个基本设置。现在,在我的 Win 7 机器上,使用 Pidgin,我可以以管理员身份登录,并可以访问许多管理功能。最重要的是我可以在服务器上创建新用户。问题是我不能用我的 android 客户端使用 asmack 库来做到这一点。我可以建立连接并登录,但是当我尝试通过帐户管理器或通过发送 IQ 数据包注册新用户时,我收到禁止(403)响应错误。

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);

有没有人遇到过类似的问题或者可以告诉我我做错了什么?

谢谢

这是我的 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)
4

7 回答 7

7

我找到了!问题出在服务器配置中(但我仍然不明白为什么我可以在此更改之前从 Pidgin 注册新用户)。环境

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

似乎不适用于新版本的 ejabberd。您需要添加

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

如果您想允许所有用户注册。如果您只希望管理员拥有此访问权限,那么您需要添加新的访问规则

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

{mod_register, [
      {access_from, register_from},
       ...
                ] ...
于 2011-10-11T11:35:30.220 回答
5

对我有用这个代码来注册一个新帐户:

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

使用以下设置 ejabberd:

{访问,注册,[{允许,全部}]}。

这是一个非常安全的设置,因为它可以在没有我们在服务器上经过身份验证的帐户的情况下进行记录(方法 support.AccountCreation () 返回 true)。

于 2012-08-27T10:37:21.730 回答
3

你指定了ip_access optioninmod_register吗?如果 Pidgin 和您的 ejabberd 服务器不知何故都使用相同的 IP,则默认规则如下所示:

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

将允许这两个 IP 注册帐户,但不允许使用不同 IP 的 Android 客户端。

我一直面临着一个相关的问题,出于某种原因{access_from, register_from},对你有用的解决方案对我来说没有按预期工作。您是否能够将创建新帐户的能力限制为只有一个admin用户?

于 2012-04-26T04:09:32.953 回答
1

我遇到了同样的问题并找到了解决方案:

在服务器中进行更改

从您的管理界面登录 ejabbered 后。转到 Virtual Host-Nodes-Modules-mod_register 并添加:

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

不能从您的客户那里成功创建帐户

于 2012-09-25T10:14:27.240 回答
0

通过管理员或其他帐户登录后使用 smack 库注册新用户。

/** * 在 Jabber 服务器上注册一个新客户端 */

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();
    }
}
于 2011-11-29T05:15:51.337 回答
0
    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}.
于 2014-07-10T12:03:50.207 回答
0

尝试在 ejabberd.cfg 中进行以下更改。

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

随着 -

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

&

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

我希望现在它对你有用。

于 2016-03-02T13:47:39.460 回答