title: Spring Security : bypass @Secured for specific service
body: <p>I am currently implementing Spring Security in my application. I did manage to put @Secured annotation on my service that getAllUsers() from the database, and it is working fine as long as the user is identified (depending on his rights, he can get or not the list of users).</p>
  
  <p>But I have a @Scheduled method in charge of indexing all users, and when it is launched it call the same protected getAllUsers() method, and obviously crashes as it is not logged in : I get the following exception :</p>
  
  <pre><code>org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
  </code></pre>
  
  <p>I'm currently thinking of one possible solution, which would be to mark the internal methods with a custom annotation, which would be retrieved by a custom <code>AccessDecisionVoter</code> allowing the caller to call the protected method.</p>
  
  <p>I'm looking for best practice for this kind of usecase</p>