TestAuthComponent.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright 2005-2011, Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. * @link https://cakephp.org CakePHP(tm) Project
  11. * @since 3.0.0
  12. * @license https://opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace TestApp\Controller\Component;
  15. use Cake\Controller\Component\AuthComponent;
  16. use Cake\Event\Event;
  17. /**
  18. * TestAuthComponent class
  19. */
  20. class TestAuthComponent extends AuthComponent
  21. {
  22. /**
  23. * @var string|null
  24. */
  25. public $authCheckCalledFrom = null;
  26. /**
  27. * @param Event $event
  28. * @return \Cake\Http\Response|null
  29. */
  30. public function authCheck(Event $event)
  31. {
  32. if (isset($this->earlyAuthTest)) {
  33. if ($this->_config['checkAuthIn'] !== $event->getName()) {
  34. return null;
  35. }
  36. $this->authCheckCalledFrom = $event->getName();
  37. return null;
  38. }
  39. return parent::authCheck($event);
  40. }
  41. /**
  42. * Helper method to add/set an authenticate object instance
  43. *
  44. * @param int $index The index at which to add/set the object
  45. * @param Object $object The object to add/set
  46. * @return void
  47. */
  48. public function setAuthenticateObject($index, $object)
  49. {
  50. $this->_authenticateObjects[$index] = $object;
  51. }
  52. /**
  53. * Helper method to add/set an authorize object instance
  54. *
  55. * @param int $index The index at which to add/set the object
  56. * @param Object $object The object to add/set
  57. * @return void
  58. */
  59. public function setAuthorizeObject($index, $object)
  60. {
  61. $this->_authorizeObjects[$index] = $object;
  62. }
  63. }