简体   繁体   English

如何使用 Spring 安全性从 controller 注销

[英]How to logout from a controller with Spring Security

Is there a logout method for Spring Security that I can use in a controller?我可以在 controller 中使用 Spring 安全性的注销方法吗? Or is there a way to logout by clearing the cache and refreshing?或者有没有办法通过清除缓存和刷新来注销?

Grails controllers have a request object available in them that is an instance of HttpServletRequest . Grails 控制器有一个request object 可用,它是HttpServletRequest的一个实例。 You can use this to log the current user out by calling the logout() method on it.您可以使用它通过调用logout()方法来注销当前用户。

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 . Spring 安全性添加了有关注销方法的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何自定义Grails Spring Security Core 2登录/注销控制器和视图? - How to customize Grails Spring Security Core 2 login / logout controller and views? 从spring-security-core覆盖Login&Logout控制器到主控制器包 - Overwrite Login & Logout controller from spring-security-core to main controller package Grails Spring安全性插件-自定义登录和注销URL,控制器和GSP - Grails Spring Security Plugin - Custom Login and Logout URL, Controller, and GSP 如何使用Spring Security避免自动注销 - how to avoid a automatic logout using spring security Spring Security 3 - Ajax 注销 - Spring Security 3 - Ajax logout Spring Security Core插件-如何从控制器访问用户ID - Spring security core plugin - How to access User id from a controller 如何从控制器调用身份验证-Spring Security Core插件 - How to invoke authenticate from a controller - spring security core plugin 使用Spring Security和Grails注销后如何将用户重定向到其他页面 - How to redirect user to different pages after logout with Spring Security and Grails 在Grails中注销时如何清除Spring Security的RememberMe cookie - How to clear RememberMe cookie of spring security while logout in Grails 如何使用Grails / Spring Security Core强制进行程序化注销? - How to force a programmatic logout using Grails / Spring Security Core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM