An authorization adapter for AuthComponent. Provides the ability to authorize using a controller callback. Your controller's isAuthorized() method should return a boolean to indicate whether or not the user is authorized.
public function isAuthorized($user) { if (!empty($this->request->params['admin'])) { return $user['role'] === 'admin'; } return !empty($user); }
the above is simple implementation that would only authorize users of the 'admin' role to access admin routing.
AuthComponent::$authenticate
authorize( array $user , CakeRequest $request )
Checks user authorization using a controller callback.
$user
CakeRequest
$request
boolean
controller( Controller $controller null )
Get/set the controller this authorize object will be working with. Also checks that isAuthorized is implemented.
Controller
$controller
optional null mixed
CakeException
BaseAuthorize::controller()
__construct( ComponentCollection $collection , string $settings array() )
Constructor
ComponentCollection
$collection
$settings
optional array() action( CakeRequest $request , string $path '/:plugin/:controller/:action' )
Get the action path for a given request. Primarily used by authorize objects that need to get information about the plugin, controller, and action being invoked.
CakeRequest
$request
$path
optional '/:plugin/:controller/:action' string
mapActions( array $map array() )
Maps crud actions to actual action names. Used to modify or get the current mapped actions.
Create additional mappings for a standard CRUD operation:
$this->Auth->mapActions(array('create' => array('add', 'register'));
Or equivalently:
$this->Auth->mapActions(array('register' => 'create', 'add' => 'create'));
Create mappings for custom CRUD operations:
$this->Auth->mapActions(array('range' => 'search'));
You can use the custom CRUD operations to create additional generic permissions that behave like CRUD operations. Doing this will require additional columns on the permissions lookup. For example if one wanted an additional search CRUD operation one would create and additional column '_search' in the aros_acos table. One could create a custom admin CRUD operation for administration functions similarly if needed.
$map
optional array() mixed
AuthComponent::mapActions()
protected ComponentCollection
Component collection instance for getting more components.
public array
Settings for authorize objects.
actionPath
- The path to ACO nodes that contains the nodes for controllers. Used as a prefix when calling $this->action();actionMap
- Action -> crud mappings. Used by authorization objects that want to map actions to CRUD roles.userModel
- Model name that ARO records can be found under. Defaults to 'User'.array( 'actionPath' => null, 'actionMap' => array( 'index' => 'read', 'add' => 'create', 'edit' => 'update', 'view' => 'read', 'delete' => 'delete', 'remove' => 'delete' ), 'userModel' => 'User' )
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-ControllerAuthorize.html