Adding a logout link
In this recipe, you'll learn how to add a URL /logout
to let the user log out.
How to do it…
In the SecurityConfig
class, in the configure()
method, call the logout()
method and the logoutRequestMatcher()
method to declare a logout URL:
protected void configure(HttpSecurity http) throws Exception { ... AntPathRequestMatcher pathRequestMatcher = new AntPathRequestMatcher("/logout"); http.logout().logoutRequestMatcher(pathRequestMatcher); }
Note
Use org.springframework.security.web.util.
matcher
.AntPathRequestMatcher
, and not the deprecated org.springframework.security.web.util.AntPathRequestMatcher
class.
How it works…
While going to the URL /logout
, the user will be logged out.