StackOverflow的好心人,请帮帮忙。我已经在我的ubuntu机器上设置了一个ejabberd服务器,添加了虚拟主机,设置了{access,register,{allow,all}}。并注册了一个管理员账号。我不是linux专家,但我已经成功地完成了这些基本设置。现在,在我的Win7机器上,使用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)
发布于 2011-10-11 19:35:30
我找到了!问题出在服务器配置上(但我仍然不明白为什么我可以在这个更改之前从Pidgin注册新用户)。设置
%% In-band registration
{access, register, [{allow, all}]}.
似乎不适用于新版本的ejabberd。您需要添加
{mod_register, [
{access_from, register},
...
] ...
如果您想要允许所有用户注册。如果您只想让admin拥有此访问权限,则需要添加新访问规则
{access, register_from, [{allow, admin}]}.
和
{mod_register, [
{access_from, register_from},
...
] ...
发布于 2012-08-27 18:37:22
注册新帐户的代码对我有效:
try
{
connection.connect ();
Log.i (TAG, "Connect");
mAccount = new AccountManager (connection);
if (mAccount.supportsAccountCreation ())
{
mAccount.createAccount ("user", "pass");
}
使用以下设置ejabberd:
{访问,注册,{允许,全部}}。
这是一个非常安全的设置,因为它可以在没有我们在服务器上验证的帐户的情况下进行记录( supports.AccountCreation ()方法返回true)。
发布于 2012-04-26 12:09:33
您是否在mod_register
中指定了ip_access option
?如果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
用户?
https://stackoverflow.com/questions/7709658
复制相似问题