How to logout from a controller with Spring Security

517 Views Asked by At

Is there a logout method for Spring Security that I can use in a controller? Or is there a way to logout by clearing the cache and refreshing?

1

There are 1 best solutions below

1
doelleri On BEST ANSWER

Grails controllers have a request object available in them that is an instance of HttpServletRequest. You can use this to log the current user out by calling the logout() method on it.

class TestController {

    def logMeOut() {
        request.logout() // Logout current user
        redirect(controller: 'home', action: 'index') // Redirect to the home page
    }
}

Spring Security adds a little more information on the logout method.