CAuthManager
鍖 | system.web.auth |
---|---|
缁ф壙 | abstract class CAuthManager » CApplicationComponent » CComponent |
瀹炵幇 | IApplicationComponent, IAuthManager |
瀛愮被 | CDbAuthManager, CPhpAuthManager |
婧愯嚜 | 1.0 |
鐗堟湰 | $Id: CAuthManager.php 3515 2011-12-28 12:29:24Z mdomba $ |
婧愮爜 | framework/web/auth/CAuthManager.php |
CAuthManager缁ф壙浜CApplicationComponent锛屽疄鐜颁簡涓浜 鍦ㄦ巿鏉冪鐞嗙被涓殑閫氱敤鏂规硶銆
CAuthManager鍜屽畠鐨勫叿浣撳瓙绫诲疄鐜颁簡 鍩轰簬鐢ㄦ埛瑙掕壊璁块棶鎺у埗锛圧BAC锛夈
涓昏鎬濇兂鏄紝灞傜骇鏉冮檺鏄敱 鎺堟潈椤圭洰鏉ョ鐞嗙殑銆傞珮灞傜殑椤圭洰 缁ф壙浜嗕綆灞傜殑椤圭洰鏉冮檺銆傝鑹叉槸鏈楂樼骇鐨勬巿鏉冮」鐩紝 浼氳祴浜堢粰姣忎釜鐢ㄦ埛銆備竴涓敤鎴锋墍鎷ユ湁鐨勬潈闄愶紝 鏄敱浠栫殑瑙掕壊鎵缁ф壙鐨勬巿鏉冮」鐩喅瀹氱殑銆
浣跨敤鎺堟潈绠$悊鍣ㄥ寘鍚袱涓柟闈€傜涓锛屾巿鏉冪瓑绾у拰浠诲姟 蹇呴』瑕佹棦瀹氱殑銆侰AuthManager鍜屽畠鐨勫瓙绫 鎻愪緵API鏉ュ畬鎴愯繖涓换鍔°傚紑鍙戜汉鍛橀渶瑕佸紑鍙戜竴浜汫UI锛 浣胯繖浜涙搷浣滄洿鍔犵洿瑙傜殑灞曠ず缁欐渶缁堢敤鎴枫傜浜岋紝寮鍙戜汉鍛樺湪绋嬪簭閲岄潰閫傚綋鐨勪綅缃 璋冪敤IAuthManager::checkAccess鏉ユ娴嬪綋鍓嶇敤鎴 鏄惁鍚湁璇ユ搷浣滅殑鏉冮檺銆
鍏叡灞炴
灞炴 | 绫诲瀷 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|---|
authItems | array | 杩斿洖鎸囧畾绫诲瀷鍜岀敤鎴风殑鎺堟潈椤广 | IAuthManager |
behaviors | array | 杩欎釜搴旂敤缁勪欢闄勫姞鐨勮涓恒 杩欐琛屼负灏嗗湪搴旂敤缁勪欢璋冪敤init鏃堕檮鍔犲湪搴旂敤缁勪欢涓娿 璇峰弬鐓CModel::behaviors濡備綍鎸囧畾姝ゅ睘鎬у笺 | CApplicationComponent |
defaultRoles | array | 闅愬紡璧嬩簣缁欐墍鏈夌敤鎴风殑瑙掕壊鍚嶅瓧鍒楄〃銆 杩欎簺瑙掕壊涓嶉渶瑕佹樉寮忚祴浜堢粰鎵鏈夌敤鎴枫 褰撹皟鐢checkAccess锛屼細棣栧厛妫鏌ヨ繖浜涜鑹层 涓轰簡鑳藉鎻愰珮绋嬪簭鏁堢巼锛岃繖鏍风殑瑙掕壊瓒婂皯瓒婂ソ銆 涓涓吀鍨嬬殑鐢ㄦ硶鏄紝瀹氫箟涓涓渁uthenticated鈥濊鑹诧紝鐒跺悗 鎶婂畠鍏宠仈鍒颁竴涓笟鍔¢昏緫瑙勫垯锛岃繖涓鍒欐槸鐢ㄦ潵楠岃瘉褰撳墠鐢ㄦ埛鐨勩 鐒跺悗鍦ㄨ繖涓睘鎬у0鏄庘渁uthenticated鈥濅互渚垮簲鐢ㄥ埌 鎵鏈夌殑楠岃瘉鐢ㄦ埛銆 | CAuthManager |
isInitialized | boolean | 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 | CApplicationComponent |
operations | array | 杩斿洖鎿嶄綔銆 | CAuthManager |
roles | array | 杩斿洖瑙掕壊銆 | CAuthManager |
showErrors | boolean | 鍏佽涓氬姟瑙勫垯閿欒鎶ュ憡銆 | CAuthManager |
tasks | array | 杩斿洖浠诲姟銆 | CAuthManager |
鍏叡鏂规硶
灞炴ц缁
闅愬紡璧嬩簣缁欐墍鏈夌敤鎴风殑瑙掕壊鍚嶅瓧鍒楄〃銆 杩欎簺瑙掕壊涓嶉渶瑕佹樉寮忚祴浜堢粰鎵鏈夌敤鎴枫 褰撹皟鐢checkAccess锛屼細棣栧厛妫鏌ヨ繖浜涜鑹层 涓轰簡鑳藉鎻愰珮绋嬪簭鏁堢巼锛岃繖鏍风殑瑙掕壊瓒婂皯瓒婂ソ銆 涓涓吀鍨嬬殑鐢ㄦ硶鏄紝瀹氫箟涓涓渁uthenticated鈥濊鑹诧紝鐒跺悗 鎶婂畠鍏宠仈鍒颁竴涓笟鍔¢昏緫瑙勫垯锛岃繖涓鍒欐槸鐢ㄦ潵楠岃瘉褰撳墠鐢ㄦ埛鐨勩 鐒跺悗鍦ㄨ繖涓睘鎬у0鏄庘渁uthenticated鈥濅互渚垮簲鐢ㄥ埌 鎵鏈夌殑楠岃瘉鐢ㄦ埛銆
杩斿洖鎿嶄綔銆 杩欎釜鏂规硶鏄IAuthManager::getAuthItems鐨勫揩鎹锋柟寮
杩斿洖瑙掕壊銆 杩欎釜鏂规硶鏄IAuthManager::getAuthItems鐨勫揩鎹锋柟寮忋
鍏佽涓氬姟瑙勫垯閿欒鎶ュ憡銆
杩斿洖浠诲姟銆 杩欎釜鏂规硶鏄IAuthManager::getAuthItems鐨勫揩鎹锋柟寮
鏂规硶璇︾粏
protected void checkItemChildType(integer $parentType, integer $childType)
| ||
$parentType | integer | 鐖堕」鐩殑绫诲瀷 |
$childType | integer | 瀛愰」鐩被鍨 |
protected function checkItemChildType($parentType,$childType)
{
static $types=array('operation','task','role');
if($parentType < $childType)
throw new CException(Yii::t('yii','Cannot add an item of type "{child}" to an item of type "{parent}".',
array('{child}'=>$types[$childType], '{parent}'=>$types[$parentType])));
}
妫鏌ラ」鐩被鍨嬩互纭畾涓涓瓙椤圭洰宸茬粡璧嬩簣缁欎竴涓埗椤圭洰銆
public CAuthItem createOperation(string $name, string $description='', string $bizRule=NULL, mixed $data=NULL)
| ||
$name | string | 椤圭洰鍚嶅瓧 |
$description | string | 椤圭洰鎻忚堪銆 |
$bizRule | string | 鍏宠仈鍒拌繖涓」鐩殑涓氬姟閫昏緫 |
$data | mixed | 褰撴墽琛屼笟鍔¤鍒欑殑鏃跺欐墍浼犻掔殑棰濆鐨勬暟鎹 |
{return} | CAuthItem | 鎺堟潈椤圭洰銆 |
public function createOperation($name,$description='',$bizRule=null,$data=null)
{
return $this->createAuthItem($name,CAuthItem::TYPE_OPERATION,$description,$bizRule,$data);
}
鍒涘缓涓涓搷浣溿 杩欎釜鏂规硶鏄IAuthManager::createAuthItem鐨勫揩鎹锋柟寮忋
public CAuthItem createRole(string $name, string $description='', string $bizRule=NULL, mixed $data=NULL)
| ||
$name | string | 椤圭洰鍚嶅瓧 |
$description | string | 椤圭洰鎻忚堪銆 |
$bizRule | string | 鍏宠仈鍒拌繖涓」鐩殑涓氬姟瑙勫垯 |
$data | mixed | 鎵ц涓氬姟瑙勫垯鐨勬椂鍊欐墍浼犻掔殑棰濆鐨勬暟鎹 |
{return} | CAuthItem | 鎺堟潈椤圭洰 |
public function createRole($name,$description='',$bizRule=null,$data=null)
{
return $this->createAuthItem($name,CAuthItem::TYPE_ROLE,$description,$bizRule,$data);
}
鍒涘缓涓涓鑹层 杩欎釜鏂规硶鏄IAuthManager::createAuthItem鐨勫揩鎹锋柟寮忋
public CAuthItem createTask(string $name, string $description='', string $bizRule=NULL, mixed $data=NULL)
| ||
$name | string | 椤圭洰鍚嶅瓧 |
$description | string | 椤圭洰鎻忚堪銆 |
$bizRule | string | 鍏宠仈鍒拌繖涓」鐩殑涓氬姟瑙勫垯銆 |
$data | mixed | 鎵ц杩欎釜涓氬姟瑙勫垯鏃跺欐墍浼犻掔殑棰濆鐨勬暟鎹 |
{return} | CAuthItem | 楠岃瘉椤圭洰銆 |
public function createTask($name,$description='',$bizRule=null,$data=null)
{
return $this->createAuthItem($name,CAuthItem::TYPE_TASK,$description,$bizRule,$data);
}
鍒涘缓涓涓换鍔° 杩欎釜鏂规硶鏄IAuthManager::createAuthItem鐨勫揩鎹锋柟寮忋
public boolean executeBizRule(string $bizRule, array $params, mixed $data)
| ||
$bizRule | string | 瑕佹墽琛岀殑涓氬姟瑙勫垯銆 |
$params | array | 浼犻掔粰IAuthManager::checkAccess鐨勫弬鏁 |
$data | mixed | 鍏宠仈鍒版巿鏉冮」鐩垨鑰呬换鍔$殑棰濆鐨勬暟鎹 |
{return} | boolean | 杩欎釜涓氬姟瑙勫垯鏄惁杩斿洖true銆 濡傛灉涓氬姟瑙勫垯涓虹┖锛屽垯杩斿洖true銆 |
public function executeBizRule($bizRule,$params,$data)
{
return $bizRule==='' || $bizRule===null || ($this->showErrors ? eval($bizRule)!=0 : @eval($bizRule)!=0);
}
鎵ц鎸囧畾鐨勪笟鍔¤鍒欍
public array getOperations(mixed $userId=NULL)
| ||
$userId | mixed | 鐢ㄦ埛ID銆傚鏋滀笉涓簄ull锛岄偅涔堝彧浼氳繑鍥炶祴浜堢粰杩欎釜 鐢ㄦ埛鐨勬搷浣溿傚惁鍒欒繑鍥炴墍鏈夌殑鎿嶄綔銆 |
{return} | array | operations (name=>CAuthItem) |
public function getOperations($userId=null)
{
return $this->getAuthItems(CAuthItem::TYPE_OPERATION,$userId);
}
杩斿洖鎿嶄綔銆 杩欎釜鏂规硶鏄IAuthManager::getAuthItems鐨勫揩鎹锋柟寮
public array getRoles(mixed $userId=NULL)
| ||
$userId | mixed | 鐢ㄦ埛ID銆傚鏋滀笉涓簄ull锛岄偅涔堝彧杩斿洖璧嬩簣缁欒繖涓敤鎴 鐨勮鑹层傚惁鍒欒繑鍥炴墍鏈夌殑瑙掕壊銆 |
{return} | array | 瑙掕壊锛坣ame=>CAuthItem锛 |
public function getRoles($userId=null)
{
return $this->getAuthItems(CAuthItem::TYPE_ROLE,$userId);
}
杩斿洖瑙掕壊銆 杩欎釜鏂规硶鏄IAuthManager::getAuthItems鐨勫揩鎹锋柟寮忋
public array getTasks(mixed $userId=NULL)
| ||
$userId | mixed | 鐢ㄦ埛ID銆傚鏋滀笉涓簄ull锛屽彧杩斿洖璧嬩簣缁欒繖涓敤鎴 浠诲姟銆傚惁鍒欒繑鍥炴墍鏈変换鍔° |
{return} | array | tasks (name=>CAuthItem) |
public function getTasks($userId=null)
{
return $this->getAuthItems(CAuthItem::TYPE_TASK,$userId);
}
杩斿洖浠诲姟銆 杩欎釜鏂规硶鏄IAuthManager::getAuthItems鐨勫揩鎹锋柟寮