Spring Security 3-Ajax注销

I'm building a single-page web application with integrated login/logout features. The back-end is powered by Grails 3 and Spring Security 3.0.3.

From Spring Securiy doc:

LoginController has JSON-generating methods ajaxSuccess(), ajaxDenied(), and authfail() that generate JSON that the login Javascript code can use to appropriately display success or error messages.

Ajax requests are identified by default by the X-Requested-With request header.

What about Ajax logout functionality though? As far as I could understand there's no built-in support to do that, so I'm looking for advice about the easiest way to achieve this.

At the moment, with the default Spring Security configuration, the logout works as expected (i.e. users are able to logout successfully), but of course what I get from the back-end is the login page's HTML.

Thanks in advance!

Just ran into the same problem myself.

Didn't find a way to skip the redirect but by adding my own logout controller, I could at least provide an json response instead of the login page.

Add this to application.groovy

grails.plugin.springsecurity.logout.afterLogoutUrl="/ajaxLogout"

And this is my controller

@Secured('permitAll')
class AjaxLogoutController {
  def index() {
    def data = [:]
    data.success = true
    render data as JSON
  }
}