title: How to authenticate a user against AD in Java
body: <p>I'm using JNDI library to access to an AD from Java Webapp. I authenticate agaisnt the AD via LDAP using a technical user as follows:</p>
  
  <pre><code>    Hashtable&lt;String, String&gt; ldapEnv = new Hashtable&lt;String, String&gt;(11);
      ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT);
      ldapEnv.put(Context.PROVIDER_URL, providerUrl);
      ldapEnv.put(Context.SECURITY_AUTHENTICATION,
              SECURITY_AUTHENTICATION_SIMPLE);
      ldapEnv.put(Context.SECURITY_PRINCIPAL, principal);
      ldapEnv.put(Context.SECURITY_CREDENTIALS, credentials);
      return new InitialDirContext(ldapEnv);
  </code></pre>
  
  <p>I use this user to read and write from/to AD.</p>
  
  <p>But after that, I don't know how to authenticate the final user who is really accessing to my webapp with his user and a password. </p>
  
  <p>I read about using find method from Context class but I'm not sure how to do or how to build the the search filter. For example</p>
  
  <pre><code>(&amp;(cn= ....
  </code></pre>
  
  <p>I don't know either how to find for all users in the AD. I would like to show in my webapp a list of all available users in AD</p>