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; }
-
-
授權部分
-