我正在尝试获取当前登录的grails应用程序的数量。我正在使用: Grails 2.3.1和spring-security-core:2.0-RC2插件。
通过引用此线程: GRAILS: how to get the number of currently signed in users via spring security core plugin?
resources.groovy
import org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy
beans = {
sessionRegistry(org.springframework.security.core.session.SessionRegistryImpl)
concurrencyFilter(org.springframework.security.web.session.ConcurrentSessionFilter){
sessionRegistry = sessionRegistry
expiredUrl = '/login/concurrentSession'
}
sessionAuthenticationStrategy(ConcurrentSessionControlStrategy, sessionRegistry) {
maximumSessions = -1
}
}
我还修改了web.xml并添加了:
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
这些是我对我的应用程序进行的唯一更改。
以这种方式修改BootStrap
class BootStrap {
def springSecurityService
def authenticationManager
def concurrentSessionController
def securityContextPersistenceFilter
def init = { servletContext ->
authenticationManager.sessionController = concurrentSessionController
}
def destroy = {
}
}
启动时出错:
Error initializing the application: No such property: sessionController for class: org.springframework.security.authentication.ProviderManager
Message: No such property: sessionController for class: org.springframework.security.authentication.ProviderManager
我到目前为止唯一的想法是SessionRegistry被注入我的控制器并且我能够调用
sessionRegistry.getAllPrincipals().size()
没有获得NullPointerException,但无论当前登录的用户数是多少,它都会返回0.
我不知道从哪里开始,因为我是春天的初学者。