4

Related Question: Initialization exception "NoClassDefFoundError: javax.naming.directory.InitialDirContext" when using Smack 4.1 on Android

I am using Smack 4.1.1 in my Android app and I am getting the following exception -

05-19 21:38:31.141    8330-8803/test W/SASLError﹕ Could not transform string 'bad_auth' to SASLError
    java.lang.IllegalArgumentException: bad_auth is not a constant in org.jivesoftware.smack.sasl.SASLError
            at java.lang.Enum.valueOf(Enum.java:192)
            at org.jivesoftware.smack.sasl.SASLError.valueOf(SASLError.java:22)
            at org.jivesoftware.smack.sasl.SASLError.fromString(SASLError.java:46)
            at org.jivesoftware.smack.sasl.packet.SaslStreamElements$SASLFailure.<init>(SaslStreamElements.java:169)
            at org.jivesoftware.smack.util.PacketParserUtils.parseSASLFailure(PacketParserUtils.java:789)
            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1032)
            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:937)
            at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:952)
            at java.lang.Thread.run(Thread.java:856)
05-19 21:38:31.221    8330-8766/test W/System.err﹕ org.jivesoftware.smack.sasl.SASLErrorException: SASLError using SCRAM-SHA-1: bad-auth
05-19 21:38:31.231    8330-8766/test W/System.err﹕ at org.jivesoftware.smack.SASLAuthentication.authenticationFailed(SASLAuthentication.java:365)
05-19 21:38:31.231    8330-8766/test W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1033)
05-19 21:38:31.231    8330-8766/test W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:937)
05-19 21:38:31.231    8330-8766/test W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:952)
05-19 21:38:31.231    8330-8766/test W/System.err﹕ at java.lang.Thread.run(Thread.java:856)

This is my current login code -

public void login(String username, String password) throws IOException, XMPPException, SmackException {

        XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                .setUsernameAndPassword(username, password)
                .setHost(SERVICE_NAME)
                .setPort(5222)
                .setServiceName(SERVICE_NAME)
                .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                .build();


        mConnection = new XMPPTCPConnection(config);

        mConnection.connect();
        mConnection.login();

        mChatManager = ChatManager.getInstanceFor(mConnection);
        mChatManager.addChatListener(this);
    }

I have tried to use Plain SASL mechanism -

SASLAuthentication.registerSASLMechanism(new SASLPlainMechanism());

And also tried the following code too

    SASLMechanism mechanism = new SASLDigestMD5Mechanism();
    SASLAuthentication.registerSASLMechanism(mechanism);
    SASLAuthentication.blacklistSASLMechanism("SCRAM-SHA-1");
    SASLAuthentication.unBlacklistSASLMechanism("DIGEST-MD5");

All of them doesn't work.

I am able to successfully use the same server to iOS(using XMPPFramework) and on WPF (using S22). I have also used it in pidgin to test. It works fine everywhere, so I am sure I am missing some essential step in authenticating in smack. How can I know which is the correct way of logging in to the specified server?

Community
  • 1
  • 1
0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
  • Could you post your exact code for this snippet, including the try-block? – y0da May 21 '15 at 00:31
  • @y0da My actual code is a lot complex which spans to several classes since the login method can not be called in main UI thread. I can't post everything. But I am sure this is the problem region. – 0xC0DED00D May 21 '15 at 13:07
  • @noob have You found a solution? Got the same problem... – Opiatefuchs Jun 03 '15 at 06:11
  • @Opiatefuchs That was due to entering wrong password all the time. I did debug the code later and found out, after I tried changing the server. The value of password was not going correct to the Authentication part. I hope this will help. – 0xC0DED00D Jun 09 '15 at 11:15
  • @noob u got any solution for this?? – PankajAndroid Aug 19 '15 at 11:34
  • @PankajAndroid The password was wrong. The code to enter the password was not correct. Debug your code too, your password might be wrong. – 0xC0DED00D Aug 19 '15 at 12:15

1 Answers1

1
05-19 21:38:31.141    8330-8803/test W/SASLError﹕ Could not transform string 'bad_auth' to SASLError
    java.lang.IllegalArgumentException: bad_auth is not a constant in org.jivesoftware.smack.sasl.SASLError
            at java.lang.Enum.valueOf(Enum.java:192)

"bad_auth" is not a defined SASL error as per RFC 6120 § 6.5. SASL Errors. Tell the vendor of the used XMPP server to fix that.

Flow
  • 23,572
  • 15
  • 99
  • 156
  • Well that doesn't solve the issue. Undefined error is still an error. I got the server working with other frameworks. Is there anything I can do to make it work using Smack? I just have the web admin panel access to it. Btw it's eJabberd if that matters. – 0xC0DED00D May 19 '15 at 20:00
  • There is no issue to solve. You would get an exception either way. – Flow Jun 09 '15 at 12:34