title: How to authenticate user against spring Security in unit tests
body: <p>I am using spring security core plugin (1.2.7) with grails 2.0</p>
  
  <p>Let's say that I have controller with a method that uses @Secured annotation.</p>
  
  <pre><code>class ArticleController {
      def springSecurityService
  
      @Secured(['ROLE_PREMIUM_USER'])
      def listPremium() { 
          render 'premium content'
      }
  }
  </code></pre>
  
  <p>in my unit test I would like to test if a user with role 'ROLE_PREMIUM_USER' can see content of listPremium method.  How can I do this?</p>
  
  <p>I know that it should start as follows:</p>
  
  <pre><code>@TestFor(ArticleController)
  @Mock([SpringSecurityService])
  class ArticleControllerTests {
      void testListPremium() {
      defineBeans {
          springSecurityService(SpringSecurityService)
      }
           //but how to login the user here in order to see premium content?
  
          controller.listPremium()
          assert response.text() == 'premium content'
      }
  }
  </code></pre>
  
  <p>I am not sure how can I authenticate user or mock action that checks ROLE_PREMIUM_USER. Any help?</p>