Skip to content

Commit 21cf791

Browse files
committed
Refactoring SecurityComponent to show messages
1 parent e5ad7ff commit 21cf791

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

src/Controller/Component/SecurityComponent.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,37 +106,29 @@ public function startup(Event $event)
106106
$this->_action = $this->request->params['action'];
107107
try {
108108
$this->_secureRequired($controller);
109-
} catch (SecurityException $se) {
110-
$this->blackHole($controller, $se->getType(), $se);
111-
}
112-
try {
113109
$this->_authRequired($controller);
114-
} catch (AuthSecurityException $ase) {
115-
$this->blackHole($controller, $ase->getType(), $ase);
116-
}
117-
118110

119-
$hasData = !empty($this->request->data);
120-
$isNotRequestAction = (
121-
!isset($controller->request->params['requested']) ||
122-
$controller->request->params['requested'] != 1
123-
);
111+
$hasData = !empty($this->request->data);
112+
$isNotRequestAction = (
113+
!isset($controller->request->params['requested']) ||
114+
$controller->request->params['requested'] != 1
115+
);
124116

125-
if ($this->_action === $this->_config['blackHoleCallback']) {
126-
return $this->blackHole($controller, 'auth');
127-
}
117+
if ($this->_action === $this->_config['blackHoleCallback']) {
118+
throw new AuthSecurityException(sprintf('Action %s is defined as the blackhole callback.', $this->_action));
119+
}
128120

129-
if (!in_array($this->_action, (array)$this->_config['unlockedActions']) &&
130-
$hasData && $isNotRequestAction
131-
) {
132-
if ($this->_config['validatePost']) {
133-
try {
121+
if (!in_array($this->_action, (array)$this->_config['unlockedActions']) &&
122+
$hasData && $isNotRequestAction
123+
) {
124+
if ($this->_config['validatePost']) {
134125
$this->_validatePost($controller);
135-
} catch (SecurityException $se) {
136-
return $this->blackHole($controller, $se->getType(), $se);
137126
}
138127
}
128+
} catch (SecurityException $se) {
129+
$this->blackHole($controller, $se->getType(), $se);
139130
}
131+
140132
$this->generateToken($controller->request);
141133
if ($hasData && is_array($controller->request->data)) {
142134
unset($controller->request->data['_Token']);
@@ -188,6 +180,7 @@ public function requireAuth($actions)
188180
*
189181
* @param \Cake\Controller\Controller $controller Instantiating controller
190182
* @param string $error Error method
183+
* @param SecurityException $exception thrown by validate methods, passed only in debug mode
191184
* @return mixed If specified, controller blackHoleCallback's response, or no return otherwise
192185
* @see SecurityComponent::$blackHoleCallback
193186
* @link http://book.cakephp.org/3.0/en/controllers/components/security.html#handling-blackhole-callbacks

0 commit comments

Comments
 (0)