2011-10-10 123 views
5

StackOverflow的好人,請幫忙。 我在我的ubuntu機器上設置了一個ejabberd服務器,添加了虛擬主機,設置爲 {access,register,[{allow,all}]}。 並註冊了一個管理員帳戶。我不是Linux大師,但我已經設法完成這個基本設置。 現在,從我的Win 7機器上,使用Pidgin,我可以以管理員身份登錄並訪問許多管理功能。最重要的是我可以在服務器上創建新用戶。 問題是,我不能用我的android客戶端使用asmack庫來做到這一點。我可以建立連接和登錄,但是當我嘗試通過帳戶管理器註冊新用戶或發送IQ數據包時,我會禁止(403)響應錯誤。asmack XMPP新用戶註冊

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", "[email protected]"); 
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='[email protected]/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>[email protected]</username></query></iq> 
10-10 10:00:26.969: INFO/System.out(21277): 10:00:26 AM RCV (1080244736): <iq from='morena.local' to='[email protected]/Smack' id='fMJxx-5' type='error'><query xmlns='jabber:iq:register'><password>new_user</password><username>[email protected]</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='[email protected]/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>[email protected]</email><password>new_user1</password><username>[email protected]</username><name>[email protected]</name></query></iq> 
10-10 10:00:31.699: INFO/System.out(21277): 10:00:31 AM RCV (1080244736): <iq from='morena.local' to='[email protected]/Smack' id='fMJxx-7' type='error'><query xmlns='jabber:iq:register'><email>[email protected]</email><password>new_user1</password><username>[email protected]</username><name>[email protected]</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) 
+0

也許這可以幫助您的Windows機器 –

+0

,你確定你的防火牆不阻止5222端口? – Maggie

+0

你解決了這個問題? – CoronaPintu

回答

8

我找到了! 問題出在服務器配置中(但我仍不明白爲什麼我可以在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}, 
     ... 
       ] ... 
0

要註冊使用嫌庫的新用戶。

/** * 註冊一個新的客戶端在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(); 
    } 
} 
+0

這個拋出異常。我安裝了openfire和spark,所以沒有ejabbaer/ejabberd.cfg文件。你能幫我在openfire – CoronaPintu

3

假如您指定mod_registerip_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地址的註冊賬戶,但不是一個Android客戶端使用,這是不同的IP。

我一直在面對一個相關的問題,出於某種原因,{access_from, register_from}解決方案對您而言並沒有像我預期的那樣工作。您是否能夠將創建新帳戶的能力限制爲只有admin用戶?

5

工作對我來說這個代碼註冊一個新的賬號:

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

以下設置ejabberd:

{接入,註冊,[{允許,所有}]}。

這是一個非常安全的設置,因爲它可以在服務器上沒有我們的身份驗證帳戶進行記錄(方法supports.AccountCreation()返回true)。

1

我遇到了同樣的問題,找到了解決辦法:

請在服務器

變化洛後從烏爾管理界面ejabbered。 轉到虛擬主機節點模塊,mod_register並添加:

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

N個U就會B,能夠從客戶端成功創建帳戶

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}. 
+0

我安裝了openfire和spark,所以沒有ejabbaer/ejabberd.cfg文件。你能在openfire幫助我嗎? – CoronaPintu

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

我現在希望它會爲你工作。