Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -4,19 +4,18 @@
*
* Manages user logins and permissions.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Controller.Component
* @since CakePHP(tm) v 0.10.0.1076
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Component', 'Controller');
@ -27,6 +26,7 @@ App::uses('Hash', 'Utility');
App::uses('CakeSession', 'Model/Datasource');
App::uses('BaseAuthorize', 'Controller/Component/Auth');
App::uses('BaseAuthenticate', 'Controller/Component/Auth');
App::uses('CakeEvent', 'Event');
/**
* Authentication control component class
@ -38,6 +38,11 @@ App::uses('BaseAuthenticate', 'Controller/Component/Auth');
*/
class AuthComponent extends Component {
/**
* Constant for 'all'
*
* @var string
*/
const ALL = 'all';
/**
@ -45,25 +50,25 @@ class AuthComponent extends Component {
*
* @var array
*/
public $components = array('Session', 'RequestHandler');
public $components = array('Session', 'Flash', 'RequestHandler');
/**
* An array of authentication objects to use for authenticating users. You can configure
* An array of authentication objects to use for authenticating users. You can configure
* multiple adapters and they will be checked sequentially when users are identified.
*
* {{{
* ```
* $this->Auth->authenticate = array(
* 'Form' => array(
* 'userModel' => 'Users.User'
* )
* );
* }}}
* ```
*
* Using the class name without 'Authenticate' as the key, you can pass in an array of settings for each
* authentication object. Additionally you can define settings that should be set to all authentications objects
* authentication object. Additionally you can define settings that should be set to all authentications objects
* using the 'all' key:
*
* {{{
* ```
* $this->Auth->authenticate = array(
* 'all' => array(
* 'userModel' => 'Users.User',
@ -72,7 +77,7 @@ class AuthComponent extends Component {
* 'Form',
* 'Basic'
* );
* }}}
* ```
*
* You can also use AuthComponent::ALL instead of the string 'all'.
*
@ -84,27 +89,27 @@ class AuthComponent extends Component {
/**
* Objects that will be used for authentication checks.
*
* @var array
* @var BaseAuthenticate[]
*/
protected $_authenticateObjects = array();
/**
* An array of authorization objects to use for authorizing users. You can configure
* An array of authorization objects to use for authorizing users. You can configure
* multiple adapters and they will be checked sequentially when authorization checks are done.
*
* {{{
* ```
* $this->Auth->authorize = array(
* 'Crud' => array(
* 'actionPath' => 'controllers/'
* )
* );
* }}}
* ```
*
* Using the class name without 'Authorize' as the key, you can pass in an array of settings for each
* authorization object. Additionally you can define settings that should be set to all authorization objects
* authorization object. Additionally you can define settings that should be set to all authorization objects
* using the 'all' key:
*
* {{{
* ```
* $this->Auth->authorize = array(
* 'all' => array(
* 'actionPath' => 'controllers/'
@ -112,7 +117,7 @@ class AuthComponent extends Component {
* 'Crud',
* 'CustomAuth'
* );
* }}}
* ```
*
* You can also use AuthComponent::ALL instead of the string 'all'
*
@ -124,7 +129,7 @@ class AuthComponent extends Component {
/**
* Objects that will be used for authorization checks.
*
* @var array
* @var BaseAuthorize[]
*/
protected $_authorizeObjects = array();
@ -153,8 +158,9 @@ class AuthComponent extends Component {
);
/**
* The session key name where the record of the current user is stored. If
* unspecified, it will be "Auth.User".
* The session key name where the record of the current user is stored. Default
* key is "Auth.User". If you are using only stateless authenticators set this
* to false to ensure session is not started.
*
* @var string
*/
@ -170,7 +176,7 @@ class AuthComponent extends Component {
/**
* A URL (defined as a string or array) to the controller action that handles
* logins. Defaults to `/users/login`
* logins. Defaults to `/users/login`.
*
* @var mixed
*/
@ -183,8 +189,8 @@ class AuthComponent extends Component {
/**
* Normally, if a user is redirected to the $loginAction page, the location they
* were redirected from will be stored in the session so that they can be
* redirected back after a successful login. If this session value is not
* set, the user will be redirected to the page specified in $loginRedirect.
* redirected back after a successful login. If this session value is not
* set, redirectUrl() method will return the URL specified in $loginRedirect.
*
* @var mixed
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#AuthComponent::$loginRedirect
@ -192,7 +198,7 @@ class AuthComponent extends Component {
public $loginRedirect = null;
/**
* The default action to redirect to after the user is logged out. While AuthComponent does
* The default action to redirect to after the user is logged out. While AuthComponent does
* not handle post-logout redirection, a redirect URL will be returned from AuthComponent::logout().
* Defaults to AuthComponent::$loginAction.
*
@ -206,11 +212,22 @@ class AuthComponent extends Component {
* Error to display when user attempts to access an object or action to which they do not have
* access.
*
* @var string
* @var string|bool
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#AuthComponent::$authError
*/
public $authError = null;
/**
* Controls handling of unauthorized access.
* - For default value `true` unauthorized user is redirected to the referrer URL
* or AuthComponent::$loginRedirect or '/'.
* - If set to a string or array the value is used as a URL to redirect to.
* - If set to false a ForbiddenException exception is thrown instead of redirecting.
*
* @var mixed
*/
public $unauthorizedRedirect = true;
/**
* Controller actions for which user validation is not required.
*
@ -234,14 +251,14 @@ class AuthComponent extends Component {
public $response;
/**
* Method list for bound controller
* Method list for bound controller.
*
* @var array
*/
protected $_methods = array();
/**
* Initializes AuthComponent for use in the controller
* Initializes AuthComponent for use in the controller.
*
* @param Controller $controller A reference to the instantiating controller object
* @return void
@ -257,11 +274,11 @@ class AuthComponent extends Component {
}
/**
* Main execution method. Handles redirecting of invalid users, and processing
* Main execution method. Handles redirecting of invalid users, and processing
* of login form data.
*
* @param Controller $controller A reference to the instantiating controller object
* @return boolean
* @return bool
*/
public function startup(Controller $controller) {
$methods = array_flip(array_map('strtolower', $controller->methods));
@ -279,67 +296,137 @@ class AuthComponent extends Component {
if (!$this->_setDefaults()) {
return false;
}
$request = $controller->request;
$url = '';
if (isset($request->url)) {
$url = $request->url;
}
$url = Router::normalize($url);
$loginAction = Router::normalize($this->loginAction);
$allowedActions = $this->allowedActions;
$isAllowed = (
$this->allowedActions == array('*') ||
in_array($action, array_map('strtolower', $allowedActions))
);
if ($loginAction != $url && $isAllowed) {
if ($this->_isAllowed($controller)) {
return true;
}
if ($loginAction == $url) {
if (empty($request->data)) {
if (!$this->Session->check('Auth.redirect') && !$this->loginRedirect && env('HTTP_REFERER')) {
if (!$this->_getUser()) {
return $this->_unauthenticated($controller);
}
if ($this->_isLoginAction($controller) ||
empty($this->authorize) ||
$this->isAuthorized($this->user())
) {
return true;
}
return $this->_unauthorized($controller);
}
/**
* Checks whether current action is accessible without authentication.
*
* @param Controller $controller A reference to the instantiating controller object
* @return bool True if action is accessible without authentication else false
*/
protected function _isAllowed(Controller $controller) {
$action = strtolower($controller->request->params['action']);
if (in_array($action, array_map('strtolower', $this->allowedActions))) {
return true;
}
return false;
}
/**
* Handles unauthenticated access attempt. First the `unathenticated()` method
* of the last authenticator in the chain will be called. The authenticator can
* handle sending response or redirection as appropriate and return `true` to
* indicate no furthur action is necessary. If authenticator returns null this
* method redirects user to login action. If it's an ajax request and
* $ajaxLogin is specified that element is rendered else a 403 http status code
* is returned.
*
* @param Controller $controller A reference to the controller object.
* @return bool True if current action is login action else false.
*/
protected function _unauthenticated(Controller $controller) {
if (empty($this->_authenticateObjects)) {
$this->constructAuthenticate();
}
$auth = $this->_authenticateObjects[count($this->_authenticateObjects) - 1];
if ($auth->unauthenticated($this->request, $this->response)) {
return false;
}
if ($this->_isLoginAction($controller)) {
if (empty($controller->request->data)) {
if (!$this->Session->check('Auth.redirect') && env('HTTP_REFERER')) {
$this->Session->write('Auth.redirect', $controller->referer(null, true));
}
}
return true;
} else {
if (!$this->_getUser()) {
if (!$request->is('ajax')) {
$this->flash($this->authError);
$this->Session->write('Auth.redirect', $request->here());
$controller->redirect($loginAction);
return false;
} elseif (!empty($this->ajaxLogin)) {
$controller->viewPath = 'Elements';
echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
$this->_stop();
return false;
} else {
$controller->redirect(null, 403);
}
}
}
if (empty($this->authorize) || $this->isAuthorized($this->user())) {
return true;
if (!$controller->request->is('ajax') && !$controller->request->is('json')) {
$this->flash($this->authError);
$this->Session->write('Auth.redirect', $controller->request->here(false));
$controller->redirect($this->loginAction);
return false;
}
if (!empty($this->ajaxLogin)) {
$controller->response->statusCode(403);
$controller->viewPath = 'Elements';
$response = $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
$response->send();
$this->_stop();
return false;
}
$controller->response->statusCode(403);
$controller->response->send();
$this->_stop();
return false;
}
/**
* Normalizes $loginAction and checks if current request URL is same as login action.
*
* @param Controller $controller A reference to the controller object.
* @return bool True if current action is login action else false.
*/
protected function _isLoginAction(Controller $controller) {
$url = '';
if (isset($controller->request->url)) {
$url = $controller->request->url;
}
$url = Router::normalize($url);
$loginAction = Router::normalize($this->loginAction);
return $loginAction === $url;
}
/**
* Handle unauthorized access attempt
*
* @param Controller $controller A reference to the controller object
* @return bool Returns false
* @throws ForbiddenException
* @see AuthComponent::$unauthorizedRedirect
*/
protected function _unauthorized(Controller $controller) {
if ($this->unauthorizedRedirect === false) {
throw new ForbiddenException($this->authError);
}
$this->flash($this->authError);
$default = '/';
if (!empty($this->loginRedirect)) {
$default = $this->loginRedirect;
if ($this->unauthorizedRedirect === true) {
$default = '/';
if (!empty($this->loginRedirect)) {
$default = $this->loginRedirect;
}
$url = $controller->referer($default, true);
} else {
$url = $this->unauthorizedRedirect;
}
$controller->redirect($controller->referer($default, true), null, true);
$controller->redirect($url);
return false;
}
/**
* Attempts to introspect the correct values for object properties.
*
* @return boolean
* @return bool True
*/
protected function _setDefaults() {
$defaults = array(
@ -347,7 +434,7 @@ class AuthComponent extends Component {
'authError' => __d('cake', 'You are not authorized to access that location.')
);
foreach ($defaults as $key => $value) {
if (empty($this->{$key})) {
if (!isset($this->{$key}) || $this->{$key} === true) {
$this->{$key} = $value;
}
}
@ -355,18 +442,21 @@ class AuthComponent extends Component {
}
/**
* Check if the provided user is authorized for the request.
*
* Uses the configured Authorization adapters to check whether or not a user is authorized.
* Each adapter will be checked in sequence, if any of them return true, then the user will
* be authorized for the request.
*
* @param array $user The user to check the authorization of. If empty the user in the session will be used.
* @param CakeRequest $request The request to authenticate for. If empty, the current request will be used.
* @return boolean True if $user is authorized, otherwise false
* @param array|null $user The user to check the authorization of. If empty the user in the session will be used.
* @param CakeRequest|null $request The request to authenticate for. If empty, the current request will be used.
* @return bool True if $user is authorized, otherwise false
*/
public function isAuthorized($user = null, $request = null) {
public function isAuthorized($user = null, CakeRequest $request = null) {
if (empty($user) && !$this->user()) {
return false;
} elseif (empty($user)) {
}
if (empty($user)) {
$user = $this->user();
}
if (empty($request)) {
@ -391,7 +481,7 @@ class AuthComponent extends Component {
*/
public function constructAuthorize() {
if (empty($this->authorize)) {
return;
return null;
}
$this->_authorizeObjects = array();
$config = Hash::normalize((array)$this->authorize);
@ -408,7 +498,7 @@ class AuthComponent extends Component {
throw new CakeException(__d('cake_dev', 'Authorization adapter "%s" was not found.', $class));
}
if (!method_exists($className, 'authorize')) {
throw new CakeException(__d('cake_dev', 'Authorization objects must implement an authorize method.'));
throw new CakeException(__d('cake_dev', 'Authorization objects must implement an %s method.', 'authorize()'));
}
$settings = array_merge($global, (array)$settings);
$this->_authorizeObjects[] = new $className($this->_Collection, $settings);
@ -426,7 +516,7 @@ class AuthComponent extends Component {
* `$this->Auth->allow('edit', 'add');` or
* `$this->Auth->allow();` to allow all actions
*
* @param string|array $action,... Controller action name or array of actions
* @param string|array|null $action Controller action name or array of actions
* @return void
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#making-actions-public
*/
@ -434,12 +524,12 @@ class AuthComponent extends Component {
$args = func_get_args();
if (empty($args) || $action === null) {
$this->allowedActions = $this->_methods;
} else {
if (isset($args[0]) && is_array($args[0])) {
$args = $args[0];
}
$this->allowedActions = array_merge($this->allowedActions, $args);
return;
}
if (isset($args[0]) && is_array($args[0])) {
$args = $args[0];
}
$this->allowedActions = array_merge($this->allowedActions, $args);
}
/**
@ -451,7 +541,7 @@ class AuthComponent extends Component {
* `$this->Auth->deny('edit', 'add');` or
* `$this->Auth->deny();` to remove all items from the allowed list
*
* @param string|array $action,... Controller action name or array of actions
* @param string|array|null $action Controller action name or array of actions
* @return void
* @see AuthComponent::allow()
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#making-actions-require-authorization
@ -460,47 +550,58 @@ class AuthComponent extends Component {
$args = func_get_args();
if (empty($args) || $action === null) {
$this->allowedActions = array();
} else {
if (isset($args[0]) && is_array($args[0])) {
$args = $args[0];
}
foreach ($args as $arg) {
$i = array_search($arg, $this->allowedActions);
if (is_int($i)) {
unset($this->allowedActions[$i]);
}
}
$this->allowedActions = array_values($this->allowedActions);
return;
}
if (isset($args[0]) && is_array($args[0])) {
$args = $args[0];
}
foreach ($args as $arg) {
$i = array_search($arg, $this->allowedActions);
if (is_int($i)) {
unset($this->allowedActions[$i]);
}
}
$this->allowedActions = array_values($this->allowedActions);
}
/**
* Maps action names to CRUD operations. Used for controller-based authentication. Make sure
* Maps action names to CRUD operations.
*
* Used for controller-based authentication. Make sure
* to configure the authorize property before calling this method. As it delegates $map to all the
* attached authorize objects.
*
* @param array $map Actions to map
* @return void
* @return array
* @see BaseAuthorize::mapActions()
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#mapping-actions-when-using-crudauthorize
* @deprecated 3.0.0 Map actions using `actionMap` config key on authorize objects instead
*/
public function mapActions($map = array()) {
if (empty($this->_authorizeObjects)) {
$this->constructAuthorize();
}
$mappedActions = array();
foreach ($this->_authorizeObjects as $auth) {
$auth->mapActions($map);
$mappedActions = Hash::merge($mappedActions, $auth->mapActions($map));
}
if (empty($map)) {
return $mappedActions;
}
return array();
}
/**
* Log a user in. If a $user is provided that data will be stored as the logged in user. If `$user` is empty or not
* Log a user in.
*
* If a $user is provided that data will be stored as the logged in user. If `$user` is empty or not
* specified, the request will be used to identify a user. If the identification was successful,
* the user record is written to the session key specified in AuthComponent::$sessionKey. Logging in
* will also change the session id in order to help mitigate session replays.
*
* @param array $user Either an array of user data, or null to identify a user using the current request.
* @return boolean True on login success, false on failure
* @param array|null $user Either an array of user data, or null to identify a user using the current request.
* @return bool True on login success, false on failure
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#identifying-users-and-logging-them-in
*/
public function login($user = null) {
@ -510,18 +611,26 @@ class AuthComponent extends Component {
$user = $this->identify($this->request, $this->response);
}
if ($user) {
$this->Session->renew();
$this->Session->write(self::$sessionKey, $user);
if (static::$sessionKey) {
$this->Session->renew();
$this->Session->write(static::$sessionKey, $user);
} else {
static::$_user = $user;
}
$event = new CakeEvent('Auth.afterIdentify', $this, array('user' => $user));
$this->_Collection->getController()->getEventManager()->dispatch($event);
}
return $this->loggedIn();
return (bool)$this->user();
}
/**
* Logs a user out, and returns the login action to redirect to.
* Triggers the logout() method of all the authenticate objects, so they can perform
* custom logout logic. AuthComponent will remove the session data, so
* there is no need to do that in an authentication object. Logging out
* will also renew the session id. This helps mitigate issues with session replays.
* Log a user out.
*
* Returns the logout action to redirect to. Triggers the logout() method of
* all the authenticate objects, so they can perform custom logout logic.
* AuthComponent will remove the session data, so there is no need to do that
* in an authentication object. Logging out will also renew the session id.
* This helps mitigate issues with session replays.
*
* @return string AuthComponent::$logoutRedirect
* @see AuthComponent::$logoutRedirect
@ -536,7 +645,7 @@ class AuthComponent extends Component {
foreach ($this->_authenticateObjects as $auth) {
$auth->logout($user);
}
$this->Session->delete(self::$sessionKey);
$this->Session->delete(static::$sessionKey);
$this->Session->delete('Auth.redirect');
$this->Session->renew();
return Router::normalize($this->logoutRedirect);
@ -545,22 +654,21 @@ class AuthComponent extends Component {
/**
* Get the current user.
*
* Will prefer the static user cache over sessions. The static user
* cache is primarily used for stateless authentication. For stateful authentication,
* Will prefer the static user cache over sessions. The static user
* cache is primarily used for stateless authentication. For stateful authentication,
* cookies + sessions will be used.
*
* @param string $key field to retrieve. Leave null to get entire User record
* @return mixed User record. or null if no user is logged in.
* @param string|null $key field to retrieve. Leave null to get entire User record
* @return mixed|null User record. or null if no user is logged in.
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user
*/
public static function user($key = null) {
if (empty(self::$_user) && !CakeSession::check(self::$sessionKey)) {
return null;
}
if (!empty(self::$_user)) {
$user = self::$_user;
if (!empty(static::$_user)) {
$user = static::$_user;
} elseif (static::$sessionKey && CakeSession::check(static::$sessionKey)) {
$user = CakeSession::read(static::$sessionKey);
} else {
$user = CakeSession::read(self::$sessionKey);
return null;
}
if ($key === null) {
return $user;
@ -570,51 +678,80 @@ class AuthComponent extends Component {
/**
* Similar to AuthComponent::user() except if the session user cannot be found, connected authentication
* objects will have their getUser() methods called. This lets stateless authentication methods function correctly.
* objects will have their getUser() methods called. This lets stateless authentication methods function correctly.
*
* @return boolean true if a user can be found, false if one cannot.
* @return bool True if a user can be found, false if one cannot.
*/
protected function _getUser() {
$user = $this->user();
if ($user) {
$this->Session->delete('Auth.redirect');
return true;
}
if (empty($this->_authenticateObjects)) {
$this->constructAuthenticate();
}
foreach ($this->_authenticateObjects as $auth) {
$result = $auth->getUser($this->request);
if (!empty($result) && is_array($result)) {
self::$_user = $result;
static::$_user = $result;
return true;
}
}
return false;
}
/**
* If no parameter is passed, gets the authentication redirect URL. Pass a url in to
* set the destination a user should be redirected to upon logging in. Will fallback to
* AuthComponent::$loginRedirect if there is no stored redirect value.
* Backwards compatible alias for AuthComponent::redirectUrl().
*
* @param string|array $url Optional URL to write as the login redirect URL.
* @param string|array|null $url Optional URL to write as the login redirect URL.
* @return string Redirect URL
* @deprecated 3.0.0 Since 2.3.0, use AuthComponent::redirectUrl() instead
*/
public function redirect($url = null) {
if (!is_null($url)) {
return $this->redirectUrl($url);
}
/**
* Get the URL a user should be redirected to upon login.
*
* Pass a URL in to set the destination a user should be redirected to upon
* logging in.
*
* If no parameter is passed, gets the authentication redirect URL. The URL
* returned is as per following rules:
*
* - Returns the normalized URL from session Auth.redirect value if it is
* present and for the same domain the current app is running on.
* - If there is no session value and there is a $loginRedirect, the $loginRedirect
* value is returned.
* - If there is no session and no $loginRedirect, / is returned.
*
* @param string|array|null $url Optional URL to write as the login redirect URL.
* @return string Redirect URL
*/
public function redirectUrl($url = null) {
if ($url !== null) {
$redir = $url;
$this->Session->write('Auth.redirect', $redir);
} elseif ($this->Session->check('Auth.redirect')) {
$redir = $this->Session->read('Auth.redirect');
$this->Session->delete('Auth.redirect');
if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
$redir = $this->loginRedirect;
if (Router::normalize($redir) === Router::normalize($this->loginAction)) {
$redir = $this->loginRedirect ?: '/';
}
} else {
} elseif ($this->loginRedirect) {
$redir = $this->loginRedirect;
} else {
$redir = '/';
}
return Router::normalize($redir);
if (is_array($redir)) {
return Router::url($redir + array('base' => false));
}
return $redir;
}
/**
@ -639,14 +776,14 @@ class AuthComponent extends Component {
}
/**
* loads the configured authentication objects.
* Loads the configured authentication objects.
*
* @return mixed either null on empty authenticate value, or an array of loaded objects.
* @return mixed Either null on empty authenticate value, or an array of loaded objects.
* @throws CakeException
*/
public function constructAuthenticate() {
if (empty($this->authenticate)) {
return;
return null;
}
$this->_authenticateObjects = array();
$config = Hash::normalize((array)$this->authenticate);
@ -656,6 +793,10 @@ class AuthComponent extends Component {
unset($config[AuthComponent::ALL]);
}
foreach ($config as $class => $settings) {
if (!empty($settings['className'])) {
$class = $settings['className'];
unset($settings['className']);
}
list($plugin, $class) = pluginSplit($class, true);
$className = $class . 'Authenticate';
App::uses($className, $plugin . 'Controller/Component/Auth');
@ -663,10 +804,12 @@ class AuthComponent extends Component {
throw new CakeException(__d('cake_dev', 'Authentication adapter "%s" was not found.', $class));
}
if (!method_exists($className, 'authenticate')) {
throw new CakeException(__d('cake_dev', 'Authentication objects must implement an authenticate method.'));
throw new CakeException(__d('cake_dev', 'Authentication objects must implement an %s method.', 'authenticate()'));
}
$settings = array_merge($global, (array)$settings);
$this->_authenticateObjects[] = new $className($this->_Collection, $settings);
$auth = new $className($this->_Collection, $settings);
$this->_Collection->getController()->getEventManager()->attach($auth);
$this->_authenticateObjects[] = $auth;
}
return $this->_authenticateObjects;
}
@ -674,46 +817,38 @@ class AuthComponent extends Component {
/**
* Hash a password with the application's salt value (as defined with Configure::write('Security.salt');
*
* This method is intended as a convenience wrapper for Security::hash(). If you want to use
* This method is intended as a convenience wrapper for Security::hash(). If you want to use
* a hashing/encryption system not supported by that method, do not use this method.
*
* @param string $password Password to hash
* @return string Hashed password
* @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#hashing-passwords
* @deprecated 3.0.0 Since 2.4. Use Security::hash() directly or a password hasher object.
*/
public static function password($password) {
return Security::hash($password, null, true);
}
/**
* Component shutdown. If user is logged in, wipe out redirect.
*
* @param Controller $controller Instantiating controller
* @return void
*/
public function shutdown(Controller $controller) {
if ($this->loggedIn()) {
$this->Session->delete('Auth.redirect');
}
}
/**
* Check whether or not the current user has data in the session, and is considered logged in.
*
* @return boolean true if the user is logged in, false otherwise
* @return bool true if the user is logged in, false otherwise
* @deprecated 3.0.0 Since 2.5. Use AuthComponent::user() directly.
*/
public function loggedIn() {
return $this->user() != array();
return (bool)$this->user();
}
/**
* Set a flash message. Uses the Session component, and values from AuthComponent::$flash.
* Set a flash message. Uses the Session component, and values from AuthComponent::$flash.
*
* @param string $message The message to set.
* @return void
*/
public function flash($message) {
$this->Session->setFlash($message, $this->flash['element'], $this->flash['params'], $this->flash['key']);
if ($message === false) {
return;
}
$this->Flash->set($message, $this->flash);
}
}