Skip to content

Commit f295bbb

Browse files
authored
Merge pull request #217 from cakephp/move-checks
Move Authentication service checks for early failures.
2 parents 1d1c6d7 + ea692ce commit f295bbb

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Controller/Component/AuthenticationComponent.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ public function initialize(array $config)
8585
*/
8686
public function beforeFilter()
8787
{
88+
if ($this->_authentication === null) {
89+
throw new Exception('The request object does not contain the required `authentication` attribute');
90+
}
91+
92+
if (!($this->_authentication instanceof AuthenticationServiceInterface)) {
93+
throw new Exception('Authentication service does not implement ' . AuthenticationServiceInterface::class);
94+
}
95+
8896
$provider = $this->_authentication->getAuthenticationProvider();
8997

9098
if ($provider === null ||
@@ -110,14 +118,6 @@ public function beforeFilter()
110118
*/
111119
public function startup()
112120
{
113-
if ($this->_authentication === null) {
114-
throw new Exception('The request object does not contain the required `authentication` attribute');
115-
}
116-
117-
if (!($this->_authentication instanceof AuthenticationServiceInterface)) {
118-
throw new Exception('Authentication service does not implement ' . AuthenticationServiceInterface::class);
119-
}
120-
121121
if (!$this->getConfig('requireIdentity')) {
122122
return;
123123
}

tests/TestCase/Controller/Component/AuthenticationComponentTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testInitializeMissingServiceAttribute()
8282
$controller = new Controller($this->request, $this->response);
8383
$registry = new ComponentRegistry($controller);
8484
$component = new AuthenticationComponent($registry);
85-
$component->startup();
85+
$component->beforeFilter();
8686
}
8787

8888
/**
@@ -98,7 +98,7 @@ public function testInitializeInvalidServiceObject()
9898
$controller = new Controller($request, $this->response);
9999
$registry = new ComponentRegistry($controller);
100100
$component = new AuthenticationComponent($registry);
101-
$component->startup();
101+
$component->beforeFilter();
102102
}
103103

104104
/**

0 commit comments

Comments
 (0)