title: RabbitMQ invalid credentials with valid information
body: <p>I'm working with some Java/Spring web applications and RabbitMQ.
  I have App1 and App2 on the <strong>same</strong> tomcat server at the address <code>192.168.0.101</code>.
  They both communicate with a RabbitMQ server located at : <code>192.168.0.100</code>.</p>
  
  <p>App1 has this configuration in the spring context:</p>
  
  <pre><code>&lt;bean id="connectionFactory"
      class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory"
      destroy-method="destroy"&gt;
      &lt;property name="host" value="192.168.0.100" /&gt;
      &lt;property name="username" value="app" /&gt;
      &lt;property name="password" value="guest" /&gt;
      &lt;property name="virtualHost" value="/" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>App2 has the same config except a different username, let's say:</p>
  
  <pre><code>&lt;bean id="connectionFactory"
      class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory"
      destroy-method="destroy"&gt;
      &lt;property name="host" value="192.168.0.100" /&gt;
      &lt;property name="username" value="app2" /&gt;
      &lt;property name="password" value="guest" /&gt;
      &lt;property name="virtualHost" value="/" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>The problem is that App1 can connect successfully to the RabbitMQ server, and App2 has always a <code>invalid credentials</code> error in the RabbitMQ logs.</p>
  
  <p>Here is the permissions list for these users:</p>
  
  <pre><code>Listing permissions in vhost "/" ...
  app    .*    .*    .*
  app2   .*    .*    .*
  </code></pre>
  
  <p>And here is what I get when I try to log in with the API (with both users): <code>curl -i -u app:guest http://192.168.0.100:15672/api/whoami</code> and <code>curl -i -u app2:guest http://192.168.0.100:15672/api/whoami</code></p>
  
  <pre><code>HTTP/1.1 401 Unauthorized
  Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
  Date: Mon, 30 Jun 2014 14:58:37 GMT
  Content-Length: 57
  
  {"error":"not_authorised","reason":"Not management user"}
  </code></pre>
  
  <p>which seems pretty normal, I think, each user is recognized as valid user but not authorized for management. When I set the management tag for app2, I get this :</p>
  
  <pre><code>curl -i -u app2:guest http://192.168.0.100:15672/api/whoami
  HTTP/1.1 200 OK
  Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
  Date: Mon, 30 Jun 2014 15:14:29 GMT
  Content-Type: application/json
  Content-Length: 80
  Cache-Control: no-cache
  
  {"name":"app2","tags":"management","auth_backend":"rabbit_auth_backend_internal"}
  </code></pre>
  
  <p>I know this is a lot of code but this is all I get, and I'm about to give up and never know what's going on. I really don't understand what I am doing wrong because configurations looks exactly the same.</p>
  
  <p>What do you think ?</p>
  
  <p>Thanks in advance ! A lot.</p>
  
  <p>EDIT:
  Here is the rabbitMq log line that I get when app2 tries to connect:</p>
  
  <pre><code>=ERROR REPORT==== 30-Jun-2014::16:42:38 ===
  closing AMQP connection &lt;0.1241.0&gt; (192.168.0.101:52871 -&gt; 192.168.0.100:5672):
  {handshake_error,starting,0,
               {amqp_error,access_refused,
                           "PLAIN login refused: user 'app2' - invalid credentials",
                           'connection.start_ok'}}
  </code></pre>
  
  <p>EDIT2:
  And here is the Java error log that I get at the moment the app2 tries to connect:</p>
  
  <pre><code>    Caused by: com.rabbitmq.client.PossibleAuthenticationFailureException: Possibly caused by authentication failure
          at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:355)
          at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:516)
          at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:545)
          at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:181)
          ... 48 more
      Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; reason: java.net.SocketException: Connection reset
          at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
          at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
          at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
          at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:216)
          at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:202)
          at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:347)
          ... 51 more
      Caused by: java.net.SocketException: Connection reset
          at java.net.SocketInputStream.read(SocketInputStream.java:196)
          at java.net.SocketInputStream.read(SocketInputStream.java:122)
          ...
  </code></pre>