用spring安全处理成功的登录事件 [英] handle successful login event with spring security
问题描述
我的Grails应用程序使用Spring Security插件。每当用户成功登录时,我都会: 我需要类似地处理注销事件,这非常简单,因为插件提供了一个名为 添加配置参数: 然后在处理此URL的操作中添加您的自定义登录处理 My Grails app uses the Spring Security plugin. Whenever a user successfully logs in I want to: I need to handle logout events similarly, which was pretty straightforward because the plugin provides a bean named I read the page in the plugin's docs about event handling, but neither of the event handling mechanisms appears to give me access to the current request or session. Add a config parameter: Then add your custom login-handling in the action that handles this URL
这篇关于用spring安全处理成功的登录事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
logoutSuccessHandler
的bean可以被重写。我希望能够类似地找到一个名为 loginSuccessHandler
的bean,但是没有这样的运气。 插件关于事件处理的文档,但是这两种事件处理机制似乎都无法让我访问当前的请求或会话。
$ p $ grails.plugins.springsecurity.successHandler.defaultTargetUrl ='/ myLogin / handleSuccessLogin'
class MyLoginController {
def springSecurityService
def handleSuccessLogin(){
session.foo ='bar'
if(springSecurityService.currentUser.username =='bob'){
redirect action:'bobLogin
} else {
redirect action:'defaultLogin'
}
}
def bobLogin(){
// bob的登录处理程序
$ b $ def def defaultLogin(){
//默认登录处理程序
}
}
logoutSuccessHandler
that can be overriden. I was hoping to similarly find a bean named loginSuccessHandler
, but no such luck.grails.plugins.springsecurity.successHandler.defaultTargetUrl = '/myLogin/handleSuccessLogin'
class MyLoginController {
def springSecurityService
def handleSuccessLogin() {
session.foo = 'bar'
if (springSecurityService.currentUser.username == 'bob') {
redirect action: 'bobLogin'
} else {
redirect action: 'defaultLogin'
}
}
def bobLogin() {
// bob's login handler
}
def defaultLogin() {
// default login handler
}
}