实在地感受到框架的复用性。比如说RBAC框架,基于角色的权限管理框架,但是很多东西你还是得自己写,Shiro可以直接管理用户,获取用户登录帐号,时间等等。
限制一个帐号只能一个用户登录
@Autowired
private SessionDAO sessionDAO;
@RequestMapping(value="index",method=RequestMethod.GET)
public ModelAndView userIndex(){
//获取所有登录用户session信息
Collection<Session> sessions = sessionDAO.getActiveSessions();
for(Session s:sessions){
//LoggerUtils.fmtDebug(getClass(), "****************"+s.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY).toString());
JSONArray array=JSONArray.fromObject(s.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)) ;
System.out.println(array.size());
for(int i=0;i<array.size();i++){
JSONObject object=array.getJSONObject(i);
System.out.println(object);
//获取昵称,为了完成匹配判断是否已经登录了
System.out.println(object.getJSONObject("primaryPrincipal").getString("nickname"));
}
System.out.println();
}
return new ModelAndView("xx");
}
其他配置东西下一个博客总结
限制一个帐号只能一个用户登录
@Autowired
private SessionDAO sessionDAO;
@RequestMapping(value="index",method=RequestMethod.GET)
public ModelAndView userIndex(){
//获取所有登录用户session信息
Collection<Session> sessions = sessionDAO.getActiveSessions();
for(Session s:sessions){
//LoggerUtils.fmtDebug(getClass(), "****************"+s.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY).toString());
JSONArray array=JSONArray.fromObject(s.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)) ;
System.out.println(array.size());
for(int i=0;i<array.size();i++){
JSONObject object=array.getJSONObject(i);
System.out.println(object);
//获取昵称,为了完成匹配判断是否已经登录了
System.out.println(object.getJSONObject("primaryPrincipal").getString("nickname"));
}
System.out.println();
}
return new ModelAndView("xx");
}
其他配置东西下一个博客总结
本文介绍了如何使用Shiro框架进行权限管理,特别是实现一个账号仅允许一个用户登录的功能。通过获取活动Session并解析用户信息来确保登录唯一性。
2219

被折叠的 条评论
为什么被折叠?



