spring security 3.0里面明确的说明了:
session-management段里面的concurrency-control是控制一个帐号最多允许登录多少次的,比如<concurrency-control max-sessions="1"/>就是一次,2当然是两次。
所有搜到的帖子,凡是提到concurrency-control这个的,我不知道有没有人试过真的好用吗?
我配置了以后发现根本就控制不住。
打开了springsecurity的debug日志,还是难以发现原因。
因为网上根本搜不到几个这方面的错误,让我误以为是我个人配置问题,就没有看代码;最后不得已挂上了spring security的代码一看,直接晕菜。
org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy
里面的checkAuthenticationAllowed方法,调用了sessionRegistry.getAllSessions,用authentication.getPrincipal(),也就是UserDetails实现对象。
但是sessionRegistry存储的时候使用的是Hash的数据结构,[size=large][b]所以UserDetails实现类必须重写equals和hashCode。[/b][/size]
另外网上发帖的基本就是抄来抄去,其实只要你加了concurrency-control配置,即使不写max-sessions属性,在org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy里面maximumSessions的默认值是1!
写下来省的后人走弯路。
session-management段里面的concurrency-control是控制一个帐号最多允许登录多少次的,比如<concurrency-control max-sessions="1"/>就是一次,2当然是两次。
所有搜到的帖子,凡是提到concurrency-control这个的,我不知道有没有人试过真的好用吗?
我配置了以后发现根本就控制不住。
打开了springsecurity的debug日志,还是难以发现原因。
因为网上根本搜不到几个这方面的错误,让我误以为是我个人配置问题,就没有看代码;最后不得已挂上了spring security的代码一看,直接晕菜。
org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy
里面的checkAuthenticationAllowed方法,调用了sessionRegistry.getAllSessions,用authentication.getPrincipal(),也就是UserDetails实现对象。
但是sessionRegistry存储的时候使用的是Hash的数据结构,[size=large][b]所以UserDetails实现类必须重写equals和hashCode。[/b][/size]
另外网上发帖的基本就是抄来抄去,其实只要你加了concurrency-control配置,即使不写max-sessions属性,在org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy里面maximumSessions的默认值是1!
写下来省的后人走弯路。