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美元)
          主站蜘蛛池模板: 大石桥市| 扬中市| 修武县| 宜丰县| 藁城市| 龙川县| 西贡区| 霍林郭勒市| 阜平县| 石渠县| 改则县| 佛冈县| 台东市| 塔河县| 闵行区| 麻城市| 鄄城县| 乌拉特后旗| 沁源县| 永年县| 观塘区| 中山市| 五莲县| 岳西县| 饶阳县| 高阳县| 桂阳县| 汾阳市| 德保县| 泊头市| 柘城县| 隆化县| 同江市| 北流市| 依兰县| 西和县| 克拉玛依市| 彭阳县| 兴隆县| 彰化县| 都安|