asmack-android-8-4.0.6:使用DIGEST-MD5的SASLError:未经授权

时间:2015-01-15 16:12:11

标签: 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时我得到以下错误。 有谁知道如何修复它?

此处为Connect方法:

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();
}

1 个答案:

答案 0 :(得分:1)

也许您应该在添加XMPPTCPConnection配置之前添加此代码:

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