shiro分享介绍.ppt

  1. 1、本文档共52页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
认证实现 Shiro的认证过程最终会交由Realm执行,这时会调用Realm的getAuthenticationInfo(token)方法。 该方法主要执行以下操作: 1、检查提交的进行认证的令牌信息 2、根据令牌信息从数据源(通常为数据库)中获取用户信息 3、对用户信息进行匹配验证。 4、验证通过将返回一个封装了用户信息的AuthenticationInfo实例。 5、验证失败则抛出AuthenticationException异常信息。 Realm代码 @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; Admin user =(Admin) adminDao.query().is(account, token.getUsername()).result(); if (user != null) { return new SimpleAuthenticationInfo(user.getAccount(), user.getPassword(), getName()); } else { return null; } } 授权实现 而授权实现则与认证实现非常相似,在我们自定义的Realm中,重载doGetAuthorizationInfo()方法,重写获取用户权限的方法即可。 Realm代码 @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { String name=getName(); Iterator iterator=principals.fromRealm(name).iterator(); String userName=null; if(iterator.hasNext()){ userName = (String) iterator.next(); } Admin user =(Admin) adminDao.findOne(account, userName); if(user.getRoleSet()!=null){ BuguMapper.fetchCascade(user, roleSet); } if (user != nulluser.getRoleSet()!=null) { SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); for (Role group : user.getRoleSet()) { info.addRole(group.getName()); if(group.getPerssionSet()!=null){ BuguMapper.fetchCascade(group, perssionSet); Iterator it=group.getPerssionSet().iterator(); while(it.hasNext()){ info.addStringPermission(((Permission)it.next()).getName()); } } } return info; } else { return null; } Shiro配置 Apache Shiro的配置主要分为四部分: 对象和属性的定义与配置 URL的过滤器配置 静态用户配置 静态角色配置 其中,由于用户、角色一般由后台进行操作的动态数据,因此Shiro配置一般仅包含前两项的配置。 Apache Shiro的大多数组件是

文档评论(0)

4477769 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档