android - asmack-android-8-4.0.6 : SASLError using DIGEST-MD5: not-authorized

标签 android smack asmack

成功连接后登录时出现以下错误:

01-15 20:44:07.448  30164-30196/com.stm.myjob E/XMPPService﹕ Failed to log in as
8b6c219c36578e893c5e6d1d7b5af8a
01-15 20:44:07.448  30164-30196/com.stm.myjob E/XMPPService﹕
org.jivesoftware.smack.sasl.SASLErrorException: SASLError using DIGEST-MD5: not-authorized
01-15 20:47:07.891  30164-30223/com.stm.myjob W/PacketWriter﹕ Exception writing closing stream
element
java.net.SocketException: sendto failed: EPIPE (Broken pipe)
        at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:546)
        at libcore.io.IoBridge.sendto(IoBridge.java:515)
        at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504)
        at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37)
        at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266 )
        at java.io.OutputStreamWriter.flushBytes(OutputStreamWriter.java:167)
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:158)
        at java.io.BufferedWriter.flush(BufferedWriter.java:124)
        at org.jivesoftware.smack.tcp.PacketWriter.writePackets(PacketWriter.java:190)
        at org.jivesoftware.smack.tcp.PacketWriter.access$000(PacketWriter.java:40)
        at org.jivesoftware.smack.tcp.PacketWriter$1.run(PacketWriter.java:77)
 Caused by: android.system.ErrnoException: sendto failed: EPIPE (Broken pipe)
        at libcore.io.Posix.sendtoBytes(Native Method)
        at libcore.io.Posix.sendto(Posix.java:176)
        at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278)
        at libcore.io.IoBridge.sendto(IoBridge.java:513)
        at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504)
        at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37)
        at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266 )
        at java.io.OutputStreamWriter.flushBytes(OutputStreamWriter.java:167)
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:158)
        at java.io.BufferedWriter.flush(BufferedWriter.java:124)
        at org.jivesoftware.smack.tcp.PacketWriter.writePackets(PacketWriter.java:190)
        at org.jivesoftware.smack.tcp.PacketWriter.access$000(PacketWriter.java:40)
        at org.jivesoftware.smack.tcp.PacketWriter$1.run(PacketWriter.java:77)

我在 OpenFire 服务器上打开用户,用户名 8b6c219c36578e893c5e6d1d7b5af8a@myjob.uz。如果我使用 asmack-2010.05.07 一切正常,但使用 asmack-android-8-4.0.6 时出现以下错误。\ 有人知道如何解决吗?

这里连接方法:

private void connect(final String login, final String password) {
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            // Create a connection
            ConnectionConfiguration connConfig = new ConnectionConfiguration(
                    AppConfig.XMPP_HOST, AppConfig.XMPP_PORT, AppConfig.XMPP_SERVICE);
            connConfig.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

            XMPPConnection connection = new XMPPTCPConnection(connConfig);

            try {
                HLog.i(TAG, "XMPP connecting ...");
                connection.connect();
                HLog.i(TAG,
                        "Connected to " + connection.getHost());
            } catch (XMPPException ex) {
                HLog.e(TAG, "Failed to connect to "
                        + connection.getHost());
                HLog.e(TAG, ex.toString());
                setConnection(null);
            } catch (SmackException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                // SASLAuthentication.supportSASLMechanism("PLAIN", 0);
                connection.login(AppConfig.TEST_USERNAME, AppConfig.TEST_PASSWORD);
                HLog.i(TAG,
                        "HLogged in as " + connection.getUser());

                // Set the status to available
                Presence presence = new Presence(Presence.Type.available);
                connection.sendPacket(presence);
                setConnection(connection);
            } catch (XMPPException ex) {
                HLog.e(TAG, "Failed to log in as "
                        + login);
                HLog.e(TAG, ex.toString());
                setConnection(null);
            } catch (SmackException sexp) {
                sexp.printStackTrace();
            } catch (IOException ioexp) {
                ioexp.printStackTrace();
            }
        }
    });
    t.start();
}

最佳答案

也许你应该在添加 XMPPTCPConnection 配置之前添加这段代码:

   SASLAuthentication.registerSASLMechanism("PLAIN", SASLPlainMechanism.class);
   SASLAuthentication.supportSASLMechanism("PLAIN",0);

关于android - asmack-android-8-4.0.6 : SASLError using DIGEST-MD5: not-authorized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27967859/

相关文章:

android - 发送自定义 IQ 时来自服务器的服务不可用响应

Android 文件传输无法通过 XMPP 和 OpenFire 工作

android - 使用 Jabber ID 的 Facebook 连接

java - 与 Smack 4.0.* 的 TLS 客户端连接的简单示例

Android:nextFocusDown 不工作

android - Fragment 不显示任何内容

android - 突出显示列表中的 TextView 项

android - openfire 中的延迟群发消息

facebook - 使用 Smack 集成 Facebook 聊天时 SASL 身份验证失败

android - 嵌套的可包裹对象未读取