title: Spring Security with LDAP and custom UserDetailsContextMapper
body: <p>I am trying to make Spring Security 3.05 to work with a modified UserDetailsContextMapper so that i can get a few more info out of LDAP they way i need to, a task that seems fairly straightforward, but had no success. </p>
  
  <p>I have configured Spring Security to use LDAP authentication with the following beans:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="contextSource"
      class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"&gt;
      &lt;constructor-arg value="ldaps://192.168.1.102:636" /&gt;
      &lt;property name="userDn" value="manager" /&gt;
      &lt;property name="password" value="password" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="ldapAuthProvider"
      class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"&gt;
      &lt;constructor-arg&gt;
          &lt;bean class="org.springframework.security.ldap.authentication.BindAuthenticator"&gt;
              &lt;constructor-arg ref="contextSource" /&gt;
              &lt;property name="userSearch"&gt;
                  &lt;bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"&gt;
                      &lt;constructor-arg index="0" value="" /&gt;
                      &lt;constructor-arg index="1" value="(mail={0})" /&gt;
                      &lt;constructor-arg index="2" ref="contextSource" /&gt;
                  &lt;/bean&gt; 
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/constructor-arg&gt;
      &lt;property name="userDetailsContextMapper" ref="myContextMapper" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>However even though i have defined <code>myContextMapper</code> as:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;bean id="myContextMapper" class="com.mypackage.MyLDAPUserDetailsMapper"&gt;
      &lt;property name="rolePrefix" value="TEST_PREFIX" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>it does not work. meaning that the custom mapper is ignored (i get no debug output whatsoever).</p>
  
  <p>p.s. applicationContext-security.xml can be seen below and apart from the custom UserDetailsMapper that's been ignored, authentication and role assignment is working fine.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;authentication-manager&gt;
      &lt;ldap-authentication-provider server-ref="contextSource"/&gt;
  &lt;/authentication-manager&gt;
  </code></pre>