如何使用Grails/Spring安全内核强制程序性注销?

如何使用Grails/Spring安全内核强制程序性注销?,grails,spring-security,Grails,Spring Security,如何使用SpringSecurityCore强制已登录用户程序性注销?我不想重定向到注销页面等。。但是需要在服务中执行此操作。我使用以下代码来实现我的目标: Authentication auth = SecurityContextHolder.context.authentication new SecurityContextLogoutHandler().logout(request, response, auth); new PersistentTokenBasedRememberMeSe

如何使用SpringSecurityCore强制已登录用户程序性注销?我不想重定向到注销页面等。。但是需要在服务中执行此操作。

我使用以下代码来实现我的目标:

Authentication auth = SecurityContextHolder.context.authentication
new SecurityContextLogoutHandler().logout(request, response, auth);
new PersistentTokenBasedRememberMeServices().logout(request, response, auth);

这是另一种方法。我从bean“LogoutHandler”中获取注销处理程序,并在以下每种情况下注销:

def logoutHandlers
def logout(request,response) {
    Authentication auth = SecurityContextHolder.context.authentication
    if (auth) {
        logoutHandlers.each  { handler->
            handler.logout(request,response,auth)
        }
    }

}