title: getPassword() returns null in spring security 3.1 with ldap although I set erase-credentials="false"
body: <p>I need to get the username and password for the logged user to use these credentials to reconnect to another product.</p>
  
  <p>Here is my SecurityContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
  &lt;security:http auto-config="false" use-expressions="true"
      access-denied-page="/app/accessDenied"&gt;
  
      &lt;security:intercept-url pattern="/login"
          access="permitAll" /&gt;
      &lt;security:intercept-url pattern="/pages/home.xhtml"
          access="isAuthenticated() and hasAnyRole('ROLE_ARCH_ADMIN','ROLE_ARCH_Data_ENTRY','ROLE_ARCH_VIEWER','ROLE_ARCH_SUPER_VIEWER','ROLE_ARCH_MANAGER')" /&gt;
      &lt;security:intercept-url pattern="/pages/realtyDoc/realtyDoc.xhtml"
          access="isAuthenticated() and hasAnyRole('ROLE_ARCH_ADMIN','ROLE_ARCH_DATA_ENTRY','ROLE_ARCH_VIEWER','ROLE_ARCH_SUPER_VIEWER','ROLE_ARCH_MANAGER')" /&gt;
  
      &lt;security:form-login login-page="/login1.xhtml"
          login-processing-url="/processLogin" authentication-failure-url="/login1.xhtml?faces-redirect=true"
          authentication-success-handler-ref="successHandler" /&gt;
  
      &lt;security:logout invalidate-session="true" logout-url="/j_spring_security_logout"
          logout-success-url="/login1.xhtml" /&gt;
  &lt;/security:http&gt;
  
  &lt;bean id="contextSource"
      class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"&gt;
      &lt;constructor-arg value="ldap://PDA-FNTEST:389/" /&gt;
      &lt;property name="userDn" value="user@PD.LOCAL" /&gt;
      &lt;property name="password" value="password" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="userSearch"
      class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"&gt;
      &lt;constructor-arg index="0" value="DC=PD,DC=LOCAL" /&gt;
      &lt;constructor-arg index="1" value="(sAMAccountName={0})" /&gt;
      &lt;constructor-arg index="2" ref="contextSource" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="bindAuthenticator"
      class="org.springframework.security.ldap.authentication.BindAuthenticator"&gt;
      &lt;constructor-arg ref="contextSource" /&gt;
      &lt;property name="userSearch" ref="userSearch" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="ldapAuthoritiesPopulator"
      class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator"&gt;
      &lt;constructor-arg ref="contextSource" /&gt;
      &lt;constructor-arg value="OU=ARCH_USERS_OU,DC=PD,DC=LOCAL" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="ldapAuthProvider"
      class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"&gt;
      &lt;constructor-arg index="0" ref="bindAuthenticator" /&gt;
      &lt;constructor-arg index="1" ref="ldapAuthoritiesPopulator" /&gt;
  &lt;/bean&gt;
  
  &lt;security:authentication-manager erase-credentials="false" &gt;
      &lt;security:authentication-provider
          ref="ldapAuthProvider" /&gt;
  &lt;/security:authentication-manager&gt;
  
  &lt;bean id="successHandler" class="com.eblacorp.archive.security.LoginSuccessHandler"&gt;
      &lt;property name="userAccessService" ref="userAccessService" /&gt;
  &lt;/bean&gt;
  &lt;bean id="loginFailuerHandler" class="com.eblacorp.archive.security.LoginFailuerHandler" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>When I use this code to print username and password, the password shows as null.</p>
  
  <pre><code>UserDetails user = (UserDetails) SecurityContextHolder.getContext()
              .getAuthentication().getPrincipal();
  
      System.out.println("username: " + user.getUsername());
      System.out.println("password: " + user.getPassword());
  </code></pre>
  
  <p>I set erase-credentials="false" in authentication manager as:</p>
  
  <pre><code>&lt;security:authentication-manager erase-credentials="false" &gt;
      &lt;security:authentication-provider
          ref="ldapAuthProvider" /&gt;
  &lt;/security:authentication-manager&gt;
  </code></pre>