title: Spring security ldap authenticate first
body: <p>I have set up an ldap authentication using the following configuration.  I just need to user to authenticate to the LDAP data store, then have their session get an authentication token.  From reading the docs, this is what I am thinking is supposed to happen:</p>
  
  <ol>
  <li>Authenticate as the manager, find the users full dn based on search criteria</li>
  <li>Attempt to bind as the user (using their full dn) and the provided password</li>
  </ol>
  
  <p>The logs dont seem to give enough information as to why this is failing.  It just says invalid credentials - when I know they are valid.  My thoughts are one of the following is happening:</p>
  
  <ol>
  <li>The users full DN is not being found, and they are just being authenticated with the username</li>
  <li>It is trying to do a password compare, vs actually trying to bind to the directory</li>
  </ol>
  
  <p>Configuration:</p>
  
  <pre><code>&lt;ldap-server 
      url="ldap://adapps.company.com:389/dc=company,dc=com" 
      manager-dn="cn=fulluserdn,dc=company,dc=com" 
      manager-password="password"/&gt;
  &lt;ldap-user-service user-search-base="" user-search-filter="(samaccountname={0})"/&gt;  
  &lt;authentication-manager&gt;
  &lt;ldap-authentication-provider user-search-filter="(samaccountname={0})" user-search-base="dc=company,dc=com"/&gt;
  &lt;/authentication-manager&gt;
  </code></pre>
  
  <p>Error logs:</p>
  
  <pre><code>[DEBUG,FilterBasedLdapUserSearch] Searching for user 'test', with user search [ searchFilter: '(samaccountname={0})', searchBase: 'dc=company,dc=com', scope: subtree, searchTimeLimit: 0, derefLinkFlag: false ]
  [DEBUG,AbstractContextSource] Got Ldap context on server 'ldap://adapps.company.com:389/dc=company,dc=com'
  [INFO,SpringSecurityLdapTemplate] Ignoring PartialResultException
  [DEBUG,XmlWebApplicationContext] Publishing event in Root WebApplicationContext: org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent[source=org.springframework.security.authentication.UsernamePasswordAuthenticationToken@488b5f0b: Principal: test; Password: [PROTECTED]; Authenticated: false; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffd148a: RemoteIpAddress: 127.0.0.1; SessionId: 0718B7EED3F930C63C03DA97C4344CBD; Not granted any authorities]
  [DEBUG,UsernamePasswordAuthenticationFilter] Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
  [DEBUG,UsernamePasswordAuthenticationFilter] Updated SecurityContextHolder to contain null Authentication
  [DEBUG,UsernamePasswordAuthenticationFilter] Delegating to authentication failure handlerorg.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler@395158
  [DEBUG,TokenBasedRememberMeServices] Interactive login attempt was unsuccessful.
  [DEBUG,TokenBasedRememberMeServices] Cancelling cookie
  </code></pre>