Skip to content

Commit 021935f

Browse files
authored
Merge pull request #108 from cakephp/missing-identity
MissingIdentity exception was never thrown.
2 parents 112f1a3 + 9e9bc18 commit 021935f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Controller/Component/AuthorizationComponent.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use Authorization\AuthorizationServiceInterface;
1818
use Authorization\Exception\ForbiddenException;
19+
use Authorization\Exception\MissingIdentityException;
1920
use Authorization\IdentityInterface;
2021
use Authorization\Policy\Result;
2122
use Authorization\Policy\ResultInterface;
@@ -62,7 +63,7 @@ class AuthorizationComponent extends Component
6263
public function authorize($resource, $action = null)
6364
{
6465
if ($action === null) {
65-
$request = $this->getController()->request;
66+
$request = $this->getController()->getRequest();
6667
$action = $this->getDefaultAction($request);
6768
}
6869

@@ -96,14 +97,14 @@ public function authorize($resource, $action = null)
9697
*/
9798
public function can($resource, $action = null)
9899
{
99-
$request = $this->getController()->request;
100+
$request = $this->getController()->getRequest();
100101
if ($action === null) {
101102
$action = $this->getDefaultAction($request);
102103
}
103104

104105
$identity = $this->getIdentity($request);
105-
if (empty($identity)) {
106-
return $this->getService($this->request)->can(null, $action, $resource);
106+
if ($identity === null) {
107+
return $this->getService($request)->can(null, $action, $resource);
107108
}
108109

109110
return $identity->can($action, $resource);
@@ -121,11 +122,14 @@ public function can($resource, $action = null)
121122
*/
122123
public function applyScope($resource, $action = null)
123124
{
124-
$request = $this->getController()->request;
125+
$request = $this->getController()->getRequest();
125126
if ($action === null) {
126127
$action = $this->getDefaultAction($request);
127128
}
128129
$identity = $this->getIdentity($request);
130+
if ($identity === null) {
131+
throw new MissingIdentityException('Identity must exist for applyScope() call.');
132+
}
129133

130134
return $identity->applyScope($action, $resource);
131135
}
@@ -137,7 +141,7 @@ public function applyScope($resource, $action = null)
137141
*/
138142
public function skipAuthorization()
139143
{
140-
$request = $this->getController()->request;
144+
$request = $this->getController()->getRequest();
141145
$service = $this->getService($request);
142146

143147
$service->skipAuthorization();
@@ -249,7 +253,7 @@ protected function getIdentity(ServerRequestInterface $request)
249253
*/
250254
public function authorizeAction()
251255
{
252-
$request = $this->getController()->request;
256+
$request = $this->getController()->getRequest();
253257
$action = $request->getParam('action');
254258

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

0 commit comments

Comments
 (0)