Shrio RBAC框架

来源:互联网 发布:天猫魔盘连接不上网络 编辑:程序博客网 时间:2024/05/29 19:32
实在地感受到框架的复用性。比如说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");
}
其他配置东西下一个博客总结
原创粉丝点击