asdtiang的博客 感謝blogjava提供的博客交流平臺

          grails acegi 在線用戶統(tǒng)計

          Posted on 2011-01-10 12:03 asdtiang 閱讀(720) 評論(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)計在線用戶,也就是登錄的用戶)

          在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 //表示同一個賬戶可以多次登錄,但只計一個在線用戶
                   sessionRegistry = ref('sessionRegistry')
                }
             }

          BootStap對應(yīng)增加以下內(nèi)容:
          class BootStrap {

                def authenticationManager
                def sessionController

                def init = { servletContext ->
                   authenticationManager.sessionController = sessionController
                } 
                def destroy = {}
             }


          測試

          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)吹草底見牛羊

          posts - 80, comments - 24, trackbacks - 0, articles - 32

          Copyright © asdtiang

          asdtiang的博客 PaidMailz
          點(diǎn)擊廣告網(wǎng)賺A(每天4個廣告,每個0.0025美元,一個搜索廣告0.03美元)
          主站蜘蛛池模板: 和田市| 五常市| 图们市| 大关县| 达日县| 都兰县| 宾川县| 鞍山市| 尤溪县| 尖扎县| 海兴县| 开化县| 宜都市| 吉安县| 万源市| 麟游县| 五原县| 土默特左旗| 大邑县| 辽源市| 深州市| 高清| 海安县| 东丽区| 香格里拉县| 礼泉县| 会理县| 武胜县| 汪清县| 都兰县| 乐陵市| 凉城县| 巴南区| 博爱县| 疏附县| 沂南县| 吉首市| 澎湖县| 太康县| 普兰县| 措美县|