title: RabbitMQ LDAP authentication failing
body: <p>I'm going through the process of setting up RabbitMQ with LDAP authorization but am not having much luck...  Could someone in the know, please take a look and tell me what I'm doing wrong?  I'm able to query LDAP to get the user object with the following code:</p>
  
  <pre><code>var entry = new DirectoryEntry("LDAP://ourldapbox.ourcompany.co.uk:636/CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk");
  </code></pre>
  
  <p><strong>Config Attempt 1</strong></p>
  
  <pre><code>[
    {rabbit, [{auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},
    {rabbitmq_auth_backend_ldap,
     [ {servers,               ["ourldapbox.ourcompany.co.uk"]},
       {user_dn_pattern,       "CN=${username},OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk"},
       {use_ssl,               false},
       {port,                  636},
       {log,                   true}
     ]
    }
  ].
  </code></pre>
  
  <p><strong>Config Attempt 2</strong></p>
  
  <pre><code>[
    {rabbit, [{auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},
    {rabbitmq_auth_backend_ldap,
     [ {servers,               ["ourldapbox.ourcompany.co.uk"]},
       {dn_lookup_attribute,   "sAMAccountName"},
       {dn_lookup_base,        "DC=ourcompany,DC=co,DC=uk"},
       {user_dn_pattern,       "${username}@ourcompany.co.uk"},
       {other_bind,            anon},
       {use_ssl,               false},
       {port,                  636},
       {log,                   true}
     ]
    }
  ].
  </code></pre>
  
  <p><strong>Config Attempt 3</strong></p>
  
  <pre><code>[
    {rabbit, [{auth_backends, [rabbit_auth_backend_ldap, rabbit_auth_backend_internal]}]},
    {rabbitmq_auth_backend_ldap,
     [ {servers,               ["ourldapbox.ourcompany.co.uk"]},
       {dn_lookup_attribute,   "userPrincipalName"},
       {dn_lookup_base,        "dc=ourcompany,dc=co,dc=uk"},
       {user_dn_pattern,       "${username}@ourcompany.co.uk"},
       {use_ssl,               false},
       {port,                  636},
       {log,                   true}
     ]
    }
  ].
  </code></pre>
  
  <p><strong>Connection Code</strong></p>
  
  <p>I'm attempting to connect in a number of ways (all failing):</p>
  
  <pre><code>var connectionFactory = new ConnectionFactory
  {
      HostName = "localhost",
      UserName = "twainm",
      Password = "fred123",
  };
  
  using (connectionFactory.CreateConnection())
  {
      // fails with:
      // None of the specified endpoints were reachable
      // ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
  }
  </code></pre>
  
  <p>The internal database fallback configuration is working, so <code>guest</code> is able to connect without issue.</p>
  
  <p><strong>Logs</strong></p>
  
  <pre><code>=INFO REPORT==== 18-Feb-2015::10:38:13 ===
  accepting AMQP connection &lt;0.1122.0&gt; ([::1]:20117 -&gt; [::1]:5672)
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
  LDAP CHECK: login for Mark Twain
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
          LDAP filling template "CN=${username},OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk" with
              [{username,&lt;&lt;"Mark Twain"&gt;&gt;}]
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
          LDAP template result: "CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk"
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
  LDAP CHECK: login for Mark Twain
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
          LDAP filling template "CN=${username},OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk" with
              [{username,&lt;&lt;"Mark Twain"&gt;&gt;}]
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
          LDAP template result: "CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk"
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
      LDAP bind error: CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk {gen_tcp_error,
                                                                                                      closed}
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
  LDAP DECISION: login for Mark Twain: {error,{gen_tcp_error,closed}}
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
      LDAP bind error: CN=Mark Twain,OU=Development,OU=OurCompany Employees,DC=OurCompany,DC=co,DC=uk {gen_tcp_error,
                                                                                                      closed}
  
  =INFO REPORT==== 18-Feb-2015::10:38:13 ===
  LDAP DECISION: login for Mark Twain: {error,{gen_tcp_error,closed}}
  
  =ERROR REPORT==== 18-Feb-2015::10:38:16 ===
  closing AMQP connection &lt;0.1122.0&gt; ([::1]:20117 -&gt; [::1]:5672):
  {handshake_error,starting,0,
                   {amqp_error,access_refused,
                               "PLAIN login refused: user 'Mark Twain' - invalid credentials",
                               'connection.start_ok'}}
  </code></pre>
  
  <p>I've had a good Google for "LDAP bind error", "handshake_error,starting,0" and "access_refused" but can't find anything that could point me in the right direction.</p>
  
  <p>Any help would be appreciated.</p>