后台管理系统 – 权限管理

不管是开发手机APP,网站还是小程序等项目,基本上都需要一个后台管理系统的支撑。而每个后台管理系统都有一个通用的功能就是用户权限管理。最近基于Antd+React.js做了一个后台管理系统。


一、概要

权限管理是一个几乎所有后台系统的都会涉及的一个重要组成部分,主要目的是对整个后台管理系统进行权限的控制,而针对的对象是员工,避免因权限控制缺失或操作不当引发的风险问题,如操作错误,数据泄露等问题。

就目前来说最广泛的是一个账号对应多个角色,每个角色对应相应的权限集(RBAC模型)这种模型基本可以应对所有的问题,且通过角色可以实现灵活且多样的的权限操作需求。

权限管理中设计到三个重要的名词:账号、角色、权限。

  • 账号:每个用户想要进入系统需要分配一个账号,而这个账号就是一把钥匙。我们通过控制账号所具备的权限,进而控制这个用户的授权范围。
  • 角色角色管理是确定角色具备哪些权限的一个过程,他是一个集合的概念,是众多最小权限颗粒的组成。我们通过把权限给这个角色,再把角色给账号,从而实现账号的权限,因此它承担了一个桥梁的作用。
  • 权限权限包括页面权限,操作权限,数据权限。页面权限控制你可以看到哪个页面,看不到哪个页面;操作权限则控制你可以在页面上操作哪些按钮;数据权限则是控制你可以看到哪些数据。

二、思考

了解很很多网上给出的权限管理方案,绝大部分解决方案都是事先定义好角色和各个角色的权限。如果换一个系统,由于角色和之前的不一样,后台管理系统需要从代码层面做相应的修改。个人感觉这种前线管理通用性不强。因此想有没有什么方式把权限的颗粒度划分的更细,角色和权限可以自由配置。

带着这些疑问整理了自己对权限管理的理解和解决方案,本人非专业WEB端开发,只是提出个人见解,有不对的地方希望大家指正。上面也说了权限主要分为页面权限、操作权限和数据权限,我想从这三个方面细化并做成可自由配置。

页面权限控制:页面权限主要通过菜单配置和页面跳转操作来控制。一般进入后台管理系统会呈现出主菜单,我们可以在角色管理中为每一个角色配置不同的菜单。用户使用账号登录时,后台通过判断该账号的角色,返回对应的菜单,这样就可以控制用户的一级页面的权限。对于二级页面及其他页面可以通过控制用户操作权限来限制用户访问。

操作权限控制:操作权限主要控制用户哪些按钮可以点击,哪些按钮不可以点击。我们可以事先为页面中要控制的按钮定义一个标识,在获取用户菜单时一并返回,通过检查当前用户是有有这个标识来判断是否有相应的操作权限。

数据权限控制:我理解的数据权限控制是角色有哪些接口调用的权限,防止用户跨域或者跨权限调用接口,我们需要把接口和角色菜单关联起来,调用接口时后台检测当前用户的角色是否有调用该接口的权限,如果没有权限则调用失败。整个权限管理中我觉得这一块是最复杂的,需要配置所有使用到的接口,还需要对每次接口调用进行检测,虽然可以通过正则表达式去匹配,但是还是有一定的局限性。另外对于非常大的系统,这个工作量是非常大的,所以这套权限控制方案不一定适用非常复杂的系统。

三、详细介绍

以下介绍以下我根据我的想法实现的权限管理功能(项目还有很多需要改进的地方,欢迎各位大神指点O(∩_∩)O~)

1.、工作台预览

以下是目前正在开发系统的整体布局,基于React.js+Antd开发,左侧菜单列表可以通过角色控制,不同角色返回的菜单不一样。

2、用户管理

这个没有什么好说的,就是管理用户信息的地方。这里其实有一个可以优化的地方,一个用户应该可以对应多个角色,这一块我简化了一下,每一个用户只有一个角色。每一个角色有一个权限级别,为数值1-9表示,值越大权限越大,每一个角色只能修改权限比其小的用户信息,否则操作按钮置灰。

3.角色管理

角色可根据自身系统业务需求,随意增删改查,无需事先定死角色类型,每个角色后面有一个权限管理入口,在那个页面给么给角色动态分配权限。

4.菜单管理

配置后台管理系统中的所有菜单,每一个菜单后面有一个“功能”按钮,在里面可以配置当前菜单中的功能点,细化到页面中的每个按钮,为每个功能点定义一个标识符,前端根据该标识符判断该用户是否有操作权限。

5.页面功能

这里统一管理页面中的功能项,包括功能名称以及对应的标识符,比如add,delete,edit,view分别代表增删改查按钮权限标识。

6.功能接口

系统是使用前后端分离的实现方式开发,为了防止跨域访问或者跨角色访问,后台需要对每个接口的调用进行权限检查,这里需要配置所有用到的接口,再把接口和菜单对应起来。前端访问调用接口时,后台检测其合法性。

7.菜单功能配置

上面配置了菜单和页面操作项标识,点击菜单管理中每一个菜单后面的“功能”按钮,进入菜单和功能点关联配置的界面。当前菜单中有哪些操作需要控制就添加那些操作的标识,前端通过这个标识判断用户是否在当前菜单页面中有该操作权限。

8.菜单接口关联配置

上面有提到,前后端分离,后台要检测接口调用权限,在这里配置菜单功能项和接口的关联,也就是说当前菜单中哪一个功能允许调用哪些接口在这记录下来,或者也可以把接口和角色关联起来,也许会更简单一些。

9.角色页面权限管理

前面角色列表界面中可以看到在每个角色后面有一个权限按钮,点击里面可以为每个角色配置相应的菜单。实现不同角色显示不同菜单的效果。

四、总结

以上是个人总结的一套权限管理解决方案,优点是可以对角色权限自由配置,权限颗粒度划分比较细,目前来看比较大的缺点就是配置比较复杂,特别是接口和各个功能点标识的配置。大家如果有什么其他更好的解决方案,希望能多多交流,学习学习。

五、其他

以上哪里写的不对或者有待改进,欢迎大家提意见,谢谢!
转载请注明出处:http://www.luoxudong.com/?p=442

有21人对 “后台管理系统 – 权限管理”留言了

  1. I am just writing to make you understand what a perfect experience my wife’s princess obtained using your webblog. She noticed some things, which included what it is like to possess an excellent teaching spirit to make others with no trouble learn about specific specialized things. You undoubtedly surpassed readers’ expected results. Thanks for providing those productive, trusted, informative as well as unique tips on your topic to Mary.

  2. I am commenting to let you know of the fine encounter my cousin’s daughter experienced reading your site. She even learned many issues, not to mention what it’s like to have a wonderful giving mindset to have many people quite simply grasp chosen hard to do subject areas. You really exceeded our expectations. Many thanks for giving the insightful, healthy, educational and as well as easy thoughts on the topic to Jane.

  3. My spouse and i got quite glad that Ervin could deal with his investigations through the ideas he got out of the web page. It’s not at all simplistic to just continually be giving out methods that many other people have been selling. And we also fully understand we have got the website owner to be grateful to for that. The entire explanations you have made, the simple site menu, the friendships you can help foster – it’s got many great, and it’s really helping our son and the family imagine that the issue is entertaining, and that is pretty indispensable. Thank you for everything!

  4. I’m just commenting to let you be aware of of the exceptional discovery my cousin’s child enjoyed going through your blog. She discovered a wide variety of details, most notably how it is like to have a very effective coaching heart to get many more effortlessly fully understand certain extremely tough matters. You actually did more than my desires. I appreciate you for displaying such great, healthy, educational and also cool guidance on that topic to Evelyn.

  5. I precisely desired to say thanks again. I’m not certain the things I could possibly have carried out in the absence of the actual creative concepts discussed by you concerning my concern. It absolutely was a daunting concern for me personally, but coming across a new professional avenue you handled it forced me to cry for delight. I’m grateful for the assistance and as well , expect you comprehend what a powerful job that you are carrying out educating men and women by way of a web site. I am certain you’ve never come across all of us.

  6. I’m just commenting to let you be aware of of the exceptional discovery my cousin’s child enjoyed going through your blog. She discovered a wide variety of details, most notably how it is like to have a very effective coaching heart to get many more effortlessly fully understand certain extremely tough matters. You actually did more than my desires. I appreciate you for displaying such powerful, safe, explanatory and in addition fun tips about this topic to Kate.

  7. Thanks for your own labor on this web site. My mother take interest in participating in research and it is simple to grasp why. My spouse and i notice all regarding the powerful way you produce valuable tips via your website and in addition recommend response from the others on this subject then our own princess is undoubtedly studying a whole lot. Take pleasure in the rest of the year. You have been performing a terrific job.

  8. I needed to draft you one little observation so as to say thank you as before for those great methods you’ve documented here. It has been certainly pretty generous of people like you to convey freely exactly what a number of people could possibly have made available as an e-book in order to make some bucks for their own end, chiefly considering that you could have done it if you considered necessary. The creative ideas additionally acted as the easy way to be certain that most people have a similar dream just like mine to find out a little more in regard to this condition. I’m certain there are lots of more enjoyable moments ahead for folks who discover your blog.

  9. I wanted to put you that tiny remark to be able to say thanks a lot over again on the pleasant solutions you have documented in this article. It is quite remarkably generous of people like you to deliver openly exactly what a number of us might have marketed as an e book to end up making some dough for themselves, most importantly given that you could possibly have done it if you ever decided. These pointers as well served like the fantastic way to fully grasp other people have similar eagerness like my own to know great deal more on the topic of this issue. I am certain there are millions of more fun opportunities in the future for individuals who look over your blog post.

  10. There is definately a lot to learn about this topic. I really like all of the points you have made. Maria Bartholomeo Phionna

  11. 大佬还在吗?
    不清楚菜单怎么细节到和按钮关联,然后每个角色都分配一套菜单吗?

    1. 不清楚菜单怎么细节到和按钮关联,然后每个角色都分配一套菜单吗?

发表评论

电子邮件地址不会被公开。