title: Retrieve password of current user from spring-security
body: <p>I'm using spring-security with HTTP Basic Auth to secure a java webapp. In my webapp I need to get the current user's username and password to further authenticate them against another service. I can get hold of the username, but not the password.</p>
  
  <p>I've tried using <code>SecurityContextHolder.getContext().getAuthentication()</code> to access this information as suggested here <a href="https://stackoverflow.com/questions/5088319/how-can-i-get-plaintext-password-from-spring-security">How can I get plaintext password from spring-security?</a> but the password is returned as <code>null</code>.</p>
  
  <p>How can I get hold of the password?</p>
  
  <p>Thanks.</p>
  
  <p>This is my applicationContext-security.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:sec="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  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;sec:http authentication-manager-ref='authenticationManager'&gt;
      &lt;sec:intercept-url pattern="/spring/**" access="ROLE_USER" /&gt;
      &lt;sec:http-basic /&gt;
  &lt;/sec:http&gt;
  
  &lt;bean id="basicAuthenticationFilter"
      class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter"&gt;
      &lt;property name="authenticationManager" ref="authenticationManager" /&gt;
      &lt;property name="authenticationEntryPoint" ref="authenticationEntryPoint" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="authenticationEntryPoint"
      class="org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint"&gt;
      &lt;property name="realmName" value="Announcements Rest Realm" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="authenticationManager"
      class="org.springframework.security.authentication.ProviderManager"&gt;
      &lt;property name="providers"&gt;
          &lt;list&gt;
              &lt;ref local="authProvider" /&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="authProvider"
      class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"&gt;
      &lt;property name="userDetailsService" ref="userDetailsService" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy"&gt;
      &lt;constructor-arg&gt;
          &lt;list&gt;
              &lt;sec:filter-chain pattern="/spring/**" filters="basicAuthenticationFilter" /&gt;
          &lt;/list&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  
  &lt;sec:user-service id="userDetailsService"&gt;
      &lt;sec:user name="admin" password="**" authorities="ROLE_USER, ROLE_ADMIN" /&gt;
      &lt;sec:user name="user" password="**" authorities="ROLE_USER" /&gt;
  &lt;/sec:user-service&gt;
  </code></pre>
  
  <p></p>