title: Spring Security - LDAP - BadCredentialsException:
body: <p>I am not able to validate a user using spring security, I get a BadCredentailException. 
  My spring security configuration is:</p>
  
  <pre><code>&lt;bean id="contextSource"
        class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"&gt;
      &lt;constructor-arg value="ldaps://ldaps.prod.sam.com:636"/&gt;
      &lt;property name="userDn" value="CN=!testUser1,OU=Service Accounts,OU=User Accounts,DC=prod,DC=sam,DC=com"/&gt;
      &lt;property name="password" value="!!testPass1!!"/&gt;
      &lt;property name="referral" value="follow"/&gt;
  &lt;/bean&gt;
  &lt;bean class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch" id="ldapSearchBean"&gt;
      &lt;constructor-arg value="OU=User Accounts,DC=prod,DC=sam,DC=com"/&gt;
      &lt;constructor-arg value="(sAMAccountName={0})"/&gt;
      &lt;constructor-arg ref="contextSource"/&gt;
      &lt;property name="searchSubtree" value="true"/&gt;
  &lt;/bean&gt;
  &lt;bean class="org.springframework.security.ldap.authentication.BindAuthenticator" id="ldapBindAuthenticator"&gt;
      &lt;constructor-arg ref="contextSource"/&gt;
      &lt;property name="userSearch" ref="ldapSearchBean"/&gt;
  &lt;/bean&gt;
  &lt;bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator" id="ldapAuthoritiesPopulator"&gt;
      &lt;constructor-arg value="ou=Groups"/&gt;
      &lt;constructor-arg ref="contextSource"/&gt;
      &lt;property name="groupRoleAttribute" value="memberOf"/&gt;
  &lt;/bean&gt;
  &lt;bean class="org.springframework.security.ldap.userdetails.InetOrgPersonContextMapper" id="ldapUserDetailsContextMapper"&gt;
  &lt;/bean&gt;
  &lt;bean id="ldapAuthProvider"        class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"&gt;
      &lt;constructor-arg ref="ldapBindAuthenticator"/&gt;
      &lt;constructor-arg ref="ldapAuthoritiesPopulator"/&gt;
      &lt;property name="useAuthenticationRequestCredentials" value="false"/&gt;
      &lt;property name="userDetailsContextMapper" ref="ldapUserDetailsContextMapper" /&gt;
  &lt;/bean&gt;
  &lt;security:authentication-manager alias="authenticationManager" &gt;
      &lt;security:authentication-provider ref="ldapAuthProvider"/&gt;
  &lt;/security:authentication-manager&gt;
  </code></pre>
  
  <p>The exception is:</p>
  
  <pre><code>org.springframework.security.authentication.BadCredentialsException: Bad credentials
  at org.springframework.security.ldap.authentication.BindAuthenticator.authenticate(BindAuthenticator.java:95)
  at org.springframework.security.ldap.authentication.LdapAuthenticationProvider.doAuthentication(LdapAuthenticationProvider.java:178)
  at org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider.authenticate(AbstractLdapAuthenticationProvider.java:61)
  at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156)
  </code></pre>
  
  <p>When I step through the validation of the ldap user is successful it's the test user validation that fails. I think the issue is with the base path. Can anyone tell what am I missing?</p>