title: How to change the login name for the current user with Spring Security 3.1?
body: <p>I have the requirement that every user can change his own user name while he stays logged in. The problem is how to update the username (<code>Principal</code>) in Spring Security`s Authentication Token?</p>
  
  <p>(<em>I have to update it, because I use the prinicpal name from the Authentication Token to identify the user in some business use cases.</em>)</p>
  
  <p>I use form based and cookie rememeber me based login so my Authentication Tokens are <code>UsernamePaswordAuthenticationToken</code> and <code>RememberMeAuthenticationToken</code>. Both have a field <code>principal</code> where the login name is stored. Unfortunately this variable is <code>final</code>, so I can not change its value.</p>
  
  <p><strong>Does anybody has an idea how Spring Security recomends to change the <code>Principal</code> in the Authentication Token?</strong></p>
  
  <p><em>My current workarround is that I replaced the <code>UsernamePaswordAuthenticationToken</code> and <code>RememberMeAuthenticationToken</code> with subclasses that have an additional not final principal field and override the <code>getPrincipal()</code> method to return this additional principal instead of the original one. Then I have also subclassed the two classes that generate this tokens to create my tokens instead of the original one. --- But I feel that this is a big hack.</em></p>