问题描述
我正在用smack进行聊天应用程序。我是这项技术的新手。
I am doing Chat application with smack . I am new for this technology.
我已经从Ejabberd服务器创建了一些手动用户。使用这些用户,我已经进行了一对一的聊天和群聊。
I have created some manual users from Ejabberd server. Using those users I have done one to one chat and group chat.
但是我试图从android代码
创建新用户,但出现以下错误
But I tried to create new user from android code But I am getting this below error
XMPPError: forbidden - auth
08-02 08:23:36.273 31097-31097/com.agarangroup.hello W/System.err: at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:232)
08-02 08:23:36.273 31097-31097/com.agarangroup.hello W/System.err: at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:207)
我在ejabberd服务器中
This is the configuration I have in ejabberd server
announce [{allow,[{acl,admin}]}]
c2s [{deny,[{acl,blocked}]},{allow,[{acl,all}]}]
c2s_shaper [{none,[{acl,admin}]},{normal,[all]}]
configure [{allow,[{acl,admin}]}]
local [{allow,[{acl,all}]}]
max_user_offline_messages [{5000,[{acl,admin}]},{100,[all]}]
max_user_sessions [{10,[all]}]
muc_create [{allow,[{acl,all}]}]
pubsub_createnode [{allow,[{acl,local}]}]
register [{allow,[{acl,all}]}]
s2s_shaper [{fast,[all]}]
trusted_network [{allow,[{acl,loopback}]}]
已更新:
此处我正在初始化连接
private void initialiseConnection() {
DomainBareJid serviceName = null;
try {
serviceName = JidCreate.domainBareFrom(ServiceAddress);
} catch (XmppStringprepException e) {
e.printStackTrace();
}
XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration
.builder().setKeystoreType(null);
// XMPPTCPConnectionConfiguration.builder().setKeystoreType(null);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setServiceName(serviceName);
config.setHost(serverAddress);
config.setPort(5222);
config.setDebuggerEnabled(true);
XMPPTCPConnection.setUseStreamManagementDefault(true);
connection = new XMPPTCPConnection(config.build());
XMPPConnectionListener connectionListener = new XMPPConnectionListener();
connection.addConnectionListener(connectionListener);
}
初始化后,我正在连接此连接
connection.connect();
DeliveryReceiptManager dm = DeliveryReceiptManager
.getInstanceFor(connection);
dm.setAutoReceiptMode(AutoReceiptMode.always);
dm.addReceiptReceivedListener(new ReceiptReceivedListener() {
@Override
public void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt) {
}
});
connected = true;
创建新用户的方法
public void createNewUser(){
try {
/* UserRegisterUtil.registerAccount(connection,"Mathan","mathan@4792");
connection.disconnect();
connection.connect();*/
Localpart lp = Localpart.from("IamHere");
// Registering the user
AccountManager accountManager = AccountManager.getInstance(connection);
accountManager.sensitiveOperationOverInsecureConnection(true);
accountManager.createAccount(lp, "mathan123"); // Skipping optional fields like email, first name, last name, etc..
Toast.makeText(context, "=>User creation completed....",
Toast.LENGTH_LONG).show();
Log.d("xmpp", ">User creation completed....!");
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
}
}
这是我得到的错误,它表示被ACL拒绝。但是我不知道如何在Windows ejabberd服务器中更改它。
It's an error I got It says Denied by ACL. But I don't know how to change it in windows ejabberd server.
<error code='403' type='auth'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Denied by ACL</text></error>
谁能告诉我如何创建一个新用户,我想在此配置中进行哪些更改文件?
我也有疑问
如何获取离线消息
如何获取聊天记录?
推荐答案
-
转到
/etc/ejabberd/ejabberd.yml
几乎在文件末尾的部分模块
下,更改 mod_register:ip_access:trusted_network
到 mod_register:ip_access:all
Almost at the end of file, under Section modules
, change mod_register:ip_access:trusted_network
to mod_register:ip_access:all
这篇关于在ejabberd上使用Smack 4.2.0-beta1创建新用户将引发XMPP异常:禁止-auth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!