4
我如何强制使用Spring Security Core登录的用户进行编程注销?我不想重定向到注销页面等,但需要在服务中完成。如何使用Grails/Spring Security Core强制编程注销?
我如何强制使用Spring Security Core登录的用户进行编程注销?我不想重定向到注销页面等,但需要在服务中完成。如何使用Grails/Spring Security Core强制编程注销?
我用下面的代码来实现我的目标:
Authentication auth = SecurityContextHolder.context.authentication
new SecurityContextLogoutHandler().logout(request, response, auth);
new PersistentTokenBasedRememberMeServices().logout(request, response, auth);
这是另一种方法。我从bean“logoutHandlers”获得注销处理程序,然后在每个注销中注销:
def logoutHandlers
def logout(request,response) {
Authentication auth = SecurityContextHolder.context.authentication
if (auth) {
logoutHandlers.each { handler->
handler.logout(request,response,auth)
}
}
}