title: SASLError using PLAIN: not-authorized
body: <p>I am trying to shift my app from <code>aSmack</code> to <code>Smack 4.1.1</code>. However I am having trouble using the same server and login details in the case of Smack while on aSmack it is working excellently.</p>
  
  <p>Here's my old code of login in <code>aSmack</code> - </p>
  
  <pre><code>void startConnect(boolean sslFlag) throws XMPPException, SmackException, IOException {
          ConnectionConfiguration connectionConfig =
                  new ConnectionConfiguration(HOST, Integer.parseInt(PORT), SERVICE);
          connectionConfig.setDebuggerEnabled(true);
          connectionConfig.setCompressionEnabled(false);
  
          if (sslFlag)
              SASLAuthentication.supportSASLMechanism("PLAIN", 0);
  
          XMPPConnection connection = new XMPPTCPConnection(connectionConfig);
  
              connection.connect();
              connection.login(mUserName, mUserPassword, getResource());
  
              // Set status to online / available
              Presence presence = new Presence(Presence.Type.available);
              connection.sendPacket(presence);
              setConnection(connection);
      }
  </code></pre>
  
  <p>I am trying to use code on similar fashion in <code>Smack</code> too - </p>
  
  <pre><code>public void init() {
          SmackConfiguration.DEBUG = true;
          XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                  .setHost(SERVICE_NAME)
                  .setPort(5222)
                  .setServiceName(SERVICE_NAME)
                  .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                  .setDebuggerEnabled(true)
                  .build();
          mConnection = new XMPPTCPConnection(config);
  
  //I have tried with blacklisting and unblacklisting all three mechanism.
          //SASLMechanism mechanism = new SASLPlainMechanism(); //This didn't help
          //SASLAuthentication.registerSASLMechanism(mechanism);
          SASLAuthentication.blacklistSASLMechanism("SCRAM-SHA-1");
          SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");
          SASLAuthentication.unBlacklistSASLMechanism("PLAIN"); 
          try {
              mConnection.connect();
              return;
          } catch (SmackException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (XMPPException e) {
              e.printStackTrace();
          }
          mConnection = null;
      }
  
      public void login(String username, String password) throws IOException, XMPPException, SmackException {
  
          if(mConnection==null || !mConnection.isConnected()){
              init();
              if(mConnection==null){
                  throw new IOException();
              }
          }
          mConnection.login(username/*+"@"+SERVICE_NAME*/, password); //I have tried both the method by adding @Domain part and without it.
  
          mChatManager = ChatManager.getInstanceFor(mConnection);
          mChatManager.addChatListener(this);
      }
  </code></pre>
  
  <p>Here's the exception I am getting - </p>
  
  <pre><code>05-21 21:22:29.782  19536-23179/test W/System.err﹕ org.jivesoftware.smack.sasl.SASLErrorException: SASLError using PLAIN: not-authorized
  05-21 21:22:29.782  19536-23179/test W/System.err﹕ at org.jivesoftware.smack.SASLAuthentication.authenticationFailed(SASLAuthentication.java:365)
  05-21 21:22:29.792  19536-23179/test W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1033)
  05-21 21:22:29.792  19536-23179/test W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:937)
  05-21 21:22:29.792  19536-23179/test W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:952)
  05-21 21:22:29.792  19536-23179/test W/System.err﹕ at java.lang.Thread.run(Thread.java:856)
  </code></pre>
  
  <p>This exception is same with SCRAM and DIGEST-MD5 too. It just changes the name.</p>
  
  <p>Here's what I am getting from server - </p>
  
  <pre><code>05-21 21:22:29.512  19536-23189/test D/SMACK﹕ SENT (0): &lt;stream:stream xmlns='jabber:client' to='xmpp.example.com' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'&gt;
  05-21 21:22:29.642  19536-23190/test D/SMACK﹕ RECV (0): &lt;?xml version='1.0'?&gt;&lt;stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='214326363' from='xmpp.example.com' version='1.0' xml:lang='en'&gt;&lt;stream:features&gt;&lt;compression xmlns='http://jabber.org/features/compress'&gt;&lt;method&gt;zlib&lt;/method&gt;&lt;/compression&gt;&lt;mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'&gt;&lt;mechanism&gt;SCRAM-SHA-1&lt;/mechanism&gt;&lt;mechanism&gt;PLAIN&lt;/mechanism&gt;&lt;mechanism&gt;DIGEST-MD5&lt;/mechanism&gt;&lt;/mechanisms&gt;&lt;c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='hX7OB6oTZugjNIFHZvd95k5UYzc='/&gt;&lt;register xmlns='http://jabber.org/features/iq-register'/&gt;&lt;/stream:features&gt;
  05-21 21:22:29.652  19536-23189/test D/SMACK﹕ SENT (0): &lt;auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'&gt;ADEwMDAAMTAwMA==&lt;/auth&gt;
  05-21 21:22:29.782  19536-23190/test D/SMACK﹕ RECV (0): &lt;failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'&gt;&lt;not-authorized/&gt;&lt;/failure&gt;
  </code></pre>
  
  <p>What could be the issue here? I have tried with all three mechanism <code>PLAIN</code>, <code>DIGEST-MD5</code> and the default <code>SCRAM-SHA-1</code>. I have also tried with or without adding domain name on it. I have tried it with adding username and password in configuration and by adding it directly on login method. </p>
  
  <p>I have tried with required security mode too which gives the following error - </p>
  
  <pre><code>05-21 21:27:53.658  25643-26009/test D/SMACK﹕ SENT (0): &lt;stream:stream xmlns='jabber:client' to='xmpp.example.com' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'&gt;
  05-21 21:27:53.788  25643-26010/test D/SMACK﹕ RECV (0): &lt;?xml version='1.0'?&gt;&lt;stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='4179863647' from='xmpp.example.com' version='1.0' xml:lang='en'&gt;&lt;stream:features&gt;&lt;compression xmlns='http://jabber.org/features/compress'&gt;&lt;method&gt;zlib&lt;/method&gt;&lt;/compression&gt;&lt;mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'&gt;&lt;mechanism&gt;SCRAM-SHA-1&lt;/mechanism&gt;&lt;mechanism&gt;PLAIN&lt;/mechanism&gt;&lt;mechanism&gt;DIGEST-MD5&lt;/mechanism&gt;&lt;/mechanisms&gt;&lt;c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='hX7OB6oTZugjNIFHZvd95k5UYzc='/&gt;&lt;register xmlns='http://jabber.org/features/iq-register'/&gt;&lt;/stream:features&gt;
  05-21 21:27:54.229  25643-26009/test D/SMACK﹕ SENT (0): &lt;auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'&gt;ADEwMDAAMTAwMA==&lt;/auth&gt;
  05-21 21:27:59.264  25643-25970/test W/System.err﹕ org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: No filter used or filter was 'null'.
  05-21 21:27:59.454  25643-26010/test W/AbstractXMPPConnection﹕ Connection closed with error
      org.jivesoftware.smack.SmackException$SecurityRequiredByClientException: SSL/TLS required by client but not supported by server
              at org.jivesoftware.smack.tcp.XMPPTCPConnection.afterFeaturesReceived(XMPPTCPConnection.java:898)
              at org.jivesoftware.smack.AbstractXMPPConnection.parseFeatures(AbstractXMPPConnection.java:1367)
              at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$800(XMPPTCPConnection.java:139)
              at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:998)
              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-21 21:27:59.494  25643-25970/test W/System.err﹕ at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:250)
  05-21 21:27:59.494  25643-25970/test W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginNonAnonymously(XMPPTCPConnection.java:365)
  05-21 21:27:59.524  25643-25970/test W/System.err﹕ at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:452)
  05-21 21:27:59.544  25643-25970/test W/System.err﹕ at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:427)
  05-21 21:27:59.574  25643-25970/test W/System.err﹕ at test.Managers.XMPPManager.login(XMPPManager.java:84)
  05-21 21:27:59.594  25643-25970/test W/System.err﹕ at test.API.LoginAPI.callAPI(LoginAPI.java:31)
  05-21 21:27:59.604  25643-25970/test W/System.err﹕ at test.API.BaseAPI$XMPPTask.doInBackground(BaseAPI.java:70)
  05-21 21:27:59.624  25643-25647/test D/dalvikvm﹕ GC_CONCURRENT freed 1558K, 17% free 30564K/36743K, paused 13ms+32ms, total 111ms
  05-21 21:27:59.624  25643-25970/test W/System.err﹕ at test.API.BaseAPI$XMPPTask.doInBackground(BaseAPI.java:45)
  05-21 21:27:59.624  25643-25970/test W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
  05-21 21:27:59.624  25643-25970/test W/System.err﹕ at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  05-21 21:27:59.664  25643-25970/test W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  05-21 21:27:59.664  25643-25970/test W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
  05-21 21:27:59.664  25643-25970/test W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
  05-21 21:27:59.664  25643-25970/test W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  05-21 21:27:59.664  25643-25970/test W/System.err﹕ at java.lang.Thread.run(Thread.java:856)
  </code></pre>
  
  <p><strong>PS:</strong><br>
  I need the solution in Smack 4.1.1. My code is already working good in aSmack, I need it to upgrade it in Smack. I guess it's clear now.</p>