- 權限定義表: 定義一個SysUser.GetAclMap 的方法, 返回的是[{code,name}, {code2,name2} ...] 的json結構。
在功能權限中, code對應url, 而name則是當前用戶是否擁有權限: null 沒有; Y 有權限.
![](http://static.javashuo.com/static/loading.gif)
- 在Controller中配置Authorize註解, 能夠在class上定義, 也能夠在action中定義
經過order控件校驗順序
![](http://static.javashuo.com/static/loading.gif)
- 經過actionKey指定
![](http://static.javashuo.com/static/loading.gif)
- 權限驗證方式:
- 驗證當前ActionKey是否存在於「權限定義表」 (ContainsKey)
- --Yes , 判斷權限定義表中, 用戶受權值(get): null (未受權),或者not null (已受權)
- -- No, 認定爲無需校驗項, 返回 (已受權)
- 若是Action未定義Authorize註解, 則向上使用Controller上的Authorize註解定義。
- Authorize能夠定義 order和actionKey, 實現重定向的檢測。
如頁面功能:列表頁, 編輯頁, 保存, 刪除。
爲刪除Action設定 一組order{ 保存, 編輯頁 } 。 因爲首先老是檢測當前action, 因此等同於 order={ 刪除, 保存, 編輯頁 }
- 檢測權限 「刪除」 , 若已ContainsKey, 直接返回 受權值。 若未定義, 繼續向下執行;
- 檢測權限 「保存」 , 若已ContainsKey, 直接返回 受權值。 若未定義, 繼續向下執行;
- 檢測權限 「編輯頁」 , 若已ContainsKey, 直接返回 受權值。 若未定義, 繼續向下執行;
- 認定無需校驗, 返回 (已受權)
- 若要禁用當前Action的權限檢測
- 在action上設置 order=-1 且action=""
- 最後, 爲啓用以上功能, 在jfinal 啓動時配置:
public void configInterceptor(Interceptors me) {
me.addGlobalActionInterceptor(new AuthorityValidateInterceptor());//進行全部Action與權限配置表的匹配檢測
me.addGlobalActionInterceptor(new ControllerInViewInterceptor());//容許FreeMaker訪問到session的值
}json
注意: 權限項設置(菜單定義)時, 不得將 /portal/user/index 簡寫爲 /portal/user/ 不然致使權限判斷爲「無權限」。致使排查困難。session