title: How do you authenticate against an Active Directory server using Spring Security?
body: <p>I'm writing a Spring web application that requires users to login.  My company has an Active Directory server that I'd like to make use of for this purpose.  However, I'm having trouble using Spring Security to connect to the server.</p>
  
  <p>I'm using Spring 2.5.5 and Spring Security 2.0.3, along with Java 1.6.</p>
  
  <p>If I change the LDAP URL to the wrong IP address, it doesn't throw an exception or anything, so I'm wondering if it's even <em>trying</em> to connect to the server to begin with.</p>
  
  <p>Although the web application starts up just fine, any information I enter into the login page is rejected.  I had previously used an InMemoryDaoImpl, which worked fine, so the rest of my application seems to be configured correctly.</p>
  
  <p>Here are my security-related beans:</p>
  
  <pre><code>  &lt;beans:bean id="ldapAuthProvider" class="org.springframework.security.providers.ldap.LdapAuthenticationProvider"&gt;
      &lt;beans:constructor-arg&gt;
        &lt;beans:bean class="org.springframework.security.providers.ldap.authenticator.BindAuthenticator"&gt;
          &lt;beans:constructor-arg ref="initialDirContextFactory" /&gt;
          &lt;beans:property name="userDnPatterns"&gt;
            &lt;beans:list&gt;
              &lt;beans:value&gt;CN={0},OU=SBSUsers,OU=Users,OU=MyBusiness,DC=Acme,DC=com&lt;/beans:value&gt;
            &lt;/beans:list&gt;
          &lt;/beans:property&gt;
        &lt;/beans:bean&gt;
      &lt;/beans:constructor-arg&gt;
    &lt;/beans:bean&gt;
  
    &lt;beans:bean id="userDetailsService" class="org.springframework.security.userdetails.ldap.LdapUserDetailsManager"&gt;
      &lt;beans:constructor-arg ref="initialDirContextFactory" /&gt;
    &lt;/beans:bean&gt;
  
    &lt;beans:bean id="initialDirContextFactory" class="org.springframework.security.ldap.DefaultInitialDirContextFactory"&gt;
      &lt;beans:constructor-arg value="ldap://192.168.123.456:389/DC=Acme,DC=com" /&gt;
    &lt;/beans:bean&gt;
  </code></pre>