asdtiang的博客 感謝blogjava提供的博客交流平臺(tái)

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

          Posted on 2011-01-10 12:03 asdtiang 閱讀(720) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 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
            }

          }
          主要類(lèi)的文檔:
          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)吹草底見(jiàn)牛羊

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

          Copyright © asdtiang

          asdtiang的博客 PaidMailz
          點(diǎn)擊廣告網(wǎng)賺A(每天4個(gè)廣告,每個(gè)0.0025美元,一個(gè)搜索廣告0.03美元)
          主站蜘蛛池模板: 纳雍县| 巴林右旗| 上饶县| 西平县| 巴塘县| 阿荣旗| 皋兰县| 巴楚县| 额济纳旗| 盘锦市| 沅陵县| 沐川县| 吴川市| 恩施市| 天门市| 武义县| 承德县| 临桂县| 通州市| 囊谦县| 玉田县| 得荣县| 孙吴县| 盐边县| 界首市| 壤塘县| 象山县| 兴文县| 辽阳县| 奉新县| 新丰县| 尚义县| 分宜县| 舞阳县| 台东县| 林甸县| 辽阳市| 民和| 凭祥市| 甘谷县| 广西|