title: How to log out with spring security basic auth?
body: <p>Someone can say that this is a duplicate question but I have looked through a lot of answers, tried a bunch of methods but can not understand what I have missed.</p>
  
  <p>I use very basic Spring Security in my REST server. When I first time make a request to my server directly from a browser to <strong><em>localhost:.../getData</em></strong> I am of course asked to authorize. </p>
  
  <p>Then the server permits this request every time. How I can <strong>logout</strong> so that the next requests require an authorization again?</p>
  
  <p>Now I tried to use several methods on my server for logout:</p>
  
  <pre><code>@RequestMapping(value = "/logoutMe2", method = RequestMethod.GET)
  public void logout2() {
  
      SecurityContextHolder.getContext().setAuthentication(null);
  
  }
  
  @RequestMapping(value = "/logoutMe3", method = RequestMethod.GET)
  public void logout3() {
  
      SecurityContextHolder.clearContext();
  
  }
  
  
  @RequestMapping(value = "/logoutMe", method = RequestMethod.GET)
  public void logout(HttpServletRequest rq, HttpServletResponse rs) {
  
      SecurityContextLogoutHandler securityContextLogoutHandler =
              new SecurityContextLogoutHandler();
      securityContextLogoutHandler.logout(rq, rs, null);
  
  }
  
  @RequestMapping(value = "/logoutMe4", method = RequestMethod.GET)
  public static void myLogoff(HttpServletRequest request, HttpServletResponse response) {
      CookieClearingLogoutHandler cookieClearingLogoutHandler = new CookieClearingLogoutHandler(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY);
      SecurityContextLogoutHandler securityContextLogoutHandler = new SecurityContextLogoutHandler();
      cookieClearingLogoutHandler.logout(request, response, null);
      securityContextLogoutHandler.logout(request, response, null);
  }
  </code></pre>
  
  <p>If I use direct link </p>
  
  <blockquote>
    <p><a href="http://localhost:.../j_spring_security_logout" rel="noreferrer">http://localhost:.../j_spring_security_logout</a></p>
  </blockquote>
  
  <p>I receive a Not Found error.</p>
  
  <p>What I am missing? It seems that I have forget some obvious thing...</p>