AuthorizationComponentは、コントローラーからのアクセス許可を確認するためのいくつかの規則ベースのヘルパーメソッドを公開します。
これは、ユーザーの取得とcanまたはapplyScopeメソッドの呼び出しを抽象化します。AuthorizationComponentを使用するには、ミドルウェアを使用する必要があるため、ミドルウェアも適用されていることを確認してください。コンポーネントを使用するには、まずそれをロードします。
// In your AppController
public function initialize()
{
    parent::initialize();
    $this->loadComponent('Authorization.Authorization');
}
AuthorizationComponentは、コントローラーの既定のモデルクラスと現在のアクション名に基づいて自動的に承認を適用するように構成できます。次の例では、インデックスと追加のアクションが許可されます:
$this->Authorization->authorizeModel('index', 'add');
承認をスキップするようにアクションを設定することもできます。
    これにより、アクションが公開され、すべてのユーザーがアクセスできるようになります。
    デフォルトでは、すべてのアクションには認証が必要であり、認証チェックが有効になっている場合はAuthorizationRequiredExceptionがスローされます。
個々のアクションの承認はスキップできます:
$this->loadComponent('Authorization.Authorization', [
    'skipAuthorization' => [
        'login',
    ]
]);
コントローラーアクションまたはコールバックメソッドで、コンポーネントを使用して承認を確認できます:
// In the Articles Controller.
public function edit($id)
{
    $article = $this->Articles->get($id);
    $this->Authorization->authorize($article);
    // Rest of the edit method.
}
上には、現在のユーザーに対して承認されている記事が表示されます。リクエストのアクションをチェックするアクションを指定していないため、使用されます。2番目のパラメーターでポリシーアクションを指定できます:
// Use a policy method that doesn't match the current controller action.
$this->Authorization->authorize($article, 'update');
権限が拒否された場合、authorize()メソッドはAuthorization\Exception\ForbiddenExceptionを発生させます。
承認を確認してブール結果を取得したい場合は、can()メソッドを使用できます:
if ($this->Authorization->can($article, 'update')) {
    // Do something to the article.
}
アプリケーションの一部のリソースは、ログインしていないユーザーがアクセスできる場合があります。認証されていないユーザーがリソースにアクセスできるかどうかは、ポリシーのドメインにあります。
コンポーネントを通じて、匿名ユーザーの承認を確認できます。can()とauthorize()はどちらも匿名ユーザーをサポートしています。ユーザーがログインしていない場合、ポリシーは「user」パラメーターに対してnullを取得することを期待できます。
コンポーネントを使用してポリシースコープを適用することもできます:
$query = $this->Authorization->applyScope($this->Articles->find());
現在のアクションにログインしているユーザーがいない場合、MissingIdentityExceptionが発生します。
アクションを別の認証方法にマップする場合は、actionMapオプションを使用します:
// In you controller initialize() method:
$this->Authorization->mapActions([
    'index' => 'list',
    'delete' => 'remove',
    'add' => 'insert',
]);
// or map actions individually.
$this->Authorization
    ->mapAction('index','list')
    ->mapAction('delete', 'remove')
    ->mapAction('add', 'insert');
例:
//ArticlesController.php
public function index()
{
    $query = $this->Articles->find();
    //this will apply `list` scope while being called in `index` controller action.
    $this->Authorization->applyScope($query);
    ...
}
public function delete($id)
{
    $article = $this->Articles->get($id);
    //this will authorize against `remove` entity action while being called in `delete` controller action.
    $this->Authorization->authorize($article);
    ...
}
public function add()
{
    //this will authorize against `insert` model action while being called in `add` controller action.
    $this->Authorization->authorizeModel();
    ...
}
認可はアクション内でスキップすることもできます:
//ArticlesController.php
public function view($id)
{
    $this->Authorization->skipAuthorization();
    ...
}