title: ActiveDirectoryLdapAuthenticationProvider | How to provide Principal creds
body: <ol>
  <li><p>I am working on spring boot app. I am boggled with how to set principal credentials in the AuthenticationManagerBuilder's authentication provider, the ActiveDirectoryLdapAuthenticationProvider object.  It just has the setSearchFilter to find if user is present in a group. But how is the principal credential supplied for authenticating web users?  I have noticed, that when I provide right credentials it takes 2 seconds longer to reload, but still authentication fails: <code>(login?error redirection)</code>. But for wrong credentails, the invalid password message is thrown.</p></li>
  <li><p>Also, how to override username from email id to samaccountname? </p></li>
  <li><p><code>(&amp;(objectClass=user)(userPrincipalName={0})(memberOf=groupname))</code> - this is failing, what does <code>userPrincipalName={0}</code> stand for here? </p>
  
  <pre><code>@Override
  public void configure(AuthenticationManagerBuilder auth) throws Exception
  {
  
      ActiveDirectoryLdapAuthenticationProvider adProvider = 
              new ActiveDirectoryLdapAuthenticationProvider(domain, url, userBaseDn);
  
      adProvider.setConvertSubErrorCodesToExceptions(true);
      adProvider.setUseAuthenticationRequestCredentials(true);
  
      // set pattern if it exists
      // The following example would authenticate a user if they were a member
      // of the ServiceAccounts group
      // (&amp;(objectClass=user)(userPrincipalName={0})
      //   (memberof=CN=ServiceAccounts,OU=alfresco,DC=mycompany,DC=com))
  
      if (userDnPattern != null &amp;&amp; userDnPattern.trim().length() &gt; 0)
      {
          adProvider.setSearchFilter(userDnPattern);
      }
      auth.authenticationProvider(adProvider);
  
      // don't erase credentials if you plan to get them later
      // (e.g using them for another web service call)
      auth.eraseCredentials(false);
   }
  </code></pre></li>
  </ol>