title: How do I use a custom authorities populator with Spring Security and the ActiveDirectoryLdapAuthenticationProvider?
body: <p>I've successfully connected to Active Directory through LDAP to authenticate, and with the following in my ldap.xml I've called my custom authorities populator:</p>
  
  <pre><code>    &lt;bean id="ldapAuthenticationProvider"
          class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"&gt;
      &lt;constructor-arg ref="ldapBindAuthenticator"/&gt;
      &lt;constructor-arg ref="ldapAuthoritiesPopulator"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="ldapBindAuthenticator"
          class="org.springframework.security.ldap.authentication.BindAuthenticator"&gt;
      &lt;constructor-arg ref="ldapServer"/&gt;
      &lt;property name="userSearch" ref="ldapSearch"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="ldapSearch"
          class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"&gt;
      &lt;constructor-arg value="CN=Users"/&gt;
      &lt;constructor-arg value="(sAMAccountName={0})"/&gt;
      &lt;constructor-arg ref="ldapServer"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="ldapAuthoritiesPopulator"
          class="my.project.package.ActiveDirectoryLdapAuthoritiesPopulator"/&gt;
  
  &lt;bean id="ldapServer"
          class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"&gt;
      &lt;constructor-arg value="ldap://192.168.0.2/dc=test,dc=server"/&gt;
  
      &lt;property name="userDn" value="ldap@test.server"/&gt;
      &lt;property name="password" value="ldap"/&gt;
      &lt;property name="baseEnvironmentProperties"&gt;
          &lt;map&gt;
              &lt;entry key="java.naming.referral"&gt;
                  &lt;value&gt;follow&lt;/value&gt;
              &lt;/entry&gt;
          &lt;/map&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>This works fine, and I can ascertain the user's authorization based on her group membership, but I would rather do this through the built-in Active Directory LDAP Authentication Provider:</p>
  
  <pre><code>&lt;bean id="ldapAuthenticationProvider"
          class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider"&gt;
  
          &lt;constructor-arg value="test.server"/&gt;
          &lt;constructor-arg value="ldap://192.168.0.2:389"/&gt;
          &lt;property name="convertSubErrorCodesToExceptions" value="true"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>The problem with the above is that my custom authorities populator is (obviously) not called, so while I can authenticate my users (which works with the above), I am left without the groups (which I need to determine authorization).</p>
  
  <p>I feel like this is a simple question, but for the life of me I cannot find an answer here or anywhere else. Do I have to extend the ActiveDirectoryLdapAuthenticationProvider class, and call my authorities populator from there?</p>
  
  <p>(Thanks for all the help this site has given me for several years running; the effectiveness of this site can be gauged by the fact that I've only recently bothered to create an account, and this is my first question. Thanks in advance for your help.)</p>