AbstractAuth.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * HTTP Authentication baseclass
  4. *
  5. * This class has the common functionality for BasicAuth and DigestAuth
  6. *
  7. * @package Sabre
  8. * @subpackage HTTP
  9. * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
  10. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  11. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  12. */
  13. abstract class Sabre_HTTP_AbstractAuth {
  14. /**
  15. * The realm will be displayed in the dialog boxes
  16. *
  17. * This identifier can be changed through setRealm()
  18. *
  19. * @var string
  20. */
  21. protected $realm = 'SabreDAV';
  22. /**
  23. * HTTP response helper
  24. *
  25. * @var Sabre_HTTP_Response
  26. */
  27. protected $httpResponse;
  28. /**
  29. * HTTP request helper
  30. *
  31. * @var Sabre_HTTP_Request
  32. */
  33. protected $httpRequest;
  34. /**
  35. * __construct
  36. *
  37. */
  38. public function __construct() {
  39. $this->httpResponse = new Sabre_HTTP_Response();
  40. $this->httpRequest = new Sabre_HTTP_Request();
  41. }
  42. /**
  43. * Sets an alternative HTTP response object
  44. *
  45. * @param Sabre_HTTP_Response $response
  46. * @return void
  47. */
  48. public function setHTTPResponse(Sabre_HTTP_Response $response) {
  49. $this->httpResponse = $response;
  50. }
  51. /**
  52. * Sets an alternative HTTP request object
  53. *
  54. * @param Sabre_HTTP_Request $request
  55. * @return void
  56. */
  57. public function setHTTPRequest(Sabre_HTTP_Request $request) {
  58. $this->httpRequest = $request;
  59. }
  60. /**
  61. * Sets the realm
  62. *
  63. * The realm is often displayed in authentication dialog boxes
  64. * Commonly an application name displayed here
  65. *
  66. * @param string $realm
  67. * @return void
  68. */
  69. public function setRealm($realm) {
  70. $this->realm = $realm;
  71. }
  72. /**
  73. * Returns the realm
  74. *
  75. * @return string
  76. */
  77. public function getRealm() {
  78. return $this->realm;
  79. }
  80. /**
  81. * Returns an HTTP 401 header, forcing login
  82. *
  83. * This should be called when username and password are incorrect, or not supplied at all
  84. *
  85. * @return void
  86. */
  87. abstract public function requireLogin();
  88. }