【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了AccessDecisionManager.class.php提供大家参考,希望对大家有所帮助!
<?php
// +----------------------------------------------------------------------
// | Think
PHP // +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* 璁块棶鍐崇瓥绠$悊鍣?
+------------------------------------------------------------------------------
* @category ORG
* @package ORG
* @subpackage RBAC
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class AccessDecisionManager extends Base
{//绫诲畾涔夊紑濮?
public $roleTable ;
public $roleUserTable ;
public $roleAccessTable;
public $roleNodeTable;
/**
+----------------------------------------------------------
* 鏋舵瀯鍑芥暟
*
+----------------------------------------------------------
* @static
* @access public
+----------------------------------------------------------
*/
public function __construct()
{
import("Think.Db.Db");
$this->roleTable = C('DB_PREFIX').'group';
$this->roleUserTable = C('DB_PREFIX').'groupuser';
$this->roleAccessTable= C('DB_PREFIX').'access';
$this->roleNodeTable = C('DB_PREFIX').'node';
}
/**
+----------------------------------------------------------
* 鍐崇瓥璁よ瘉
* 妫鏌ユ槸鍚﹀叿鏈夊綋鍓嶇殑鎿嶄綔鏉冮檺
+----------------------------------------------------------
* @param integer $authId 璁よ瘉id
* @param string $app 椤圭洰鍚?
* @param string $module 妯″潡鍚?
* @param string $action 鎿嶄綔鍚?
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function decide($authId,$app=APP_NAME,$module=MODULE_NAME,$action=ACTION_NAME)
{
//鍐崇瓥璁よ瘉鍙锋槸鍚﹀叿鏈夊綋鍓嶆ā鍧楁潈闄?
$db = DB::getInstance();
$sql = "select a.id from ".
$this->roleTable." as a,".
$this->roleUserTable." as b,".
$this->roleAccessTable." as c ,".
$this->roleNodeTable." as d ".
"where b.userId={$authId} and b.groupId=a.id and ( c.groupId=a.id or (c.groupId=a.pid and a.pid!=0 ) ) and a.status=1 and c.groupId=a.id and c.nodeId=d.id and ( (d.name='".$module."' and d.level=2) or ( d.name='".$action."' and d.level=3 ) or ( d.name='".$app."' and d.level=1) )";
$rs = $db->query($sql);
if($rs->count()>0) {
return true;
}else {
return false;
}
}
/**
+----------------------------------------------------------
* 鍙栧緱褰撳墠璁よ瘉鍙风殑鎵鏈夋潈闄愬垪琛?
+----------------------------------------------------------
* @param string $appPrefix 鏁版嵁搴撳墠缂
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function getAccessList($authId)
{
// 璇诲彇椤圭洰鏉冮檺
$db = DB::getInstance();
$sql = "select d.id,d.name from ".
$this->roleTable." as a,".
$this->roleUserTable." as b,".
$this->roleAccessTable." as c ,".
$this->roleNodeTable." as d ".
"where b.userId={$authId} and b.groupId=a.id and ( c.groupId=a.id or (c.groupId=a.pid and a.pid!=0 ) ) and a.status=1 and c.nodeId=d.id and d.level=1 and d.status=1";
$apps = $db->query($sql);
$access = array();
foreach($apps as $key=>$app) {
$app = (array)$app;
$appId = $app['id'];
$appName = $app['name'];
// 璇诲彇椤圭洰鐨勬ā鍧楁潈闄?
$access[strtoupper($appName)] = array();
$sql = "select d.id,d.name from ".
$this->roleTable." as a,".
$this->roleUserTable." as b,".
$this->roleAccessTable." as c ,".
$this->roleNodeTable." as d ".
"where b.userId={$authId} and b.groupId=a.id and ( c.groupId=a.id or (c.groupId=a.pid and a.pid!=0 ) ) and a.status=1 and c.nodeId=d.id and d.level=2 and d.pid={$appId} and d.status=1";
$modules = $db->query($sql);
// 鍒ゆ柇鏄惁瀛樺湪鍏叡妯″潡鐨勬潈闄?
$publicAction = array();
fo