CAuthItem
CAuthItem represents an authorization item. An authorization item can be an operation, a task or a role. They form an authorization hierarchy. Items on higher levels of the hierarchy inherit the permissions represented by items on lower levels. A user may be assigned one or several authorization items (called
assignments. He can perform an operation only when it is among his assigned items.
Public Properties
Property |
Type |
Description |
Defined By |
authManager | IAuthManager | the authorization manager | CAuthItem |
bizRule | string | the business rule associated with this item | CAuthItem |
children | array | Returns the children of this item. | CAuthItem |
data | mixed | the additional data associated with this item | CAuthItem |
description | string | the item description | CAuthItem |
name | string | the item name | CAuthItem |
type | integer | the authorization item type. | CAuthItem |
Property Details
public IAuthManager getAuthManager()
the authorization manager
public string getBizRule()
public void setBizRule(string $value)
the business rule associated with this item
public array getChildren()
Returns the children of this item.
public mixed getData()
public void setData(mixed $value)
the additional data associated with this item
public string getDescription()
public void setDescription(string $value)
the item description
public string getName()
public void setName(string $value)
the item name
public integer getType()
the authorization item type. This could be 0 (operation), 1 (task) or 2 (role).
Method Details
public void __construct(IAuthManager $auth, string $name, integer $type, string $description='', string $bizRule=NULL, mixed $data=NULL) |
$auth | IAuthManager | authorization manager |
$name | string | authorization item name |
$type | integer | authorization item type. This can be 0 (operation), 1 (task) or 2 (role). |
$description | string | the description |
$bizRule | string | the business rule associated with this item |
$data | mixed | additional data for this item |
Source Code: framework/web/auth/CAuthItem.php#53 (
show)
public function __construct($auth,$name,$type,$description='',$bizRule=null,$data=null)
{
$this->_type=(int)$type;
$this->_auth=$auth;
$this->_name=$name;
$this->_description=$description;
$this->_bizRule=$bizRule;
$this->_data=$data;
}
Constructor.
public boolean addChild(string $name) |
$name | string | the name of the child item |
{return} | boolean | whether the item is added successfully |
Adds a child item.
public CAuthAssignment assign(mixed $userId, string $bizRule=NULL, mixed $data=NULL) |
$userId | mixed | the user ID (see IWebUser::getId) |
$bizRule | string | the business rule to be executed when checkAccess is called for this particular authorization item. |
$data | mixed | additional data associated with this assignment |
{return} | CAuthAssignment | the authorization assignment information. |
Assigns this item to a user.
public boolean checkAccess(string $itemName, array $params=array ( )) |
$itemName | string | the name of the item to be checked |
$params | array | the parameters to be passed to business rule evaluation |
{return} | boolean | whether the specified item is within the hierarchy starting from this item. |
Source Code: framework/web/auth/CAuthItem.php#71 (
show)
public function checkAccess($itemName,$params=array())
{
Yii::trace('Checking permission "'.$this->_name.'"','system.web.auth.CAuthItem');
if($this->_auth->executeBizRule($this->_bizRule,$params,$this->_data))
{
if($this->_name==$itemName)
return true;
foreach($this->_auth->getItemChildren($this->_name) as $item)
{
if($item->checkAccess($itemName,$params))
return true;
}
}
return false;
}
Checks to see if the specified item is within the hierarchy starting from this item. This method is expected to be internally used by the actual implementations of the IAuthManager::checkAccess.
Returns the item assignment information.
public string getBizRule() |
{return} | string | the business rule associated with this item |
public array getChildren() |
{return} | array | all child items of this item. |
Returns the children of this item.
public mixed getData() |
{return} | mixed | the additional data associated with this item |
public string getDescription() |
{return} | string | the item description |
public string getName() |
{return} | string | the item name |
public integer getType() |
{return} | integer | the authorization item type. This could be 0 (operation), 1 (task) or 2 (role). |
public boolean hasChild(string $name) |
$name | string | the child item name |
{return} | boolean | whether the child exists |
Returns a value indicating whether a child exists
public boolean isAssigned(mixed $userId) |
$userId | mixed | the user ID (see IWebUser::getId) |
{return} | boolean | whether the item has been assigned to the user. |
Returns a value indicating whether this item has been assigned to the user.
public boolean removeChild(string $name) |
$name | string | the child item name |
{return} | boolean | whether the removal is successful |
Removes a child item. Note, the child item is not deleted. Only the parent-child relationship is removed.
public boolean revoke(mixed $userId) |
$userId | mixed | the user ID (see IWebUser::getId) |
{return} | boolean | whether removal is successful |
Revokes an authorization assignment from a user.
public void setBizRule(string $value) |
$value | string | the business rule associated with this item |
public void setData(mixed $value) |
$value | mixed | the additional data associated with this item |
public void setDescription(string $value) |
$value | string | the item description |
public void setName(string $value) |
$value | string | the item name |
Source Code: framework/web/auth/CAuthItem.php#114 (
show)
public function setName($value)
{
if($this->_name!==$value)
{
$oldName=$this->_name;
$this->_name=$value;
$this->_auth->saveAuthItem($this,$oldName);
}
}