我正在用smack做聊天应用程序。我是这项技术的新手。
我已经从Ejabberd服务器创建了一些手动用户。使用这些用户,我进行了一对一的聊天和群聊。
但我试图从android代码创建新用户 但我得到以下错误
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服务器中的配置
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服务器中更改它。
<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>
有谁能告诉我如何创建新用户,我想在此配置文件中更改哪些内容?
我也有一些疑问
如何使用smack库在android中获取离线消息?
如何获取聊天记录?
答案 0 :(得分:1)
关于用户创建:您需要先连接(不登录)连接。
此外,所有用户名必须为小写:
accountManager.createAccount(lp.toLowerCase(), "mathan123");
<小时/> 关于离线消息:当用户上线时将调度它们
关于聊天记录:抱歉,我没有与Ejabber合作,但对于正常聊天1vs1,您可能需要在客户端上存储或在服务器上添加一些自定义功能(如Openfire)。
答案 1 :(得分:1)
转到/etc/ejabberd/ejabberd.yml
几乎在文件末尾的Section modules
下,将mod_register:ip_access:trusted_network
更改为mod_register:ip_access:all