【发布时间】:2016-12-07 16:20:46
【问题描述】:
我正在使用 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 中获取离线消息?
如何获取聊天记录?
【问题讨论】:
标签: android xmpp ejabberd smack