title: Access Spring MVC Service From Spring Security
body: <p>I'm using Spring 3 and trying to populate the authorities of a Spring Security Authentication bean from the database after a user logs in.</p>
  
  <p>I have a service that's used for accessing the database like</p>
  
  <pre class="lang-java prettyprint-override"><code>@Service
  public class UserService {
      public User getUser(String username){...}
  }
  </code></pre>
  
  <p>Normally, I can <code>@Autowire</code> this service, but because the Authentication bean is created by the Spring Security, it can't seem to access the service. I also tried using the <code>ApplicationContextAware</code> interface, but Spring Security seems to have a separate <code>ApplicationContext</code>.</p>
  
  <p>I can access the Authentication bean from MVC through <code>getUserPrincipal()</code> but is there a way I can access this @Service from somewhere in Spring Security authentication?</p>