title: @WithMockUser doesn't pick Spring Security auth credentials
body: <p>I have setup basic authentication in my controller with Spring Security in the classic way as follows:</p>
  
  <pre><code>@EnableWebSecurity
  @EnableGlobalMethodSecurity
  public class MySecurityConfig extends WebSecurityConfigurerAdapter {
  
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth.inMemoryAuthentication()
                  .withUser("user").password("user").roles("USER")
                  .and()
                  .withUser("admin").password("admin").roles("USER", "ADMIN");
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests()
                  .antMatchers(....);
      }
  }
  </code></pre>
  
  <p>When it comes to the point of testing, I am using <strong><em>@WithMockUser</em></strong> to annotate my tests. A test might look like this for GET:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @WebMvcTest(controllers = SomeController.class)
  public class SomeControllerTest {
  
      @Autowired
      private MockMvc mockMvc;
  
      @Test
      public void test1() {
                    mockMvc.perform(get(...)).andExpect(...);
      }
  </code></pre>
  
  <p>or like this for POST:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @WebMvcTest(controllers = SomeController.class)
  public class SomeControllerTest {
  
      @Autowired
      private MockMvc mockMvc;
  
      @Test
      public void test1() {
                    mockMvc.perform(post(...)).andExpect(...);
      }
  </code></pre>
  
  <p>then something unexpected happens:</p>
  
  <ul>
  <li>when a test method is not annotated with <em>@WithMockUser</em>, it fails because of 401 status (Unauthorized) which is reasonable, because no basic authentication has been fullfilled</li>
  <li>when a test method is simply annotated with an empty <em>@WithMockUser</em> <strong>without specifying ANY credentials</strong>, it starts passing, which is not reasonable, because I did not provide the correct data for authentication (rather I left them empty)</li>
  <li>at this point a test method is passing also when filling in some correct credentials like in <em>@WithMockUser(username = "user", password = "user", roles = "USER")</em></li>
  </ul>
  
  <p><strong>QUESTION</strong>: what's going on? How to fix this misbehaviour?</p>
  
  <p>Looks like Spring Security is activated, however my testing is not using the authentication that I would expect to be used. Do I have to mock the authentication data myself?</p>
  
  <p><strong>EDIT</strong> The full configure method is the following</p>
  
  <pre><code>@Override
  protected void configure(HttpSecurity http) throws Exception {
      http.authorizeRequests()
              .antMatchers(URL1).hasAnyRole(ROLE_ADMIN)
              .antMatchers(URL2).hasAnyRole(ROLE_USER)
              .antMatchers(URL3).permitAll()
              .and()
              .httpBasic()
              .and()
              .csrf().disable();
  }
  </code></pre>