spring security logout handler无法正常工作

时间:2012-10-15 17:06:04

标签: spring grails spring-security

我有grails pluggin spring-security-core-1.2.1

我在grails-app / conf / spring / resources.groovy中将安全事件监听器注册为spring bean:

securityEventListener(LoggingSecurityEventListener)

并向grails-app / conf / Config.groovy添加两个内容:

grails.plugins.springsecurity.useSecurityEventListener = true
grails.plugins.springsecurity.logout.handlerNames =
    ['rememberMeServices',
            'securityContextLogoutHandler',
            'securityEventListener']

我的日志/注销侦听器

class LoggingSecurityEventListener implements ApplicationListener<AbstractAuthenticationEvent>, LogoutHandler {

            void onApplicationEvent(AbstractAuthenticationEvent event) {
                System.out.println('appEvent')
            }


            void logout(HttpServletRequest request, HttpServletResponse response,
                            Authentication authentication) {
                System.out.println('logout')
            }

}
ApplicationEvent上的

运行良好,但注销无效 可能是什么问题?

或者您可以告诉如何获取所有日志记录用户

1 个答案:

答案 0 :(得分:3)

设置

grails.plugins.springsecurity.useSecurityEventListener = true

spring security插件将注册它自己的名为securityEventListener的事件监听器。从handlerNames查找的处理程序可能会使插件注册而不是您的插件。尝试将bean重命名为:

loggingSecurityEventListener(LoggingSecurityEventListener)

并将handlerNames替换为

grails.plugins.springsecurity.logout.handlerNames = 
    ['rememberMeServices',
     'securityContextLogoutHandler',
     'loggingSecurityEventListener']

注意:配置属性名称已更改(plugins - &gt; plugin)。如果您使用的是grails spring-security插件版本2.0或更高版本,请使用:

grails.plugin.springsecurity.logout.handlerNames