CAccessControlFilter
| Package |
system.web.auth |
| Inheritance |
class CAccessControlFilter »
CFilter »
CComponent |
| Implements |
IFilter |
| Since |
1.0 |
| Version |
$Id: CAccessControlFilter.php 2192 2010-06-15 21:43:32Z alexander.makarow $ |
CAccessControlFilter performs authorization checks for the specified actions.
By enabling this filter, controller actions can be checked for access permissions.
Only when the user is allowed by one of the security rules, will he be able
to access the action.
To specify the access rules, set the
rules property, which should
be an array of the rules. Each rule is specified as an array of the following structure:
array(
'allow', // or 'deny'
// optional, list of action IDs (case insensitive) that this rule applies to
'actions'=>array('edit', 'delete'),
// optional, list of controller IDs (case insensitive) that this rule applies to
// This option is available since version 1.0.3.
'controllers'=>array('post', 'admin/user'),
// optional, list of usernames (case insensitive) that this rule applies to
// Use * to represent all users, ? guest users, and @ authenticated users
'users'=>array('thomas', 'kevin'),
// optional, list of roles (case sensitive!) that this rule applies to.
'roles'=>array('admin', 'editor'),
// optional, list of IP address/patterns that this rule applies to
// e.g. 127.0.0.1, 127.0.0.*
'ips'=>array('127.0.0.1'),
// optional, list of request types (case insensitive) that this rule applies to
'verbs'=>array('GET', 'POST'),
// optional, a PHP expression whose value indicates whether this rule applies
// This option is available since version 1.0.3.
'expression'=>'!$user->isGuest && $user->level==2',
// optional, the customized error message to be displayed
// This option is available since version 1.1.1.
'message'=>'Access Denied.',
)
Public Properties
Hide inherited properties
| Property | Type | Description | Defined By |
| message |
string |
the error message to be displayed when authorization fails. |
CAccessControlFilter |
| rules |
array |
list of access rules. |
CAccessControlFilter |
Property Details
public string $message;
the error message to be displayed when authorization fails.
This property can be overridden by individual access rule via CAccessRule::message.
If this property is not set, a default error message will be displayed.
list of access rules.
Method Details
protected void accessDenied( IWebUser $user, string $message)
|
| $user |
IWebUser |
the current user |
| $message |
string |
the error message to be displayed |
Denies the access of the user.
This method is invoked when access check fails.
|
public array getRules()
|
| {return} |
array |
list of access rules. |
|
|
| $filterChain |
CFilterChain |
the filter chain that the filter is on. |
| {return} |
boolean |
whether the filtering process should continue and the action
should be executed. |
Performs the pre-action filtering.
protected string resolveErrorMessage( CAccessRule $rule)
|
| $rule |
CAccessRule |
the access rule |
| {return} |
string |
the error message |
Resolves the error message to be displayed.
This method will check message and CAccessRule::message to see
what error message should be displayed.
|
public void setRules(array $rules)
|
| $rules |
array |
list of access rules. |