401.php 844 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. class Kohana_HTTP_Exception_401 extends HTTP_Exception_Expected {
  3. /**
  4. * @var integer HTTP 401 Unauthorized
  5. */
  6. protected $_code = 401;
  7. /**
  8. * Specifies the WWW-Authenticate challenge.
  9. *
  10. * @param string $challenge WWW-Authenticate challenge (eg `Basic realm="Control Panel"`)
  11. */
  12. public function authenticate($challenge = NULL)
  13. {
  14. if ($challenge === NULL)
  15. return $this->headers('www-authenticate');
  16. $this->headers('www-authenticate', $challenge);
  17. return $this;
  18. }
  19. /**
  20. * Validate this exception contains everything needed to continue.
  21. *
  22. * @throws Kohana_Exception
  23. * @return bool
  24. */
  25. public function check()
  26. {
  27. if ($this->headers('www-authenticate') === NULL)
  28. throw new Kohana_Exception('A \'www-authenticate\' header must be specified for a HTTP 401 Unauthorized');
  29. return TRUE;
  30. }
  31. }