PHP Class CakeDC\Users\Auth\SimpleRbacAuthorize

Matches current plugin/controller/action against defined permissions in permissions.php file
Inheritance: extends Cake\Auth\BaseAuthorize, use trait Cake\Log\LogTrait
ファイルを表示 Open project: CakeDC/users Class Usage Examples

Protected Properties

Property Type Description
$_defaultConfig
$_defaultPermissions array Default permissions to be loaded if no provided permissions

Public Methods

Method Description
__construct ( Cake\Controller\ComponentRegistry $registry, array $config = [] ) Autoload permission configuration
authorize ( array $user, Cake\Network\Request $request ) : boolean Match the current plugin/controller/action against loaded permissions Set a default role if no role is provided

Protected Methods

Method Description
_checkPermissions ( array $user, string $role, Cake\Network\Request $request ) : boolean Match against permissions, return if matched Permissions are processed based on the 'permissions' config values
_loadPermissions ( string $key ) : array Load config and retrieve permissions If the configuration file does not exist, or the permissions key not present, return defaultPermissions To be mocked
_matchOrAsterisk ( string | array $possibleValues, string | mixed | null $value, boolean $allowEmpty = false ) : boolean Check if rule matched or '*' present in rule matching anything
_matchPermission ( array $permission, array $user, string $role, Cake\Network\Request $request ) : null | boolean Match the rule for current permission
_startsWith ( string $haystack, string $needle ) : boolean Checks if $heystack begins with $needle

Method Details

__construct() public method

Autoload permission configuration
public __construct ( Cake\Controller\ComponentRegistry $registry, array $config = [] )
$registry Cake\Controller\ComponentRegistry component registry
$config array config

_checkPermissions() protected method

Match against permissions, return if matched Permissions are processed based on the 'permissions' config values
protected _checkPermissions ( array $user, string $role, Cake\Network\Request $request ) : boolean
$user array current user array
$role string effective role for the current user
$request Cake\Network\Request request
return boolean true if there is a match in permissions

_loadPermissions() protected method

Load config and retrieve permissions If the configuration file does not exist, or the permissions key not present, return defaultPermissions To be mocked
protected _loadPermissions ( string $key ) : array
$key string name of the configuration file to read permissions from
return array permissions

_matchOrAsterisk() protected method

Check if rule matched or '*' present in rule matching anything
protected _matchOrAsterisk ( string | array $possibleValues, string | mixed | null $value, boolean $allowEmpty = false ) : boolean
$possibleValues string | array Values that are accepted (from permission config)
$value string | mixed | null Value to check with. We'll check the DASHERIZED value too
$allowEmpty boolean If true and $value is null, the rule will pass
return boolean

_matchPermission() protected method

Match the rule for current permission
protected _matchPermission ( array $permission, array $user, string $role, Cake\Network\Request $request ) : null | boolean
$permission array The permission configuration
$user array Current user data
$role string Effective user's role
$request Cake\Network\Request Current request
return null | boolean Null if permission is discarded, boolean if a final result is produced

_startsWith() protected method

Checks if $heystack begins with $needle
See also: http://stackoverflow.com/a/7168986/2588539
protected _startsWith ( string $haystack, string $needle ) : boolean
$haystack string The whole string
$needle string The beginning to check
return boolean

authorize() public method

Match the current plugin/controller/action against loaded permissions Set a default role if no role is provided
public authorize ( array $user, Cake\Network\Request $request ) : boolean
$user array user data
$request Cake\Network\Request request
return boolean

Property Details

$_defaultConfig protected_oe property

protected $_defaultConfig

$_defaultPermissions protected_oe property

Default permissions to be loaded if no provided permissions
protected array $_defaultPermissions
return array