概述
本通用權限管理系統是基於2棵樹來做權限管理的,這2棵樹就是 資源樹 和 組織樹
組織+資源+動作 所組成的權限數據就是整個系統的核心。 這里之所以只用組織而不用人員,一方面可以減少權限數據的量,一方面還可以簡化權限數據。
每個人員的的權限是可以計算出來的。 人員從屬於一個或者多個組織的,默認情況下所有人員都有一個根組織,權限數據為了保持簡單,只存儲組織的權限。
表結構設計
概略圖

真正在權限系統中的數據只要 Permission,Rule,Action 3張表就夠了。
User,Group,Resource 的數據可以放在權限中,也可以和既有的系統對接,既有的系統提供API,能夠讓權限訪問到User,Group,Resource的信息即可。
表設計
本系統希望最后以服務的形式提供權限管理的功能,所以每張表沒有多余的字段,只有權限管理必需的一些字段。 關於 人員,組織,資源 的冗余信息應該在各自的系統中查詢和錄入。
權限表(Permission)
| field name | field type | comment |
|---|---|---|
| Id | string | 權限ID |
| ActionId | string | 動作ID |
| GroupId | string | 組織ID |
| ResourceId | string | 資源ID |
動作表(Action)
| field name | field type | comment |
|---|---|---|
| Id | string | 動作ID |
| Name | string | 動作名稱 |
| Description | string | 動作描述 |
規則表(暫略)
人員表(User)
| field name | field type | comment |
|---|---|---|
| Id | string | 用戶ID |
| Name | string | 用戶名 |
| Password | string | 密碼 |
| string | 郵件地址 |
組織表(Group)
| field name | field type | comment |
|---|---|---|
| Id | string | 組織ID |
| ParentId | string | 父組織ID |
| Name | string | 組織名稱 |
| Description | string | 組織描述 |
用戶-組織關聯表(UserGroupRel)
| field name | field type | comment |
|---|---|---|
| Id | string | 用戶組織關系ID |
| UserId | string | 用戶ID |
| GroupId | string | 組織ID |
資源表(Resource)
| field name | field type | comment |
|---|---|---|
| Id | string | 資源ID |
| ParentId | string | 父資源ID |
| Name | string | 資源名稱 |
| Description | string | 資源描述 |
權限規則
權限規則會以插件的形式加入權限驗證的過程中,其目的就是讓權限管理系統更加靈活,更加的通用。
關於權限規則的定義和解析,以后再單獨介紹。
沒有權限規則,整個權限管理系統也可以正常運行,使用。
總結
權限功能幾乎是每個系統都需要的功能,也是每個系統中比較麻煩的一個模塊,不僅測試麻煩,而且一般對其他的業務侵入比較多。
本權限系統的數據結構很簡單,以權限數據為核心,加上與之關聯的一些表,先將基本的權限服務提供出來。
