title: Spring custom AuthenticationProvider for Principal with additional data
body: <p>I'm fairly new to Spring.</p>
  
  <p>My goal is to have some <code>AuthenticationProvider</code> with a custom <code>authenticate</code> Method that takes an <code>Authenticate</code> object as argument with more than just a user name and password. Let's say a realm name (and there can be 2 users with the same user name when they are in different realms). I already looked for answers to my question, but the simple answers to questions about authentication only explain how to extend <code>AbstractUserDetailsAuthenticationProvider</code>, which doesn't cater my needs because the retrieve method only takes a user name as argument while I need the realm name as well to retrieve the user. The complex ones are about extending or implementing all kinds of different Spring classes and interfaces without the context being explained.</p>
  
  <p>So the simple question is:</p>
  
  <p>How do I have to implement / extend an <code>AuthenticationProvider</code> to be able to read custom data out of an <code>Authentication</code> object?</p>
  
  <p>My call would look like this (yes, I want to get an OAuth2 token):</p>
  
  <pre><code>curl -vX POST http://localhost:9001/oauth/token \
  -d "client_id=myId&amp;client_secret=secret&amp;grant_type=password&amp;username=myUser&amp;password=1234&amp;realm=realm3"
  </code></pre>
  
  <p>Notice the <code>realm=realm3</code> at the end.</p>
  
  <p>The call without the extra data and with my own sub class of <code>AbstractUserDetailsAuthenticationProvider</code> already works when there's just one realm.</p>
  
  <p>Thanks in advance!</p>