mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-03 22:53:58 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -1,36 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* 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
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Security', 'Utility');
|
||||
App::uses('Hash', 'Utility');
|
||||
App::uses('CakeEventListener', 'Event');
|
||||
|
||||
/**
|
||||
* Base Authentication class with common methods and properties.
|
||||
*
|
||||
* @package Cake.Controller.Component.Auth
|
||||
*/
|
||||
abstract class BaseAuthenticate {
|
||||
abstract class BaseAuthenticate implements CakeEventListener {
|
||||
|
||||
/**
|
||||
* Settings for this object.
|
||||
*
|
||||
* - `fields` The fields to use to identify a user by.
|
||||
* - `userModel` The model name of the User, defaults to User.
|
||||
* - `userFields` Array of fields to retrieve from User model, null to retrieve all. Defaults to null.
|
||||
* - `scope` Additional conditions to use when looking up and authenticating users,
|
||||
* i.e. `array('User.is_active' => 1).`
|
||||
* - `recursive` The value of the recursive key passed to find(). Defaults to 0.
|
||||
* - `contain` Extra models to contain and store in session.
|
||||
* - `passwordHasher` Password hasher class. Can be a string specifying class name
|
||||
* or an array containing `className` key, any other keys will be passed as
|
||||
* settings to the class. Defaults to 'Simple'.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -40,9 +45,11 @@ abstract class BaseAuthenticate {
|
|||
'password' => 'password'
|
||||
),
|
||||
'userModel' => 'User',
|
||||
'userFields' => null,
|
||||
'scope' => array(),
|
||||
'recursive' => 0,
|
||||
'contain' => null,
|
||||
'passwordHasher' => 'Simple'
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -52,6 +59,22 @@ abstract class BaseAuthenticate {
|
|||
*/
|
||||
protected $_Collection;
|
||||
|
||||
/**
|
||||
* Password hasher instance.
|
||||
*
|
||||
* @var AbstractPasswordHasher
|
||||
*/
|
||||
protected $_passwordHasher;
|
||||
|
||||
/**
|
||||
* Implemented events
|
||||
*
|
||||
* @return array of events => callbacks.
|
||||
*/
|
||||
public function implementedEvents() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
@ -66,42 +89,102 @@ abstract class BaseAuthenticate {
|
|||
/**
|
||||
* Find a user record using the standard options.
|
||||
*
|
||||
* @param string $username The username/identifier.
|
||||
* @param string $password The unhashed password.
|
||||
* @return Mixed Either false on failure, or an array of user data.
|
||||
* The $username parameter can be a (string)username or an array containing
|
||||
* conditions for Model::find('first'). If the $password param is not provided
|
||||
* the password field will be present in returned array.
|
||||
*
|
||||
* Input passwords will be hashed even when a user doesn't exist. This
|
||||
* helps mitigate timing attacks that are attempting to find valid usernames.
|
||||
*
|
||||
* @param string|array $username The username/identifier, or an array of find conditions.
|
||||
* @param string $password The password, only used if $username param is string.
|
||||
* @return bool|array Either false on failure, or an array of user data.
|
||||
*/
|
||||
protected function _findUser($username, $password) {
|
||||
protected function _findUser($username, $password = null) {
|
||||
$userModel = $this->settings['userModel'];
|
||||
list($plugin, $model) = pluginSplit($userModel);
|
||||
list(, $model) = pluginSplit($userModel);
|
||||
$fields = $this->settings['fields'];
|
||||
|
||||
$conditions = array(
|
||||
$model . '.' . $fields['username'] => $username,
|
||||
$model . '.' . $fields['password'] => $this->_password($password),
|
||||
);
|
||||
if (is_array($username)) {
|
||||
$conditions = $username;
|
||||
} else {
|
||||
$conditions = array(
|
||||
$model . '.' . $fields['username'] => $username
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($this->settings['scope'])) {
|
||||
$conditions = array_merge($conditions, $this->settings['scope']);
|
||||
}
|
||||
|
||||
$userFields = $this->settings['userFields'];
|
||||
if ($password !== null && $userFields !== null) {
|
||||
$userFields[] = $model . '.' . $fields['password'];
|
||||
}
|
||||
|
||||
$result = ClassRegistry::init($userModel)->find('first', array(
|
||||
'conditions' => $conditions,
|
||||
'recursive' => $this->settings['recursive'],
|
||||
'fields' => $userFields,
|
||||
'contain' => $this->settings['contain'],
|
||||
));
|
||||
if (empty($result) || empty($result[$model])) {
|
||||
if (empty($result[$model])) {
|
||||
$this->passwordHasher()->hash($password);
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $result[$model];
|
||||
unset($user[$fields['password']]);
|
||||
if ($password !== null) {
|
||||
if (!$this->passwordHasher()->check($password, $user[$fields['password']])) {
|
||||
return false;
|
||||
}
|
||||
unset($user[$fields['password']]);
|
||||
}
|
||||
|
||||
unset($result[$model]);
|
||||
return array_merge($user, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return password hasher object
|
||||
*
|
||||
* @return AbstractPasswordHasher Password hasher instance
|
||||
* @throws CakeException If password hasher class not found or
|
||||
* it does not extend AbstractPasswordHasher
|
||||
*/
|
||||
public function passwordHasher() {
|
||||
if ($this->_passwordHasher) {
|
||||
return $this->_passwordHasher;
|
||||
}
|
||||
|
||||
$config = array();
|
||||
if (is_string($this->settings['passwordHasher'])) {
|
||||
$class = $this->settings['passwordHasher'];
|
||||
} else {
|
||||
$class = $this->settings['passwordHasher']['className'];
|
||||
$config = $this->settings['passwordHasher'];
|
||||
unset($config['className']);
|
||||
}
|
||||
list($plugin, $class) = pluginSplit($class, true);
|
||||
$className = $class . 'PasswordHasher';
|
||||
App::uses($className, $plugin . 'Controller/Component/Auth');
|
||||
if (!class_exists($className)) {
|
||||
throw new CakeException(__d('cake_dev', 'Password hasher class "%s" was not found.', $class));
|
||||
}
|
||||
if (!is_subclass_of($className, 'AbstractPasswordHasher')) {
|
||||
throw new CakeException(__d('cake_dev', 'Password hasher must extend AbstractPasswordHasher class.'));
|
||||
}
|
||||
$this->_passwordHasher = new $className($config);
|
||||
return $this->_passwordHasher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash the plain text password so that it matches the hashed/encrypted password
|
||||
* in the datasource.
|
||||
*
|
||||
* @param string $password The plain text password.
|
||||
* @return string The hashed form of the password.
|
||||
* @deprecated 3.0.0 Since 2.4. Use a PasswordHasher class instead.
|
||||
*/
|
||||
protected function _password($password) {
|
||||
return Security::hash($password, null, true);
|
||||
|
@ -130,14 +213,25 @@ abstract class BaseAuthenticate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get a user based on information in the request. Primarily used by stateless authentication
|
||||
* Get a user based on information in the request. Primarily used by stateless authentication
|
||||
* systems like basic and digest auth.
|
||||
*
|
||||
* @param CakeRequest $request Request object.
|
||||
* @return mixed Either false or an array of user information
|
||||
*/
|
||||
public function getUser($request) {
|
||||
public function getUser(CakeRequest $request) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle unauthenticated access attempt.
|
||||
*
|
||||
* @param CakeRequest $request A request object.
|
||||
* @param CakeResponse $response A response object.
|
||||
* @return mixed Either true to indicate the unauthenticated request has been
|
||||
* dealt with and no more action is required by AuthComponent or void (default).
|
||||
*/
|
||||
public function unauthenticated(CakeRequest $request, CakeResponse $response) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue