title: Custom logout with method
body: <p>I'm writing a web project with Spring Boot and Spring Security. </p>
  
  <p>I want to logout in a method instead of URL <code>/logout</code>. For example: a controller method get a URL, then this method do something and logout. </p>
  
  <p>My Spring Security configuration:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  protected void configure(HttpSecurity httpSecurity) throws Exception {
      httpSecurity
          .authorizeRequests()
              .anyRequest().authenticated()
              .and()
          .formLogin()
              .loginPage("/login")
              .failureUrl("/login?error").permitAll()
              .and()
          .logout().permitAll();
  }
  </code></pre>
  
  <p>But I don't know how to logout with a method. What should I do in <code>SecurityConfig.class</code>? What should I do in the method to logout without a URL?</p>