CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • AbstractPasswordHasher
  • BaseAuthenticate
  • BaseAuthorize
  • BasicAuthenticate
  • ControllerAuthorize
  • DefaultPasswordHasher
  • DigestAuthenticate
  • FallbackPasswordHasher
  • FormAuthenticate
  • PasswordHasherFactory
  • WeakPasswordHasher
 1: <?php
 2: /**
 3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 5:  *
 6:  * Licensed under The MIT License
 7:  * For full copyright and license information, please see the LICENSE.txt
 8:  * Redistributions of files must retain the above copyright notice.
 9:  *
10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11:  * @link          https://cakephp.org CakePHP(tm) Project
12:  * @since         2.0.0
13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
14:  */
15: namespace Cake\Auth;
16: 
17: use Cake\Controller\ComponentRegistry;
18: use Cake\Controller\Controller;
19: use Cake\Core\Exception\Exception;
20: use Cake\Http\ServerRequest;
21: 
22: /**
23:  * An authorization adapter for AuthComponent. Provides the ability to authorize
24:  * using a controller callback. Your controller's isAuthorized() method should
25:  * return a boolean to indicate whether or not the user is authorized.
26:  *
27:  * ```
28:  *  public function isAuthorized($user)
29:  *  {
30:  *      if ($this->request->getParam('admin')) {
31:  *          return $user['role'] === 'admin';
32:  *      }
33:  *      return !empty($user);
34:  *  }
35:  * ```
36:  *
37:  * The above is simple implementation that would only authorize users of the
38:  * 'admin' role to access admin routing.
39:  *
40:  * @see \Cake\Controller\Component\AuthComponent::$authenticate
41:  */
42: class ControllerAuthorize extends BaseAuthorize
43: {
44:     /**
45:      * Controller for the request.
46:      *
47:      * @var \Cake\Controller\Controller
48:      */
49:     protected $_Controller;
50: 
51:     /**
52:      * {@inheritDoc}
53:      */
54:     public function __construct(ComponentRegistry $registry, array $config = [])
55:     {
56:         parent::__construct($registry, $config);
57:         $this->controller($registry->getController());
58:     }
59: 
60:     /**
61:      * Get/set the controller this authorize object will be working with. Also
62:      * checks that isAuthorized is implemented.
63:      *
64:      * @param \Cake\Controller\Controller|null $controller null to get, a controller to set.
65:      * @return \Cake\Controller\Controller
66:      * @throws \Cake\Core\Exception\Exception If controller does not have method `isAuthorized()`.
67:      */
68:     public function controller(Controller $controller = null)
69:     {
70:         if ($controller) {
71:             if (!method_exists($controller, 'isAuthorized')) {
72:                 throw new Exception(sprintf(
73:                     '%s does not implement an isAuthorized() method.',
74:                     get_class($controller)
75:                 ));
76:             }
77:             $this->_Controller = $controller;
78:         }
79: 
80:         return $this->_Controller;
81:     }
82: 
83:     /**
84:      * Checks user authorization using a controller callback.
85:      *
86:      * @param array|\ArrayAccess $user Active user data
87:      * @param \Cake\Http\ServerRequest $request Request instance.
88:      * @return bool
89:      */
90:     public function authorize($user, ServerRequest $request)
91:     {
92:         return (bool)$this->_Controller->isAuthorized($user);
93:     }
94: }
95: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs