shiro的实现权限管理的流程
一、登录认证
-
发起请求之后:会经过doFilter判断需要哪些权限,在复习shiro之前需要对springMvc有一定了解 ,根据debug顺便复习一下MVC的处理流程—根据递归调用栈:
-
首先根据Httpservlet判断是post还是Get请求
-
根据servlet中的request携带的的路径以及参数信息交给前端控制器处理分发
-
DispatcherServlet前端控制器将请求信息转发给RequestMappingHandlerAdapter映射处理器进程处理转发
-
ModelAndView mav;
mav = invokeHandlerMethod(request, response, handlerMethod);处理得到一个ModelAndView 视图模型
-
进一步通过method.invoke方法,反射的机制还有动态代理的机制进行回调Controller方法(回调是满足方法的条件之后重新执行)
-
-
回到shrio部分:
-
权限验证部分
-
controller层:
Subject subject = SecurityUtils.getSubject(); try { subject.login(token);//核心 return R.ok();
-
实际调用:public class DelegatingSubject implements Subject
public void login(AuthenticationToken token) throws AuthenticationException { clearRunAsIdentitiesInternal(); Subject subject = securityManager.login(this, token);//调用
-
实际调用:securityManager
public void login(AuthenticationToken token) throws AuthenticationException { clearRunAsIdentitiesInternal(); Subject subject = securityManager.login(this, token)//实际实例的方法调用
-
实际调用:AuthenticationInfo
public Subject login(Subject subject, AuthenticationToken token) throws AuthenticationException { AuthenticationInfo info;//实际 try { info = authenticate(token);//进一步调用
-
然而:AuthenticationInfo方法被我们重写了里面的逻辑,实际查询数据库验证账户逻辑需要我们自己编写:UserRealm extends AuthorizingRealm
@Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) { Long userId = ShiroUtils.getUserId(); Set<String> perms = menuService.listPerms(userId); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); info.setStringPermissions(perms); return info; }
-
-
授权部分
-