title: Spring, Oauth2: authentication details lost after refreshing the token
body: <p>I have two Spring applications: an <em>Authentication Service</em> and a <em>Business Service</em>.</p>
  
  <p>When a webservice user authenticates at the <em>Authentication Service</em>, he gets an <code>access_token</code> and a <code>refresh_token</code>. He can refresh his <code>access_token</code> by sending the <code>refresh_token</code> to the service. The service implements <code>AuthenticationProvider</code>, there the details of the authentication are set:</p>
  
  <pre><code>@Override
  public Authentication authenticate(Authentication authentication) throws AuthenticationException { 
      UsernamePasswordAuthenticationToken newAuthentication = ...;
      LinkedHashMap&lt;String, Object&gt; detailsMap = (LinkedHashMap&lt;String, Object&gt;) authentication.getDetails();
      detailsMap.put(...);
      newAuthentication.setDetails(detailsMap);
      return newAuthentication;
  }
  </code></pre>
  
  <p>The <em>Business Service</em> is secured by <code>Oauth2</code>. Its controller contains</p>
  
  <pre><code>@Secured({ SOME_ROLE })
  @RequestMapping(...)
  public ResponseEntity&lt;?&gt; doSomething(OAuth2Authentication authentication) {
      LinkedHashMap&lt;String, String&gt; detailsMap = (LinkedHashMap&lt;String, String&gt;) authentication
              .getUserAuthentication().getDetails();
  </code></pre>
  
  <p>If the webservice user authenticates at the <em>Authentication Service</em> and calls the <em>Business Service</em>, <code>detailsMap</code> will contain the information set in <code>authenticate()</code>. But if he refreshes the token and calls the <em>Business Service</em> again, <code>detailsMap</code> will be <code>null</code>.</p>
  
  <p>I want the <code>detailsMap</code> to be preserved after the token has been refreshed. How can I achieve this?</p>