asmack XMPP新用户注册 [英] asmack XMPP new user registration

查看:151
本文介绍了asmack XMPP新用户注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好计算器的人,请大家帮忙。 我已经设置了对我的Ubuntu机器上的服务器的ejabberd,添加虚拟主机,设置     {接入,注册,[{允许,所有}]}。 和注册管理员帐户。我不是一个Linux的大师,但我已经成功地做​​到这一点基本设置。 现在,从我的Win 7的机器,用洋泾浜,我能够作为管理员登录,并有机会获得许多管理功能。最重要的是我可以在服务器上创建新的用户。 问题是,我不能做到这一点,使用asmack库我的Andr​​oid客户端。我可以建立连接和登录,但是当我试图通过发送IQ数据包注册一个新用户无论是低谷的客户经理或我被禁止(403)响应错误。

 的AccountManager AM =新的AccountManager(连接);
地图<字符串,字符串>属性=新的HashMap<字符串,字符串>();
attributes.put(用户名,my_user_name);
attributes.put(密码,MY_PASSWORD);
attributes.put(电子邮件,foo@foo.com);
attributes.put(姓名,my_full_name);
am.createAccount(my_user_name,MY_PASSWORD,属性);


注册章=新注册();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
// attributes.put(用户名,用户名);
// attributes.put(密码,密码);
// reg.setAttributes(属性);
reg.addAttribute(用户名,用户名);
reg.addAttribute(密码,密码);
reg.addAttribute(邮件,邮件);
reg.addAttribute(名,全名);
PacketFilter过滤器=新AndFilter(新PacketIDFilter(
    reg.getPacketID()),新PacketTypeFilter(IQ.class));
PacketCollector收藏家= connection.createPacketCollector(过滤器);
connection.sendPacket(REG);
 

有没有人有类似的问题,或者可以告诉我,我究竟做错了什么?

感谢

下面是我的LogCat中

  10月10号至10日:00:26.249:DEBUG / StatusBarPolicy(1639):[BRIGHTHY] curNetwork = 22003 curHPLMN = 22003
10月10日至10日:00:26.839:信息/的System.out(21277):上午十点00分26秒SENT(1080244736):其中,智商ID =fMJxx-4=morena.localTYPE =得到><查询的xmlns =胡言乱语:IQ:注册>< /查询>< / IQ>
10月10日至10日:00:26.869:信息/的System.out(21277):上午十点00分26秒RCV(1080244736):其中,来自='morena.localIQ to='admin@morena.local/Smack ID ='fMJxx-4型='结果'&GT;&LT;查询的xmlns ='胡言乱语:IQ:注册'&GT;&LT;说明&GT;选择一个用户名和密码与该注册server</instructions><username>admin</username><password/><registered/></query></iq>
10月10日至10日:00:26.959:信息/的System.out(21277):上午十点00分26秒SENT(1080244736):其中,智商ID =fMJxx-5=morena.localTYPE =设置&GT;&LT;查询xmlns="jabber:iq:register"><password>new_user</password><username>new_user@morena.local</username></query></iq>
10月10日至10日:00:26.969:信息/的System.out(21277):上午十点00分26秒RCV(1080244736):其中,来自='morena.localIQ to='admin@morena.local/Smack ID ='fMJxx-5型='错误'&GT;&LT;查询xmlns='jabber:iq:register'><password>new_user</password><username>new_user@morena.local</username></query><error code ='403'型='权威性'&GT;&LT;严禁的xmlns =金塔:IETF:params:一个XML:NS:XMPP协议,叙述/&GT;&LT; /错误&GT;&LT; / IQ&GT;
10月10号至一十号:00:31.659:WARN / System.err的(21277):禁止(403)
10月10号至一十号:00:31.659:WARN / System.err的(21277):在org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:246)
10月10号至一十号:00:31.659:WARN / System.err的(21277):在org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:207)
10月10号至一十号:00:31.659:WARN / System.err的(21277):在org.me.my_project.FriendProfileActivity.connectToServer(FriendProfileActivity.java:698)
10月10号至一十号:00:31.659:WARN / System.err的(21277):在org.me.my_project.FriendProfileActivity.connectLogin(FriendProfileActivity.java:578)
10月10号至一十号:00:31.659:WARN / System.err的(21277):在org.me.my_project.FriendProfileActivity $ 2.运行(FriendProfileActivity.java:433)
10月10日至10日:00:31.659:信息/的System.out(21277):上午10时00分31秒SENT(1080244736):其中,智商ID =fMJxx-6=morena.localTYPE =得到&GT;&LT;查询的xmlns =胡言乱语:IQ:注册&GT;&LT; /查询&GT;&LT; / IQ&GT;
10月10日至10日:00:31.679:信息/的System.out(21277):上午10时00分31秒RCV(1080244736):其中,来自='morena.localIQ to='admin@morena.local/Smack ID ='fMJxx-6型='结果'&GT;&LT;查询的xmlns ='胡言乱语:IQ:注册'&GT;&LT;说明&GT;选择一个用户名和密码与该注册server</instructions><username>admin</username><password/><registered/></query></iq>
10月10日至10日:00:31.689:信息/的System.out(21277):上午10时00分31秒SENT(1080244736):其中,智商ID =fMJxx-7为=morena.localTYPE =设置&GT;&LT;查询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:信息/的System.out(21277):上午10时00分31秒RCV(1080244736):其中,来自='morena.localIQ to='admin@morena.local/Smack ID ='fMJxx-7'型='错误'&GT;&LT;查询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'型='权威性'&GT;&LT;严禁的xmlns =金塔:IETF:params:一个XML:NS:XMPP协议,叙述/&GT;&LT; /错误&GT;&LT; / IQ&GT;
10月10号至一十号:00:31.729:WARN / System.err的(21277):禁止(403)
10月10号至一十号:00:31.729:WARN / System.err的(21277):在org.me.my_project.utilities.CreateChatAccount.createAccount(CreateChatAccount.java:100)
10月10号至一十号:00:31.729:WARN / System.err的(21277):在org.me.my_project.utilities.CreateChatAccount.createAccount(CreateChatAccount.java:143)
10月10号至一十号:00:31.729:WARN / System.err的(21277):在org.me.my_project.FriendProfileActivity.connectToServer(FriendProfileActivity.java:706)
10月10号至一十号:00:31.729:WARN / System.err的(21277):在org.me.my_project.FriendProfileActivity.connectLogin(FriendProfileActivity.java:578)
10月10号至一十号:00:31.729:WARN / System.err的(21277):在org.me.my_project.FriendProfileActivity $ 2.运行(FriendProfileActivity.java:433)
 

解决方案

我找到了! 问题出在服务器配置(但我还是不明白,为什么我会从洋泾浜此更改之前注册新用户)。设置

  %%带内注册
{接入,注册,[{允许,所有}]}。
 

似乎不使用的ejabberd新版本一起使用。您需要添加

  {mod_register,[
      {access_from,注册},
       ...
                ] ...
 

如果你想允许所有的用户注册。如果你想只管理有此访问权限,那么你就需要增加新的访问规则

  {访问,register_from,[{允许,管理员}]}。
 

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

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)

解决方案

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

这篇关于asmack XMPP新用户注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆