0
我正在創建與Ejabberd服務器和Xmpp聊天應用程序。在這個應用程序中,我想用Android代碼添加新用戶。我使用asmack-android-8-0.8.10.jar。我檢查在stackoverflow.com這個問題的其他問題,我沒有他們說什麼,但我沒能解決的問題......無法在Android中向Ejabberd服務器添加新用戶。它給予禁止(403)
我嘗試添加新用戶使用此代碼就像有人說:
HashMap<String, String> attr = new HashMap<String, String>();
attr.put("user", username);
attr.put("password", password);
try {
// Admin login
connection.login(username, password);
} catch (XMPPException e) {
e.printStackTrace();
}
Log.i("connection.isAuthenticated() : ","" + connection.isAuthenticated());
if (connection.isAuthenticated()) {
AccountManager manager = new AccountManager(connection);
try {
if (manager.supportsAccountCreation())
{
manager.createAccount(username, password, attr);
}
} 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();
}
}
但它給了我這個錯誤:
12-01 17:12:32.436: D/SMACK(16442): 05:12:32 PM SENT (1101049376): <iq id="44B8E-6" to="mehmetcan" type="set"><query xmlns="jabber:iq:register"><password>can123</password> <user>user2fasf</user><username>user2fasf</username></query></iq>
12-01 17:12:32.626: D/SMACK(16442): 05:12:32 PM RCV (1101049376): <iq from='mehmetcan' to='[email protected]/Smack' id='44B8E-6' type='error'><query xmlns='jabber:iq:register'><password>can123</password><user>user2fasf</user><username>user2fasf</username></query><error code='403' type='auth'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
12-01 17:12:32.626: W/[create_user] Cannot create new user: XMPP Exception.(16442): 0
12-01 17:12:32.626: W/System.err(16442): forbidden(403)
12-01 17:12:32.626: W/System.err(16442): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:243)
12-01 17:12:32.626: W/System.err(16442): at org.apache.android.xmppClient.XmppUserCreateTask.doInBackground(XmppUserCreateTask.java:66)
12-01 17:12:32.626: W/System.err(16442): at org.apache.android.xmppClient.XmppUserCreateTask.doInBackground(XmppUserCreateTask.java:1)
12-01 17:12:32.626: W/System.err(16442): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-01 17:12:32.626: W/System.err(16442): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-01 17:12:32.626: W/System.err(16442): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-01 17:12:32.626: W/System.err(16442): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-01 17:12:32.626: W/System.err(16442): at java.lang.Thread.run(Thread.java:856)
那麼喜歡的人說,在ejabberd.cfg文件,我做了這個變化:
%% Put this in the section ACCESS RULES
{access, register_from, [{allow, admin}]}.
,改變mod_register機會獲得access_from並註冊register_from:
{mod_register, [
%%
%% After successful registration, the user receives
%% a message with this subject and body.
%%
{welcome_message, {"Welcome!",
"Welcome to this Jabber server."}},
%%
%% When a user registers, send a notification to
%% these Jabber accounts.
%%
%%{registration_watchers, ["[email protected]"]},
{access_from, register_from}
]},
它仍然給了我同樣的錯誤:
Cannot create new user: XMPP Exception.(16442): 0 forbidden (403)
如何解決這個問題呢?這是因爲ejabberd的一些更新?請幫助..
我沒有定義的有關「管理員」用戶..我可以張貼ü約「管理員」用戶,如果你說哪裏是關於信息...我從[此帖]註冊碼什麼(HTTP ://stackoverflow.com/questions/17125459/using-asmack-xmpp-create-new-user-on-ejabberd-from-android)。我做了他們所說的......現在我也改變了cfg文件中的那一行,正如你所說的,但它給出了同樣的錯誤。你提供什麼? – canmuratt 2014-12-01 22:22:10
是的,但他們所說的不完整。您在這裏指的是「管理員」規則。如果它不存在,那麼它什麼都不會做。 – 2014-12-01 22:50:23
okey,我如何定義管理規則並允許他註冊某人?我會做你說的。 – canmuratt 2014-12-02 10:52:07