Skip to content
Permalink
Browse files

Clean up ServerResponse usage to be consistent.

  • Loading branch information...
dereuromark committed Nov 7, 2016
1 parent 0f63f82 commit 223152eb78d5d84d481875fc69dcc199050f320e
Showing with 152 additions and 139 deletions.
  1. +7 −7 src/Auth/BaseAuthenticate.php
  2. +3 −3 src/Auth/BaseAuthorize.php
  3. +9 −9 src/Auth/BasicAuthenticate.php
  4. +3 −3 src/Auth/ControllerAuthorize.php
  5. +7 −8 src/Auth/DigestAuthenticate.php
  6. +5 −5 src/Auth/FormAuthenticate.php
  7. +3 −3 src/Auth/Storage/SessionStorage.php
  8. +2 −1 src/Auth/WeakPasswordHasher.php
  9. +2 −2 src/Controller/Component/AuthComponent.php
  10. +2 −2 src/Controller/Component/CookieComponent.php
  11. +5 −5 src/Controller/Component/CsrfComponent.php
  12. +4 −2 src/Controller/Component/RequestHandlerComponent.php
  13. +3 −3 src/Controller/Component/SecurityComponent.php
  14. +7 −7 src/Controller/Controller.php
  15. +1 −1 src/Error/BaseErrorHandler.php
  16. +2 −2 src/Error/ExceptionRenderer.php
  17. +2 −4 src/Http/ActionDispatcher.php
  18. +3 −4 src/Http/ControllerFactory.php
  19. +2 −3 src/Http/RequestTransformer.php
  20. +2 −2 src/Http/ServerRequest.php
  21. +2 −2 src/Network/Response.php
  22. +3 −3 src/Routing/Dispatcher.php
  23. +3 −3 src/Routing/Filter/AssetFilter.php
  24. +1 −1 src/Routing/Filter/ControllerFactoryFilter.php
  25. +2 −2 src/Routing/RequestActionTrait.php
  26. +2 −2 src/Routing/Route/Route.php
  27. +15 −15 src/Routing/Router.php
  28. +3 −3 src/TestSuite/LegacyRequestDispatcher.php
  29. +1 −1 src/TestSuite/MiddlewareDispatcher.php
  30. +3 −3 src/View/AjaxView.php
  31. +3 −3 src/View/Cell.php
  32. +2 −1 src/View/CellTrait.php
  33. +3 −3 src/View/Form/ArrayContext.php
  34. +3 −3 src/View/Form/EntityContext.php
  35. +3 −3 src/View/Form/FormContext.php
  36. +3 −3 src/View/Form/NullContext.php
  37. +3 −3 src/View/SerializedView.php
  38. +6 −6 src/View/View.php
  39. +3 −3 src/View/ViewBuilder.php
  40. +14 −0 tests/test_app/TestApp/Auth/TestAuthenticate.php
@@ -16,7 +16,7 @@
use Cake\Controller\ComponentRegistry;
use Cake\Core\InstanceConfigTrait;
use Cake\Event\EventListenerInterface;
use Cake\Network\Request;
use Cake\Http\ServerRequest;
use Cake\Network\Response;
use Cake\ORM\TableRegistry;
@@ -193,20 +193,20 @@ public function needsPasswordRehash()
/**
* Authenticate a user based on the request information.
*
* @param \Cake\Network\Request $request Request to get authentication information from.
* @param \Cake\Http\ServerRequest $request Request to get authentication information from.
* @param \Cake\Network\Response $response A response object that can have headers added.
* @return mixed Either false on failure, or an array of user data on success.
*/
abstract public function authenticate(Request $request, Response $response);
abstract public function authenticate(ServerRequest $request, Response $response);
/**
* Get a user based on information in the request. Primarily used by stateless authentication
* systems like basic and digest auth.
*
* @param \Cake\Network\Request $request Request object.
* @param \Cake\Http\ServerRequest $request Request object.
* @return mixed Either false or an array of user information
*/
public function getUser(Request $request)
public function getUser(ServerRequest $request)
{
return false;
}
@@ -219,11 +219,11 @@ public function getUser(Request $request)
* - Cake\Network\Response - A response object, which will cause AuthComponent to
* simply return that response.
*
* @param \Cake\Network\Request $request A request object.
* @param \Cake\Http\ServerRequest $request A request object.
* @param \Cake\Network\Response $response A response object.
* @return void
*/
public function unauthenticated(Request $request, Response $response)
public function unauthenticated(ServerRequest $request, Response $response)
{
}
@@ -16,7 +16,7 @@
use Cake\Controller\ComponentRegistry;
use Cake\Core\InstanceConfigTrait;
use Cake\Network\Request;
use Cake\Http\ServerRequest;
/**
* Abstract base authorization adapter for AuthComponent.
@@ -58,8 +58,8 @@ public function __construct(ComponentRegistry $registry, array $config = [])
* Checks user authorization.
*
* @param array|\ArrayAccess $user Active user data
* @param \Cake\Network\Request $request Request instance.
* @param \Cake\Http\ServerRequest $request Request instance.
* @return bool
*/
abstract public function authorize($user, Request $request);
abstract public function authorize($user, ServerRequest $request);
}
@@ -14,8 +14,8 @@
*/
namespace Cake\Auth;
use Cake\Http\ServerRequest;
use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
use Cake\Network\Response;
/**
@@ -56,22 +56,22 @@ class BasicAuthenticate extends BaseAuthenticate
* Authenticate a user using HTTP auth. Will use the configured User model and attempt a
* login using HTTP auth.
*
* @param \Cake\Network\Request $request The request to authenticate with.
* @param \Cake\Http\ServerRequest $request The request to authenticate with.
* @param \Cake\Network\Response $response The response to add headers to.
* @return mixed Either false on failure, or an array of user data on success.
*/
public function authenticate(Request $request, Response $response)
public function authenticate(ServerRequest $request, Response $response)
{
return $this->getUser($request);
}
/**
* Get a user based on information in the request. Used by cookie-less auth for stateless clients.
*
* @param \Cake\Network\Request $request Request object.
* @param \Cake\Http\ServerRequest $request Request object.
* @return mixed Either false or an array of user information
*/
public function getUser(Request $request)
public function getUser(ServerRequest $request)
{
$username = $request->env('PHP_AUTH_USER');
$pass = $request->env('PHP_AUTH_PW');
@@ -86,12 +86,12 @@ public function getUser(Request $request)
/**
* Handles an unauthenticated access attempt by sending appropriate login headers
*
* @param \Cake\Network\Request $request A request object.
* @param \Cake\Http\ServerRequest $request A request object.
* @param \Cake\Network\Response $response A response object.
* @return void
* @throws \Cake\Network\Exception\UnauthorizedException
*/
public function unauthenticated(Request $request, Response $response)
public function unauthenticated(ServerRequest $request, Response $response)
{
$Exception = new UnauthorizedException();
$Exception->responseHeader([$this->loginHeaders($request)]);
@@ -101,10 +101,10 @@ public function unauthenticated(Request $request, Response $response)
/**
* Generate the login headers
*
* @param \Cake\Network\Request $request Request object.
* @param \Cake\Http\ServerRequest $request Request object.
* @return string Headers for logging in.
*/
public function loginHeaders(Request $request)
public function loginHeaders(ServerRequest $request)
{
$realm = $this->config('realm') ?: $request->env('SERVER_NAME');
@@ -17,7 +17,7 @@
use Cake\Controller\ComponentRegistry;
use Cake\Controller\Controller;
use Cake\Core\Exception\Exception;
use Cake\Network\Request;
use Cake\Http\ServerRequest;
/**
* An authorization adapter for AuthComponent. Provides the ability to authorize
@@ -85,10 +85,10 @@ public function controller(Controller $controller = null)
* Checks user authorization using a controller callback.
*
* @param array|\ArrayAccess $user Active user data
* @param \Cake\Network\Request $request Request instance.
* @param \Cake\Http\ServerRequest $request Request instance.
* @return bool
*/
public function authorize($user, Request $request)
public function authorize($user, ServerRequest $request)
{
return (bool)$this->_Controller->isAuthorized($user);
}
@@ -16,8 +16,7 @@
use Cake\Controller\ComponentRegistry;
use Cake\Core\Configure;
use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
use Cake\Http\ServerRequest;
/**
* Digest Authentication adapter for AuthComponent.
@@ -100,10 +99,10 @@ public function __construct(ComponentRegistry $registry, array $config = [])
/**
* Get a user based on information in the request. Used by cookie-less auth for stateless clients.
*
* @param \Cake\Network\Request $request Request object.
* @param \Cake\Http\ServerRequest $request Request object.
* @return mixed Either false or an array of user information
*/
public function getUser(Request $request)
public function getUser(ServerRequest $request)
{
$digest = $this->_getDigest($request);
if (empty($digest)) {
@@ -134,10 +133,10 @@ public function getUser(Request $request)
/**
* Gets the digest headers from the request/environment.
*
* @param \Cake\Network\Request $request Request object.
* @param \Cake\Http\ServerRequest $request Request object.
* @return array Array of digest information.
*/
protected function _getDigest(Request $request)
protected function _getDigest(ServerRequest $request)
{
$digest = $request->env('PHP_AUTH_DIGEST');
if (empty($digest) && function_exists('apache_request_headers')) {
@@ -213,10 +212,10 @@ public static function password($username, $password, $realm)
/**
* Generate the login headers
*
* @param \Cake\Network\Request $request Request object.
* @param \Cake\Http\ServerRequest $request Request object.
* @return string Headers for logging in.
*/
public function loginHeaders(Request $request)
public function loginHeaders(ServerRequest $request)
{
$realm = $this->_config['realm'] ?: $request->env('SERVER_NAME');
@@ -15,7 +15,7 @@
*/
namespace Cake\Auth;
use Cake\Network\Request;
use Cake\Http\ServerRequest;
use Cake\Network\Response;
/**
@@ -41,11 +41,11 @@ class FormAuthenticate extends BaseAuthenticate
/**
* Checks the fields to ensure they are supplied.
*
* @param \Cake\Network\Request $request The request that contains login information.
* @param \Cake\Http\ServerRequest $request The request that contains login information.
* @param array $fields The fields to be checked.
* @return bool False if the fields have not been supplied. True if they exist.
*/
protected function _checkFields(Request $request, array $fields)
protected function _checkFields(ServerRequest $request, array $fields)
{
foreach ([$fields['username'], $fields['password']] as $field) {
$value = $request->data($field);
@@ -62,11 +62,11 @@ protected function _checkFields(Request $request, array $fields)
* to find POST data that is used to find a matching record in the `config.userModel`. Will return false if
* there is no post data, either username or password is missing, or if the scope conditions have not been met.
*
* @param \Cake\Network\Request $request The request that contains login information.
* @param \Cake\Http\ServerRequest $request The request that contains login information.
* @param \Cake\Network\Response $response Unused response object.
* @return mixed False on login failure. An array of User data on success.
*/
public function authenticate(Request $request, Response $response)
public function authenticate(ServerRequest $request, Response $response)
{
$fields = $this->_config['fields'];
if (!$this->_checkFields($request, $fields)) {
@@ -15,7 +15,7 @@
namespace Cake\Auth\Storage;
use Cake\Core\InstanceConfigTrait;
use Cake\Network\Request;
use Cake\Http\ServerRequest;
use Cake\Network\Response;
/**
@@ -61,11 +61,11 @@ class SessionStorage implements StorageInterface
/**
* Constructor.
*
* @param \Cake\Network\Request $request Request instance.
* @param \Cake\Http\ServerRequest $request Request instance.
* @param \Cake\Network\Response $response Response instance.
* @param array $config Configuration list.
*/
public function __construct(Request $request, Response $response, array $config = [])
public function __construct(ServerRequest $request, Response $response, array $config = [])
{
$this->_session = $request->session();
$this->config($config);
@@ -43,7 +43,8 @@ public function __construct(array $config = [])
if (Configure::read('debug')) {
Debugger::checkSecurityKeys();
}
parent::config($config);
parent::__construct($config);
}
/**
@@ -21,8 +21,8 @@
use Cake\Core\Exception\Exception;
use Cake\Event\Event;
use Cake\Event\EventDispatcherTrait;
use Cake\Http\ServerRequest;
use Cake\Network\Exception\ForbiddenException;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\Router;
use Cake\Utility\Hash;
@@ -511,7 +511,7 @@ protected function _setDefaults()
* If empty, the current request will be used.
* @return bool True if $user is authorized, otherwise false
*/
public function isAuthorized($user = null, Request $request = null)
public function isAuthorized($user = null, ServerRequest $request = null)
{
if (empty($user) && !$this->user()) {
return false;
@@ -15,8 +15,8 @@
namespace Cake\Controller\Component;
use Cake\Controller\Component;
use Cake\Http\ServerRequest;
use Cake\I18n\Time;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Utility\CookieCryptTrait;
use Cake\Utility\Hash;
@@ -126,7 +126,7 @@ public function initialize(array $config)
}
if ($controller === null) {
$this->request = Request::createFromGlobals();
$this->request = ServerRequest::createFromGlobals();
$this->_response = new Response();
}
@@ -16,9 +16,9 @@
use Cake\Controller\Component;
use Cake\Event\Event;
use Cake\Http\ServerRequest;
use Cake\I18n\Time;
use Cake\Network\Exception\InvalidCsrfTokenException;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Utility\Security;
@@ -117,11 +117,11 @@ public function implementedEvents()
* Also sets the request->params['_csrfToken'] so the newly minted
* token is available in the request data.
*
* @param \Cake\Network\Request $request The request object.
* @param \Cake\Http\ServerRequest $request The request object.
* @param \Cake\Network\Response $response The response object.
* @return void
*/
protected function _setCookie(Request $request, Response $response)
protected function _setCookie(ServerRequest $request, Response $response)
{
$expiry = new Time($this->_config['expiry']);
$value = hash('sha512', Security::randomBytes(16), false);
@@ -140,11 +140,11 @@ protected function _setCookie(Request $request, Response $response)
/**
* Validate the request data against the cookie token.
*
* @param \Cake\Network\Request $request The request to validate against.
* @param \Cake\Http\ServerRequest $request The request to validate against.
* @throws \Cake\Network\Exception\InvalidCsrfTokenException when the CSRF token is invalid or missing.
* @return void
*/
protected function _validateToken(Request $request)
protected function _validateToken(ServerRequest $request)
{
$cookie = $request->cookie($this->_config['cookieName']);
$post = $request->data($this->_config['field']);
@@ -155,7 +155,7 @@ public function initialize(array $config)
* If html is one of the preferred types, no content type will be set, this
* is to avoid issues with browsers that prefer HTML and several other content types.
*
* @param \Cake\Network\Request $request The request instance.
* @param \Cake\Http\ServerRequest $request The request instance.
* @param \Cake\Network\Response $response The response instance.
* @return void
*/
@@ -323,7 +323,9 @@ public function beforeRender(Event $event)
);
if ($this->ext && $isRecognized) {
$this->renderAs($event->subject(), $this->ext);
/* @var \Cake\Controller\Controller $controller */
$controller = $event->subject();
$this->renderAs($controller, $this->ext);
} else {
$this->response->charset(Configure::read('App.encoding'));
}
@@ -20,8 +20,8 @@
use Cake\Controller\Exception\SecurityException;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Http\ServerRequest;
use Cake\Network\Exception\BadRequestException;
use Cake\Network\Request;
use Cake\Utility\Hash;
use Cake\Utility\Security;
@@ -562,10 +562,10 @@ protected function _debugCheckFields($dataFields, $expectedFields = [], $intKeyM
* Manually add form tampering prevention token information into the provided
* request object.
*
* @param \Cake\Network\Request $request The request object to add into.
* @param \Cake\Http\ServerRequest $request The request object to add into.
* @return bool
*/
public function generateToken(Request $request)
public function generateToken(ServerRequest $request)
{
if ($request->is('requested')) {
if ($this->session->check('_Token')) {
Oops, something went wrong.

0 comments on commit 223152e

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