Skip to content
Permalink
Browse files

Allow getting of Authorize and Authenticate objects

Current there is no way of getting an authorize or authenticate object in order to call a custom method on them. This adds a simple getter for authorize and authenticate objects.
  • Loading branch information...
Walther Lalk
Walther Lalk committed Sep 1, 2014
1 parent c5999bb commit 6ba5dfeedf7a6ea28604c04447919d88c448ab99
Showing with 51 additions and 2 deletions.
  1. +51 −2 src/Controller/Component/AuthComponent.php
@@ -500,12 +500,36 @@ public function constructAuthorize() {
if (!method_exists($className, 'authorize')) {
throw new Exception('Authorization objects must implement an authorize() method.');
}
if (!empty($config['alias'])) {
$alias = $config['alias'];
unset($config['alias']);
} else {
$alias = $className;
}
$config = (array)$config + $global;
$this->_authorizeObjects[] = new $className($this->_registry, $config);
$this->_authorizeObjects[$alias] = new $className($this->_registry, $config);
}
return $this->_authorizeObjects;
}
/**
* Getter for authorize objects. Will either return an array of all authorize objects, or a particular authorize object.
*
* @param string|null $alias Alias for the authorize object
* @return \Cake\Auth\BaseAuthorize|array|null
*/
public function getAuthorize($alias = null) {
if (empty($this->_authorizeObjects)) {
$this->constructAuthorize();
}
if ($alias !== null && isset($this->_authorizeObjects[$alias])) {
return $this->_authorizeObjects[$alias];
}
return $alias === null ? $this->_authorizeObjects : null;
}
/**
* Takes a list of actions in the current controller for which authentication is not required, or
* no parameters to allow all actions.
@@ -741,12 +765,37 @@ public function constructAuthenticate() {
if (!method_exists($className, 'authenticate')) {
throw new Exception('Authentication objects must implement an authenticate() method.');
}
if (!empty($config['alias'])) {
$alias = $config['alias'];
unset($config['alias']);
} else {
$alias = $className;
}
$config = array_merge($global, (array)$config);
$this->_authenticateObjects[] = new $className($this->_registry, $config);
$this->_authenticateObjects[$alias] = new $className($this->_registry, $config);
}
return $this->_authenticateObjects;
}
/**
* Getter for authenticate objects. Will either return an array of all authenticate objects, or a particular authenticate object.
*
* @param string|null $alias Alias for the authenticate object
*
* @return \Cake\Auth\BaseAuthenticate|array|null
*/
public function getAuthenticate($alias = null) {
if (empty($this->_authenticateObjects)) {
$this->constructAuthenticate();
}
if ($alias !== null && isset($this->_authenticateObjects[$alias])) {
return $this->_authenticateObjects[$alias];
}
return $alias === null ? $this->_authenticateObjects : null;
}
/**
* Set a flash message. Uses the Session component, and values from `flash` config.
*

0 comments on commit 6ba5dfe

Please sign in to comment.
You can’t perform that action at this time.