我使用spring安全核心插件。我希望在用户登录后立即将对象放入会话中。到目前为止我发现的是插件中有grails.plugin.springsecurity.LoginController
。它有一个名为ajaxSuccess
的方法,它似乎在成功验证后才被调用。所以我决定创建另一个LoginController,它扩展默认值并覆盖这个方法:
@Secured('permitAll')
class LoginController extends grails.plugin.springsecurity.LoginController {
def ajaxSuccess() {
session['somevproperty'] = someValue
super.ajaxSuccess()
}
}
但是调试显示从不调用此方法。出了什么问题?愿还有另一种方法可以做我想要的吗?谢谢!
答案 0 :(得分:5)
Spring security拥有自己的事件监听器。我更喜欢你用它。
http://grails-plugins.github.io/grails-spring-security-core/guide/events.html
上述链接中的示例代码,用于成功登录。
package com.foo.bar
import org.springframework.context.ApplicationListener
import org.springframework.security.authentication.event. AuthenticationSuccessEvent
class MySecurityEventListener implements ApplicationListener<AuthenticationSuccessEvent> {
void onApplicationEvent(AuthenticationSuccessEvent event) {
// handle the event
}
}