title: How can I disable authentication for a specific endpoint?
body: <p><a href="https://stackoverflow.com/questions/22767205/spring-security-exclude-url-patterns-in-security-annotation-configurartion">Many</a> answers to <a href="https://stackoverflow.com/questions/30366405/how-to-disable-spring-security-for-particular-url/30366773">similar questions</a> explains that <code>permitAll()</code> means "allow all <em>authenticated</em> users", and that if you want to skip authentication, you need to do </p>
  
  <pre><code>@Override
  public void configure(WebSecurity web) throws Exception {
      web.ignoring().antMatchers("/chores");
  }
  </code></pre>
  
  <p>This does not work for me.</p>
  
  <p>In particular, here is my controller test that I would like to pass.</p>
  
  <pre><code>@SpringBootTest
  @AutoConfigureMockMvc
  public class ChoreApplicationTest
  {
      @Autowired
      private MockMvc mockMvc;
  
      @Test
      public void choresShouldBeEmptyAtStart() throws Exception
      {
          this.mockMvc.perform(get("/chores")).
                  andExpect(status().isOk());
      }
  </code></pre>
  
  <p>Test results:</p>
  
  <pre><code>java.lang.AssertionError: Status expected:&lt;200&gt; but was:&lt;401&gt;
  Expected :200
  Actual   :401
  </code></pre>
  
  <p>Here's how I'm setting up the security:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfigurer extends WebSecurityConfigurerAdapter
  {
      @Override
      public void configure(WebSecurity web) throws Exception
      {
          web.ignoring().antMatchers("/chores");
          super.configure(web);
      }
  }
  </code></pre>
  
  <p>I reckon you can imagine what's in the Chores controller, but for completeness here's the relevant part:</p>
  
  <pre><code>@RestController
  public class ChoreController
  {
      private final ChoreRepository repository;
  
      ChoreController(ChoreRepository repository)
      {
          this.repository = repository;
      }
  
      @GetMapping("/chores")
      List&lt;Chore&gt; all()
      {
          return this.repository.findAll();
      }
  }
  </code></pre>
  
  <p>Here is the request that the test prints in the output:</p>
  
  <pre><code>MockHttpServletRequest:
        HTTP Method = GET
        Request URI = /chores
         Parameters = {}
            Headers = []
               Body = null
      Session Attrs = {SPRING_SECURITY_SAVED_REQUEST=DefaultSavedRequest[http://localhost/chores]}
  </code></pre>
  
  <p>So why is my test getting a return code of 401, and how can I fix it?</p>