title: Spring Security - Integration Tests with user
body: <p>I have an integration test for Spring (with Spring Security) that looks like this:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  public class RootControllerIT {
      @LocalServerPort
      private int port;
  
      private URL base;
  
      @Autowired
      private TestRestTemplate template;
  
      @Before
      public void setUp() throws Exception {
          this.base = new URL("http://localhost:" + port + "/");
      }
  
      @Test
      @WithMockUser
      public void getHello() throws Exception {
          ResponseEntity&lt;String&gt; response = template.getForEntity(base.toString(),
                  String.class);
          assertThat(response.getBody(), equalTo("OK"));
      }
  }
  </code></pre>
  
  <p>My issue is that the <code>@WithMockUser</code> does not work here, is there a way to add a mock user to the <code>TestRestTemplte</code> or otherwise send authenticated user information to the Integration test? </p>
  
  <p>The mock user works fine when using <code>MockMvc</code> to test, but it's obviously not appropriate here.</p>