在ejabberd上使用Smack创建新用户将引发XMPP异常:禁止(403) [英] Creating new user with Smack on ejabberd throws XMPP Exception: forbidden(403)
问题描述
我正在研究ejabberd,对这项技术我还很陌生。
Hi I am working on ejabberd and I am quite new to this technology.
我正在尝试使用以下代码在我的ejabberd服务器上添加用户:
I am trying to add a user on 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();
}
}
}
它已连接到服务器和管理员登录是完美的,但是在创建新帐户
时,会出现403错误:
Its connecting to server and admin login is perfectly But during creating new account it gives forbidden 403 error that is :
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 thankful if somebody can suggest a workarround for this .
推荐答案
转到C:\Program Files(x86)\ejabberd-2.1.8\conf(在我的情况下)文件夹&使用记事本++打开ejabberd.cfg文件(很容易使用它进行编辑)。
Goto C:\Program Files (x86)\ejabberd-2.1.8\conf (in my case) folder & open ejabberd.cfg file using Notepad++ (it is easy to edit using it).
在文件中进行以下更改:
In the file do 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},
...
] ...
这篇关于在ejabberd上使用Smack创建新用户将引发XMPP异常:禁止(403)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!