Posted on 2011-01-10 12:03
asdtiang 閱讀(714)
評(píng)論(0) 編輯 收藏 所屬分類:
grails study
主要參考文檔:
http://grails.1312388.n4.nabble.com/Information-about-all-logged-in-users-with-Acegi-or-SpringSecurity-in-Grails-td1372911.html
根據(jù)文檔,基本操作翻譯如下:(注意只統(tǒng)計(jì)在線用戶,也就是登錄的用戶)
在SecurityConfig中設(shè)置 useHttpSessionEventPublisher 為true,
// HttpSessionEventPublisher
useHttpSessionEventPublisher = true
這樣不用更改web.xml文件
resources.groovy:文件增加以下bean:
beans = {
sessionRegistry(org.springframework.security.concurrent.SessionRegistryImpl)
sessionController(org.springframework.security.concurrent.ConcurrentSessionControllerImpl) {
maximumSessions = -1 //表示同一個(gè)賬戶可以多次登錄,但只計(jì)一個(gè)在線用戶
sessionRegistry = ref('sessionRegistry')
}
}
BootStap對(duì)應(yīng)增加以下內(nèi)容:
class BootStrap {
def authenticationManager
def sessionController
def init = { servletContext ->
authenticationManager.sessionController = sessionController
}
def destroy = {}
}
測(cè)試
class OnlineController {
def sessionRegistry
def test={
render sessionRegistry.getAllPrincipals().length
}
}
主要類的文檔:
ConcurrentSessionControllerImpl:
http://static.springsource.org/spring-security/site/docs/2.0.x/apidocs/org/springframework/security/concurrent/ConcurrentSessionControllerImpl.html
SessionRegistryImpl:
http://static.springsource.org/spring-security/site/docs/2.0.x/apidocs/org/springframework/security/concurrent/SessionRegistryImpl.html
天蒼蒼,野茫茫,風(fēng)吹草底見牛羊