Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security 3.2.0RC2 logout url POST only?

I am experimenting with Spring Security 3.2.0.RC2 using javaconfig and it appears that the logout url is POST only. Is this by design and is there any way to make it logout a user with a GET request?

protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
        .antMatchers("/resources/**", "/signup", "/about", "/password").permitAll()                  
        .antMatchers("/admin/**").hasRole("ADMIN")
            .anyRequest().authenticated().and()
        .formLogin()
            .loginPage("/login")
            .permitAll();        
}
like image 334
NA. Avatar asked Dec 02 '13 16:12

NA.


People also ask

What is the default logout URL defined by Spring Security?

4.2. Similar to other defaults in Spring Security, the URL that actually triggers the logout mechanism has a default as well – /logout.

How do I logout of spring boot security?

Start the application with ./mvnw spring-boot:run and browse to http://localhost:8080/ in a private/incognito window. Click the Login button. Now the fun part. Click the Logout button.

Which actions are performed by the Spring Security framework upon accessing the default logout URL?

The default is that accessing the URL /logout will log the user out by: Invalidating the HTTP Session. Cleaning up any RememberMe authentication that was configured.


1 Answers

This is intentional and is documented within the CSRF documentation. The reason is to prevent CSRF attacks that forcibly log users out of your application. If you would like to support non-POST requests you can do so with the following Java Configuration:

protected void configure(HttpSecurity http) throws Exception {
  http
    // ...
    .logout()
       .logoutRequestMatcher(new AntPathRequestMatcher("/logout"));
}

You can also find information about configuring log out on the Javadoc of the LogoutConfigurer (i.e. the object returned by the http.logout() method).

like image 165
Rob Winch Avatar answered Sep 22 '22 19:09

Rob Winch