Skip to content

Commit

Permalink
Merge pull request #108 from cakephp/missing-identity
Browse files Browse the repository at this point in the history
MissingIdentity exception was never thrown.
  • Loading branch information
markstory authored Nov 9, 2019
2 parents 112f1a3 + 9e9bc18 commit 021935f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Controller/Component/AuthorizationComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Authorization\AuthorizationServiceInterface;
use Authorization\Exception\ForbiddenException;
use Authorization\Exception\MissingIdentityException;
use Authorization\IdentityInterface;
use Authorization\Policy\Result;
use Authorization\Policy\ResultInterface;
Expand Down Expand Up @@ -62,7 +63,7 @@ class AuthorizationComponent extends Component
public function authorize($resource, $action = null)
{
if ($action === null) {
$request = $this->getController()->request;
$request = $this->getController()->getRequest();
$action = $this->getDefaultAction($request);
}

Expand Down Expand Up @@ -96,14 +97,14 @@ public function authorize($resource, $action = null)
*/
public function can($resource, $action = null)
{
$request = $this->getController()->request;
$request = $this->getController()->getRequest();
if ($action === null) {
$action = $this->getDefaultAction($request);
}

$identity = $this->getIdentity($request);
if (empty($identity)) {
return $this->getService($this->request)->can(null, $action, $resource);
if ($identity === null) {
return $this->getService($request)->can(null, $action, $resource);
}

return $identity->can($action, $resource);
Expand All @@ -121,11 +122,14 @@ public function can($resource, $action = null)
*/
public function applyScope($resource, $action = null)
{
$request = $this->getController()->request;
$request = $this->getController()->getRequest();
if ($action === null) {
$action = $this->getDefaultAction($request);
}
$identity = $this->getIdentity($request);
if ($identity === null) {
throw new MissingIdentityException('Identity must exist for applyScope() call.');
}

return $identity->applyScope($action, $resource);
}
Expand All @@ -137,7 +141,7 @@ public function applyScope($resource, $action = null)
*/
public function skipAuthorization()
{
$request = $this->getController()->request;
$request = $this->getController()->getRequest();
$service = $this->getService($request);

$service->skipAuthorization();
Expand Down Expand Up @@ -249,7 +253,7 @@ protected function getIdentity(ServerRequestInterface $request)
*/
public function authorizeAction()
{
$request = $this->getController()->request;
$request = $this->getController()->getRequest();
$action = $request->getParam('action');

$skipAuthorization = $this->checkAction($action, 'skipAuthorization');
Expand Down

0 comments on commit 021935f

Please sign in to comment.