我正在构建一个grails应用程序,它具有spring-security-core 1.2.7.3插件以及spring-security-ui 0.2插件,并希望获得当前登录的所有用户的列表(即有一个目前活跃的会议).用户可以通过登录控制器(daoAuthenticationProvider)登录,也可以通过rememberMe cookie自动登录.我已经实现了下面的代码,使用ConcurrentSessionControlStrategy来创建sessionRegistry:
在/conf/spring/resources.groovy中:
import org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy
import org.springframework.security.web.session.ConcurrentSessionFilter
import org.springframework.security.core.session.SessionRegistryImpl
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy
beans = {
userDetailsService(lablore.MyUserDetailsService)
sessionRegistry(SessionRegistryImpl)
sessionAuthenticationStrategy(ConcurrentSessionControlStrategy, sessionRegistry) {
maximumSessions = -1
}
concurrentSessionFilter(ConcurrentSessionFilter){
sessionRegistry = sessionRegistry
expiredUrl = '/login/concurrentSession'
}
}
Run Code Online (Sandbox Code Playgroud)
在/plugins/spring-security-core/conf/DefaultSecurityConfig.groovy
useHttpSessionEventPublisher = true
Run Code Online (Sandbox Code Playgroud)
在控制器中:
controller{
def sessionRegistry
action(){
def loggedInUsers = sessionRegistry.getAllPrincipals()
}
}
Run Code Online (Sandbox Code Playgroud)
它适用于通过登录页面登录的用户 - 通过"注销"链接登出的用户 - 会话过期的用户,但它不适用于使用rememberMe cookie自动进行身份验证的用户.它没有看到他们有一个新创建的会话.如果我理解正确,这是因为与ConcurrentSessionFilter(运行sessionRegistry的那个)相比,RememberMeAuthenticationFilter在过滤器链中"更进一步"?或者,我搞砸了我的配置....
任何有关如何使其工作的帮助都会很棒!
谢谢!!