如何在Grails Acegi插件中控制同一账号登录

本文介绍如何在Grails应用中实现并发会话控制,包括配置并发会话控制器、过滤器及设置最大会话数等步骤。通过具体示例展示了如何在BootStrap类中初始化并发会话控制器,并在resources.groovy文件中定义相关bean。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.Set the concurrentSessionController in Bootstrap:

class BootStrap {

   def authenticationManager
   def concurrentSessionController

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

   def destroy = {}
} 
 



2. then in resources.groovy I configured the missing concurrentSessionFilter :

import org.springframework.security.concurrent.ConcurrentSessionControllerImpl
import org.springframework.security.concurrent.ConcurrentSessionFilter
import org.springframework.security.concurrent.SessionRegistryImpl
import org.springframework.security.providers.ProviderManager

beans = {

   sessionRegistry(SessionRegistryImpl)

   concurrentSessionController(ConcurrentSessionControllerImpl) {
      maximumSessions = 1
      sessionRegistry = sessionRegistry
   }

   concurrentSessionFilter(ConcurrentSessionFilter) {
      sessionRegistry = sessionRegistry
      expiredUrl = '/login/concurrentSession'
   }
} 
 



3. and took advantage of a new feature in the 0.3 version of the plugin, being
able to specify the FilterChainProxy filter list as a list of strings in
SecurityConfig.groovy:

   filterNames = ['concurrentSessionFilter',
                  'httpSessionContextIntegrationFilter',
                  'logoutFilter',
                  'authenticationProcessingFilter',
                  'securityContextHolderAwareRequestFilter',
                  'rememberMeProcessingFilter',
                  'anonymousProcessingFilter',
                  'exceptionTranslationFilter',
                  'filterInvocationInterceptor'] 
 

结论及其他:

1.本文引自nabble讨论:http://old.nabble.com/dealing-with-concurrent-session-in-acegi-and-grails-td18987010.html

2.另一个nabble讨论提到acegi plugin将在0.6版本纳入此功能:http://jira.codehaus.org/browse/GRAILSPLUGINS-962

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值