Skip to content

Commit

Permalink
Refactoring SecurityComponent to show messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ajibarra committed Mar 11, 2016
1 parent e5ad7ff commit 21cf791
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/Controller/Component/SecurityComponent.php
Expand Up @@ -106,37 +106,29 @@ public function startup(Event $event)
$this->_action = $this->request->params['action'];
try {
$this->_secureRequired($controller);
} catch (SecurityException $se) {
$this->blackHole($controller, $se->getType(), $se);
}
try {
$this->_authRequired($controller);
} catch (AuthSecurityException $ase) {
$this->blackHole($controller, $ase->getType(), $ase);
}


$hasData = !empty($this->request->data);
$isNotRequestAction = (
!isset($controller->request->params['requested']) ||
$controller->request->params['requested'] != 1
);
$hasData = !empty($this->request->data);
$isNotRequestAction = (
!isset($controller->request->params['requested']) ||
$controller->request->params['requested'] != 1
);

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

if (!in_array($this->_action, (array)$this->_config['unlockedActions']) &&
$hasData && $isNotRequestAction
) {
if ($this->_config['validatePost']) {
try {
if (!in_array($this->_action, (array)$this->_config['unlockedActions']) &&
$hasData && $isNotRequestAction
) {
if ($this->_config['validatePost']) {
$this->_validatePost($controller);
} catch (SecurityException $se) {
return $this->blackHole($controller, $se->getType(), $se);
}
}
} catch (SecurityException $se) {
$this->blackHole($controller, $se->getType(), $se);
}

$this->generateToken($controller->request);
if ($hasData && is_array($controller->request->data)) {
unset($controller->request->data['_Token']);
Expand Down Expand Up @@ -188,6 +180,7 @@ public function requireAuth($actions)
*
* @param \Cake\Controller\Controller $controller Instantiating controller
* @param string $error Error method
* @param SecurityException $exception thrown by validate methods, passed only in debug mode
* @return mixed If specified, controller blackHoleCallback's response, or no return otherwise
* @see SecurityComponent::$blackHoleCallback
* @link http://book.cakephp.org/3.0/en/controllers/components/security.html#handling-blackhole-callbacks
Expand Down

0 comments on commit 21cf791

Please sign in to comment.